Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help! I have to modify my C++ program below per these instructions: // P2_4a.cpp - This program adds money of two different people #include

Please help! I have to modify my C++ program below per these instructions:

image text in transcribed

// P2_4a.cpp - This program adds money of two different people #include #include using namespace std;

class AltMoney { public: AltMoney(); AltMoney(int d, int c); friend void add(AltMoney m1, AltMoney m2, AltMoney& sum); void display_money( ); private: int dollars; int cents; }; void read_money(int& d, int& c); int main( ) { int d, c; AltMoney m1, m2, sum;

sum = AltMoney(0,0); read_money(d, c); m1 = AltMoney(d,c); cout =100) { sum.cents = sum.cents - 100; extra = 1; } sum.dollars = m1.dollars + m2.dollars + extra; }

void read_money(int& d, int& c) { cout > d; cout > c; if( d 1. Modify the previous add function so that it becomes now a member function of the class AltMoney. The function takes the sum of dollars and cents of an object AltMoney and returns the result as an AltMoney. Note that in the above version of the program, the object sum has been passed by reference. Do not pass the sum any longer. 2. Add a new friend function, called subtract, that computes the subtraction of one money from another. 3. Modify read_money and make it member function of AltMoney. Note that if you make read_money a member function, then you can use it to directly initialize the dollars and cents of an AltMoney type object directly

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started