Question: 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

YourNameMoney.cpp file (this file contains only the Money class implementation), YourNameProj4.cpp (thisYourNameMoney.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

Please help me make YourNameMoney.cpp file and YournameMoney.h file

________________________________________________ #include #include #include #include using namespace std;

//Create a class name, Money class Money { public:

//Define the methods friend bool operator (const Money& price1, const Money& price2); friend bool operator >= (const Money& price1, const Money& price2); friend const Money operator + (const Money& amount1, const Money& amount2); friend const Money operator - (const Money& amount1, const Money& amount2); friend bool operator == (const Money& amount1, const Money& amount2); friend const Money operator - (const Money& amount); friend ostream& operator > (istream& inputStream, Money& amount); Money(); Money(double amount); Money(int dol, int cen); Money(int dol); double findTotalamount() const; int findTotaldolloars() const; int findTotalcents() const; const Money percent(int percent_figure) const; private: //Member variables int dollars; int cents; int dType(double amount) const; int cType(double amount) const; int roundedNumber(double number) const; }; //Program begins with a main function int main() { //Class object Money amount; Money systemAmount(50, 5); int p; //For input file variable ifstream in_stream; //For output file variable ofstream out_stream; //Open the input file in_stream.open("infile.dat"); if (in_stream.fail()) { //Display an error message cout

} //Open the output file out_stream.open("outfile.dat"); if (out_stream.fail()) { //Display an error message cout > amount; in_stream >> p; //Display the output cout cout cout cout //Compare the amounts if (amount == systemAmount) cout Money sumAmount = amount + systemAmount; cout Money diffAmount = amount - systemAmount; cout if (amount >= systemAmount) cout diffAmount) cout cout cout in_stream.close(); out_stream.close(); system("pause"); }//End main

//Method definition of operator bool operator { //Return output value return (price1.dollars (price1.cents }

//Method definition of operator bool operator //Method definition of operator> bool operator > (const Money& price1, const Money& price2) { //Return output value return (price1.dollars > price2.dollars) || ((price1.dollars == price2.dollars) && (price1.cents > price2.cents)); }

//Method definition of operator >= bool operator >=(const Money& price1, const Money& price2) { //Return output value return ((price1.dollars > price2.dollars) || ((price1.dollars == price2.dollars) && (price1.cents > price2.cents))) || ((price1.dollars == price2.dollars) && (price1.cents == price2.cents)); }

//Method definition of percent const Money Money::percent(int per) const { int ds = dollars * per / 100; int cs = dollars * per % 100 + cents * per / 100; return Money(ds, cs); }

//Method definition of operator+ const Money operator + (const Money& amount1, const Money& amount2) { int c1 = amount1.cents + amount1.dollars * 100; int c2 = amount2.cents + amount2.dollars * 100; int totalCents = (c1 + c2); int absCents = abs(totalCents); int totDollars = absCents / 100; int totCents = absCents % 100; if (totalCents //Return output value return Money(totDollars, totCents); } //Method definition of operator- with two parameters const Money operator -(const Money& amount1, const Money& amount2) { int c1 = amount1.cents + amount1.dollars * 100; int c2 = amount2.cents + amount2.dollars * 100; int differCents = c1 - c2; int absCents = abs(differCents); int totDollars = absCents / 100; int totCents = absCents % 100; if (differCents //Method definition of operator== bool operator == (const Money& amount1, const Money& amount2) { //Return output value return((amount1.dollars == amount2.dollars) && (amount1.cents == amount2.cents)); } //Method definition of operator- with one parameter const Money operator - (const Money& amount) { //Return output value return Money(-amount.dollars, -amount.cents); }

Money::Money() : dollars(0), cents(0) { } Money::Money(double amount) : dollars(dType(amount)), cents(cType(amount)) { } Money::Money(int dol) : dollars(dol), cents(0) { } Money::Money(int dol, int cen) { if ((dol 0) || (dol > 0 && cen (amount); } //Method definition of cType int Money::cType(double amount) const { double doubleCents = amount * 100; int intCents = (roundedNumber(fabs(doubleCents))) % 100; if (amount ; } //Method definition of roundedNumber int Money::roundedNumber(double number) const { //Return output value return floor(number + 0.5); } ostream& operator = 10) outputStream

istream& operator >> (istream& inputStream, Money& amount) { char dollarSign; inputStream >> dollarSign; if (dollarSign != '$') { cout > incrementAmount; amount.dollars = amount.dType(incrementAmount); amount.cents = amount.cType(incrementAmount); return inputStream; }

Redo Practice Programs 1 11, time Money from Chapter but this define the ADT class in separate files for the interface and implementation so that the implementation can be compiled separately from any application program

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!