CJCoding With Joseph
15free / daySign inCreate account

operator<< for Money

A class Money that stores a whole number of cents is given, together with a friend declaration for operator<<. Define the free function ostream& 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; return os. Write to os, not to cout.

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
Topics:
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.