Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SavingsAccount is a class with two double* data members pointing to the balance and interest rate of the savings account, respectively. Two doubles are read

SavingsAccount is a class with two double* data members pointing to the balance and interest rate of the savings account, respectively. Two doubles are read from input to initialize userAccount. Use the copy constructor to create a SavingsAccount object named copyAccount that is a deep copy of userAccount.

Ex: If the input is 87.00 0.01, then the output is:

Original constructor called Produced a new SavingsAccount object userAccount: $87.00 with 1.00% interest rate copyAccount: $174.00 with 2.00% interest rate

#include #include using namespace std;

class SavingsAccount { public: SavingsAccount(double startingBalance = 0.0, double startingInterestRate = 0.0); SavingsAccount(const SavingsAccount& acc); void SetBalance(double newBalance); void SetInterestRate(double newInterestRate); double GetBalance() const; double GetInterestRate() const; void Print() const; private: double* balance; double* interestRate; };

SavingsAccount::SavingsAccount(double startingBalance, double startingInterestRate) { balance = new double(startingBalance); interestRate = new double(startingInterestRate); cout << "Original constructor called" << endl; }

SavingsAccount::SavingsAccount(const SavingsAccount& acc) { balance = new double; *balance = *(acc.balance); interestRate = new double; *interestRate = *(acc.interestRate); cout << "Produced a new SavingsAccount object" << endl; }

void SavingsAccount::SetBalance(double newBalance) { *balance = newBalance; }

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

double SavingsAccount::GetBalance() const { return *balance; }

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

void SavingsAccount::Print() const { cout << fixed << setprecision(2) << "$" << *balance << " with " << *interestRate * 100 << "\% interest rate" << endl; }

int main() { double balance; double interestRate;

cin >> balance; cin >> interestRate;

SavingsAccount userAccount(balance, interestRate); /* Your code goes here */ copyAccount.SetBalance(copyAccount.GetBalance() * 2); copyAccount.SetInterestRate(copyAccount.GetInterestRate() * 2);

cout << "userAccount: "; userAccount.Print(); cout << "copyAccount: "; copyAccount.Print();

return 0; }

c++ and please please make it correct

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago

Question

How are members held accountable for serving in the assigned roles?

Answered: 1 week ago