Write a more generalized format() function that works like this: double amt = 1234.25; cout << format(amount); // default formatting cout << format(amount, .2); // fixed, 2 decimals cout << format(amount, 12.2); // width 12, fixed, 2 decimals cout << format(amount, 12.2, "€"); // width 12, fixed, 2 decimals, Euro file: #include // fixed #include // setw, setprecision #include // ostringstream #include #include // round using namespace std; #include "format.h" string format(double amt, double fmt, const string& prefix) { } In the lecture, you worked on the toDollars function which formats a number in the form $ 1,234.25. Write a more generalized format() function that works like this: double amt = 1234.25; cout << format(amount); // default formatting cout << format(amount, .2); // fixed, 2 decimals cout << format(amount, 12.2); // width 12, fixed, 2 decimals cout << format(amount, 12.2, "€"); // width 12, fixed, 2 decimals, Euro Complete the following file: format.cpp 1 2 3 4 5 6 7 8 9 10 11 12 #include // fixed #include // setw, setprecision #include // ostringstream #include #include // round using namespace std; #include "format.h" string format(double amt, double fmt, const string& prefix) { } Use the following files: Tester.cpp #include #include #include #include using namespace std; #include "format.h" int main() { cout << format(1234567.2345678) << endl; cout << "Expected: 1.23457e+06" << endl; cout << format(1234567.2345678, .5) << endl; cout << "Expected: 1234567.23457" << endl; cout << '"' << format(1234.2345678, 10.3) << '"' << endl; cout << "Expected: \" 1234.235\"" << endl; cout << '"' << format(315.25, 8.2, "£") << '"' << endl; cout << "Expected: \"£ 315.25\"" << endl; } format.h #ifndef FORMAT_H #define FORMAT_H #include std::string format(double amt, double fmt = 0.0, const std::string& prefix = ""); #endif
Write a more generalized format() function that works like this: double amt = 1234.25; cout << format(amount); // default formatting cout << format(amount, .2); // fixed, 2 decimals cout << format(amount, 12.2); // width 12, fixed, 2 decimals cout << format(amount, 12.2, "€"); // width 12, fixed, 2 decimals, Euro file: #include // fixed #include // setw, setprecision #include // ostringstream #include #include // round using namespace std; #include "format.h" string format(double amt, double fmt, const string& prefix) { } In the lecture, you worked on the toDollars function which formats a number in the form $ 1,234.25. Write a more generalized format() function that works like this: double amt = 1234.25; cout << format(amount); // default formatting cout << format(amount, .2); // fixed, 2 decimals cout << format(amount, 12.2); // width 12, fixed, 2 decimals cout << format(amount, 12.2, "€"); // width 12, fixed, 2 decimals, Euro Complete the following file: format.cpp 1 2 3 4 5 6 7 8 9 10 11 12 #include // fixed #include // setw, setprecision #include // ostringstream #include #include // round using namespace std; #include "format.h" string format(double amt, double fmt, const string& prefix) { } Use the following files: Tester.cpp #include #include #include #include using namespace std; #include "format.h" int main() { cout << format(1234567.2345678) << endl; cout << "Expected: 1.23457e+06" << endl; cout << format(1234567.2345678, .5) << endl; cout << "Expected: 1234567.23457" << endl; cout << '"' << format(1234.2345678, 10.3) << '"' << endl; cout << "Expected: \" 1234.235\"" << endl; cout << '"' << format(315.25, 8.2, "£") << '"' << endl; cout << "Expected: \"£ 315.25\"" << endl; } format.h #ifndef FORMAT_H #define FORMAT_H #include std::string format(double amt, double fmt = 0.0, const std::string& prefix = ""); #endif
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Write a more generalized format() function that works like this:
double amt = 1234.25; cout << format(amount); // default formatting cout << format(amount, .2); // fixed, 2 decimals cout << format(amount, 12.2); // width 12, fixed, 2 decimals cout << format(amount, 12.2, "€"); // width 12, fixed, 2 decimals, Eurofile:
#include <iostream> // fixed
#include <iomanip> // setw, setprecision
#include <sstream> // ostringstream
#include <string>
#include <cmath> // round
using namespace std;
#include "format.h"
string format(double amt, double fmt, const string& prefix)
{
}
In the lecture, you worked on the toDollars function which formats a number in the form $ 1,234.25. Write a more generalized format() function that works like this:
double amt = 1234.25; cout << format(amount); // default formatting cout << format(amount, .2); // fixed, 2 decimals cout << format(amount, 12.2); // width 12, fixed, 2 decimals cout << format(amount, 12.2, "€"); // width 12, fixed, 2 decimals, EuroComplete the following file:
format.cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream> // fixed
#include <iomanip> // setw, setprecision
#include <sstream> // ostringstream
#include <string>
#include <cmath> // round
using namespace std;
#include "format.h"
string format(double amt, double fmt, const string& prefix)
{
}
Use the following files:
Tester.cpp
#include <iostream> #include <iomanip> #include <sstream> #include <string> using namespace std; #include "format.h" int main() { cout << format(1234567.2345678) << endl; cout << "Expected: 1.23457e+06" << endl; cout << format(1234567.2345678, .5) << endl; cout << "Expected: 1234567.23457" << endl; cout << '"' << format(1234.2345678, 10.3) << '"' << endl; cout << "Expected: \" 1234.235\"" << endl; cout << '"' << format(315.25, 8.2, "£") << '"' << endl; cout << "Expected: \"£ 315.25\"" << endl; }format.h
#ifndef FORMAT_H #define FORMAT_H #include <string> std::string format(double amt, double fmt = 0.0, const std::string& prefix = ""); #endifExpert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education