Question
Create a class called Money with the data members and member functions described below. Type the class declaration with data members and member function prototypes
Create a class called Money with the data members and member functions described below. Type the class declaration with data members and member function prototypes into a file named prog6.h. Enter all member function definitions in a file named prog6.cpp. Name your main (client) program file prog6client.cpp.
Private data members: dollars (int) cents (int)
Private member function: simplify checks for values in cents that are 100 or greater or less than 0, adjusts dollars and cents as needed so that cents amount is never greater than 99
Public member functions: Default constructor sets dollars and cents to zero
A second constructor that sets dollars and cents to the values passed to the constructor
Mutator (setters) and accessor (getters) to set and get the dollars and cents values
An overloaded + operator that adds two Money objects together
An overloaded - operator that subtracts two Money objects
An overloaded << operator that displays a Money object in the form $dd.cc
An overloaded >> operator that accepts values for a Money object entered as a double value (e.g., 5.25) and stores the dollars and cents amounts correctly in the Money object's data members
To demonstrate your Money class your main function in the client program should do the following using the overloaded operator functions for each step:
1. Instantiate four Money objects, one with the values 7 and 95 for dollars and cents, one with values 4 and 90 for the dollars and cents and the third and fourth with default values.
2. Display the value of all four Money objects using the overloaded << operator function of the Money class.
3. Add the first two Money objects together, storing the result in the third Money object. Display the result with an appropriate label.
4. Subtract the first two Money objects (subtract second from first), storing the result in the fourth Money object. Display the result with an appropriate label.
5. Prompt the user to enter a value (e.g. 5.25) and store it in the third Money object. Display the value stored in the third Money object. Program Documentation & Style Be sure your name, class and the due date are included at the beginning of each file. The standard header comments should be included in the client program file. Brief comments describing the purpose of each class member function should be in the class specification and/or implementation file. Label all output values with clear, descriptive labels. e.g., money1 ($7.95) plus money2 ($4.90) = money3 ($12.85)
BONUS Instructions
Write a loop that repeats 10 times, using the ++ operator (prefix) to add 1 cent each time to the first Money object.
Print its value after the loop.
Add 1.99 to the second Money object with the += operator and display the result.
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