Question: C++ Write a class called Money with overloaded operator < < to print a Money object to an ostream in standard format ($0.00). Include a

C++

Write a class called Money with overloaded operator<< to print a Money object to an ostream in standard format ($0.00).

Include a default constructor that makes a Money object have value $0.00, also a constructor that takes two integers (dollars and cents), and also a constructor that takes a double (in dollars, you should round appropriately if it is not an integral number of cents, so 45.678 should become $45.68, and 45.671 should become $45.67. Be careful to make this work properly for negative amounts too). Also include a copy constructor. Also include an operator= to be able to assign Money objects.

A main function should be able to print the following:

const Money con0;

cout << con0 << endl; //$0.00

cout << Money (2, 2) << endl; //$2.02

cout << Money(2.02) << endl; //$2.02

cout << Money(-3.03) << endl; //-$3.03

cout << Money(7.072) << endl; //$7.07

cout << Money(7.077) << endl; //$7.08

cout << Money(-7.072) << endl; //-$7.07

cout << Money(-7.077) << endl; //-$7.08

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!