← Back to Streams
Question 632
operator<< for Money
operator<< for Money
A classMoneythat stores a whole number of cents is given, together with a friend declaration foroperator<<. Define the free functionostream& operator<<(ostream& os, const Money& m)below the class so that an amount prints as a dollar sign, the whole dollars, a period, and the cents ALWAYS as two digits (pad with a leading zero when the cents part is below 10). Do not print a newline; returnos. Write toos, not tocout. Examples:Money(1205)prints$12.05,Money(7)prints$0.07,Money(250)prints$2.50. Do NOT write a main function.
Expected Output:
$12.05 $0.07 $2.50
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Streamsostream
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.