Question: Redo Practice Programs 1 from Chapter 11 , but this time define the Money ADT class in separate files for the interface and implementation so
Redo Practice Programs 1 from Chapter 11 , but this time define the Money ADT class in separate files for the interface and implementation so that the implementation can be compiled separately from any application program.
_____
TURN IN THREE FILES: Namely YourNameMoney.cpp file (this file contains only the Money class implementation), YourNameProj4.cpp (this file contains only main function to use/test your money class), and YourNameMoney.h file, by clicking on the above Proj4 link, then clicking on "Browse My Computer" button.
_____
Practice Program 1 From Chapter 11:
Modify the definition of the class Money shown in Display 11.8 so that all of the following are added:
a. The operators , and >= have each been overloaded to apply to the type Money. (Hint: See Self-Test Exercise 13.)
b. The following member function has been added to the class definition. (We show the function declaration as it should appear in the class definition. The definition of the function itself will include the qualifier Money::.)
Money percent(int percentFigure) const;
//Returns a percentage of the money amount in the
//calling object. For example, if percentFigure is 10,
//then the value returned is 10% of the amount of
//money represented by the calling object.
For example, if purse is an object of type Money whose value represents the amount $100.10, then the call
purse.percent(10);
returns 10% of $100.10; that is, it returns a value of type Money that represents the amount $10.01.
_____
Display 11.8




DISPLAY 11.8 Overloading >(part 1 of 4) 1 //Program to demonstrate the class Money This is an improved version #include #include #include #1 nclude using namespace std; of the class Money that we gave in Display 11.6 Although we have omitted 3 4 6 7 some of the comments from Displays 11.5 and 11.6 8 IIClass for amounts of money in U.S. currency. 9class Money you should include them. 10 11 12 public: friend Money operatorCconst Money& amountl, const Money& amount2); friend Money operator -(const Money&amountl, const Money& amount2); friend Money operator -(const Money& amount); 13 14 (continued) DISPLAY 11.8 Overloading (part 2 of 4) 15 16 17 18 friend bool operator (const Money& amountl, const Money& amount2) Money(long dollars, int cents) Money(long dollars) Money) 19 double getvalue const 20 21 friend istream& operator >Cistream& ins, Money& amount); //Overloads the operator so it can be used to input vaTues of type Money //Notation for inputting negative amounts is as in -$100.00 //Precondition: If ins is a file input stream, then ins has already been //connected to a file 23 friend ostream& operator > 35 /Precondition: c is one of the digits '0'through '9'. 36 //Returns the integer for the digit; for example, digit to_int('3 37 38 int mainC) 39 40 ong all_cents; returns 3 Money amount; ifstream in_stream ofstream out stream; 42 43 in stream.open C"infile.dat"); if (in_stream.fail()) 46 47 cout (part 3 of 4) 57 58 59 60 61 62 63 64 65 in stream amount; out_stream >Cistream& ins, Money& amount) 71 72 73 74 75 76 return 0 char one_char, decimal_point, digitl, digit2; //digits for the amount of cents long dollars; int cents; bool negative://set to true if input is negative ins >> one_char if Cone_char-") 78 79 80 81 82 83 negative -true; ins >one_char; //read e1se negativefalse; 85 86 87 if input is 1egal, then one char' ins >> dollars >> decimal_point >digitl digit2; if Cone_char !'S decimal_point ! '.' Il lisdigit(digit1) |I lisdigit(digit2)) 89 90 91 92 cout (part 4 of 4) 100 nt digit to_int(char c) 101 102 103 return ( static cast(c) - static_castC'0; 104 //Uses cstdlib and iostream: 105 ostream& operator infile.dat outfile.dat (Not changed by program.) After program is run.) $1.11 S2.22 $3.33 $1.11 copied from the file infile.dat Screen Output $1.11 copied from the file infile.dat. DISPLAY 11.8 Overloading >(part 1 of 4) 1 //Program to demonstrate the class Money This is an improved version #include #include #include #1 nclude using namespace std; of the class Money that we gave in Display 11.6 Although we have omitted 3 4 6 7 some of the comments from Displays 11.5 and 11.6 8 IIClass for amounts of money in U.S. currency. 9class Money you should include them. 10 11 12 public: friend Money operatorCconst Money& amountl, const Money& amount2); friend Money operator -(const Money&amountl, const Money& amount2); friend Money operator -(const Money& amount); 13 14 (continued) DISPLAY 11.8 Overloading (part 2 of 4) 15 16 17 18 friend bool operator (const Money& amountl, const Money& amount2) Money(long dollars, int cents) Money(long dollars) Money) 19 double getvalue const 20 21 friend istream& operator >Cistream& ins, Money& amount); //Overloads the operator so it can be used to input vaTues of type Money //Notation for inputting negative amounts is as in -$100.00 //Precondition: If ins is a file input stream, then ins has already been //connected to a file 23 friend ostream& operator > 35 /Precondition: c is one of the digits '0'through '9'. 36 //Returns the integer for the digit; for example, digit to_int('3 37 38 int mainC) 39 40 ong all_cents; returns 3 Money amount; ifstream in_stream ofstream out stream; 42 43 in stream.open C"infile.dat"); if (in_stream.fail()) 46 47 cout (part 3 of 4) 57 58 59 60 61 62 63 64 65 in stream amount; out_stream >Cistream& ins, Money& amount) 71 72 73 74 75 76 return 0 char one_char, decimal_point, digitl, digit2; //digits for the amount of cents long dollars; int cents; bool negative://set to true if input is negative ins >> one_char if Cone_char-") 78 79 80 81 82 83 negative -true; ins >one_char; //read e1se negativefalse; 85 86 87 if input is 1egal, then one char' ins >> dollars >> decimal_point >digitl digit2; if Cone_char !'S decimal_point ! '.' Il lisdigit(digit1) |I lisdigit(digit2)) 89 90 91 92 cout (part 4 of 4) 100 nt digit to_int(char c) 101 102 103 return ( static cast(c) - static_castC'0; 104 //Uses cstdlib and iostream: 105 ostream& operator infile.dat outfile.dat (Not changed by program.) After program is run.) $1.11 S2.22 $3.33 $1.11 copied from the file infile.dat Screen Output $1.11 copied from the file infile.dat