Question: 1 . Change the add function, so that it receives two AltMoney objects which it adds together and returns one object AltMoney as the result
Change the add function, so that it receives two AltMoney objects which it adds together
and returns one object AltMoney as the result of the addition.
Note that in the above version of the program, you have passed the object sum as callbyreference.
Add a new friend function, subtract, that computes the subtraction of one money from the
other. This function must receive by parameters two AltMoney objects which it will
subtract and return an AltMoney object with the result.
Make readmoney a member function. Note that if you make readmoney a member
function, then you can use it to directly initialize the dollars and cents of an AltMoney type
object directly.
#include
#include
using namespace std;
class AltMoney
public:
AltMoney;
AltMoneyint d int c;
friend void addAltMoney m AltMoney m AltMoney ∑
void displaymoney;
private:
int dollars;
int cents;
;
void readmoneyint& d int& c;
int main
int d c;
AltMoney m m sum;
sum AltMoney;
readmoneyd c;
m AltMoneyd c;
cout "The first money is:;
mdisplaymoney;
readmoneyd c;
m AltMoneyd c;
cout "The second money is:;
mdisplaymoney;
addm m sum;
cout "The sum is:;
sum.displaymoney;
return ;
AltMoney::AltMoney
AltMoney::AltMoneyint d int c
dollars d;
cents c;
void AltMoney::displaymoney
cout $ dollars ;
ifcents
cout ; to display a in the left for numbers less than
cout cents endl;
void addAltMoney m AltMoney m AltMoney &sum
int extra ;
sum.cents mcents mcents;
ifsumcents
sum.cents sum.cents ;
extra ;
sum.dollars mdollars mdollars extra;
void readmoneyint &d int &c
cout "Enter dollar
;
cin d;
cout "Enter cents
;
cin c;
if d c
cout "Invalid dollars and cents, negative values
;
exit;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
