Question: CreditCard is a class with two double* data members pointing to the balance and interest rate of the credit card, respectively. Two doubles are read

CreditCard is a class with two double* data members pointing to the balance and interest rate of the credit card, respectively. Two doubles are read from input to initialize myCreditCard. Write a copy constructor for CreditCard that creates a deep copy of myCreditCard. At the end of the copy constructor, output "Called CreditCard's copy constructor" and end with a newline.

Ex: If the input is 96.00 1.00, then the output is:

Called CreditCard's copy constructor Initial balance: $96.00 with 2.00 interest rate Called CreditCard's copy constructor After 1 month(s): $288.00 After 2 month(s): $864.00 After 3 month(s): $2592.00 Custom value interest rate $96.00 with 1.00 interest rate

#include #include using namespace std;

class CreditCard { public: CreditCard(double startingBal = 0.0, double startingInterestRate = 0.0); CreditCard(const CreditCard& card); void SetBal(double newBal); void SetInterestRate(double newInterestRate); double GetBal() const; double GetInterestRate() const; void Print() const; private: double* bal; double* interestRate; };

CreditCard::CreditCard(double startingBal, double startingInterestRate) { bal = new double(startingBal); interestRate = new double(startingInterestRate); }

/* Your code goes here */

void CreditCard::SetBal(double newBal) { *bal = newBal; }

void CreditCard::SetInterestRate(double newInterestRate) { *interestRate = newInterestRate; }

double CreditCard::GetBal() const { return *bal; }

double CreditCard::GetInterestRate() const { return *interestRate; }

void CreditCard::Print() const { cout << fixed << setprecision(2) << "$" << *bal << " with " << *interestRate << " interest rate" << endl; }

void SimulateGrowth(CreditCard c, int months) { for (auto i = 1; i <= months; ++i) { c.SetBal(c.GetBal() * (c.GetInterestRate() + 1.0)); cout << "After " << i << " month(s): " << "$" << c.GetBal() << endl; } }

int main() { double bal; double interestRate;

cin >> bal; cin >> interestRate;

CreditCard myCreditCard(bal, interestRate); CreditCard myCreditCardCopy = myCreditCard; myCreditCard.SetInterestRate(interestRate + 1.0); cout << "Initial balance: "; myCreditCard.Print(); SimulateGrowth(myCreditCard, 3); cout << endl; cout << "Custom value interest rate" << endl; myCreditCardCopy.Print();

return 0; }

c++ and please please make it correct

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!