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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started