Only in c++ please. Just need the solution code. Thank you. SavingsAccount is a class with two double* data members pointing to the amount saved and interest rate of the savings account, respectively. Two doubles are read from input to initialize mySavingsAccount. Write a copy constructor for SavingsAccount that creates a deep copy of mySavingsAccount. At the end of the copy constructor, output "Produced a new SavingsAccount object" and end with a newline. Ex: If the input is 78.00 1.00, then the output is: Produced a new SavingsAccount object Initial amount saved: $78.00 with 2.00 interest rate Produced a new SavingsAccount object After 1 month(s): $234.00 After 2 month(s): $702.00 After 3 month(s): $2106.00 After 4 month(s): $6318.00 After 5 month(s): $18954.00 Custom value interest rate $78.00 with 1.00 interest rate#include #include using namespace std; class SavingsAccount { public: SavingsAccount(double startingAmount = 0.0, double startingRate = 0.0); SavingsAccount(const SavingsAccount& acc); void SetAmount(double newAmount); void SetRate(double newRate); double GetAmount() const; double GetRate() const; void Print() const; private: double* amount; double* rate; }; SavingsAccount::SavingsAccount(double startingAmount, double startingRate) { amount = new double(startingAmount); rate = new double(startingRate); } /* Your code goes here */ void SavingsAccount::SetAmount(double newAmount) { *amount = newAmount; } void SavingsAccount::SetRate(double newRate) { *rate = newRate; } double SavingsAccount::GetAmount() const { return *amount; } double SavingsAccount::GetRate() const { return *rate; } void SavingsAccount::Print() const { cout << fixed << setprecision(2) << "$" << *amount << " with " << *rate << " interest rate" << endl; } void SimulateGrowth(SavingsAccount c, int months) { for (auto i = 1; i <= months; ++i) { c.SetAmount(c.GetAmount() * (c.GetRate() + 1.0)); cout << "After " << i << " month(s): " << "$" << c.GetAmount() << endl; } } int main() { double amount; double rate; cin >> amount; cin >> rate; SavingsAccount mySavingsAccount(amount, rate); SavingsAccount mySavingsAccountCopy = mySavingsAccount; mySavingsAccount.SetRate(rate + 1.0); cout << "Initial amount saved: "; mySavingsAccount.Print(); SimulateGrowth(mySavingsAccount, 5); cout << endl; cout << "Custom value interest rate" << endl; mySavingsAccountCopy.Print(); return 0; }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section12.2: Providing Class Conversion Capabilities
Problem 5E
icon
Related questions
Question

Only in c++ please. Just need the solution code. Thank you.

SavingsAccount is a class with two double* data members pointing to the amount saved and interest rate of the savings account, respectively. Two doubles are read from input to initialize mySavingsAccount. Write a copy constructor for SavingsAccount that creates a deep copy of mySavingsAccount. At the end of the copy constructor, output "Produced a new SavingsAccount object" and end with a newline.

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

Produced a new SavingsAccount object Initial amount saved: $78.00 with 2.00 interest rate Produced a new SavingsAccount object After 1 month(s): $234.00 After 2 month(s): $702.00 After 3 month(s): $2106.00 After 4 month(s): $6318.00 After 5 month(s): $18954.00 Custom value interest rate $78.00 with 1.00 interest rate#include <iostream> #include <iomanip> using namespace std; class SavingsAccount { public: SavingsAccount(double startingAmount = 0.0, double startingRate = 0.0); SavingsAccount(const SavingsAccount& acc); void SetAmount(double newAmount); void SetRate(double newRate); double GetAmount() const; double GetRate() const; void Print() const; private: double* amount; double* rate; }; SavingsAccount::SavingsAccount(double startingAmount, double startingRate) { amount = new double(startingAmount); rate = new double(startingRate); } /* Your code goes here */ void SavingsAccount::SetAmount(double newAmount) { *amount = newAmount; } void SavingsAccount::SetRate(double newRate) { *rate = newRate; } double SavingsAccount::GetAmount() const { return *amount; } double SavingsAccount::GetRate() const { return *rate; } void SavingsAccount::Print() const { cout << fixed << setprecision(2) << "$" << *amount << " with " << *rate << " interest rate" << endl; } void SimulateGrowth(SavingsAccount c, int months) { for (auto i = 1; i <= months; ++i) { c.SetAmount(c.GetAmount() * (c.GetRate() + 1.0)); cout << "After " << i << " month(s): " << "$" << c.GetAmount() << endl; } } int main() { double amount; double rate; cin >> amount; cin >> rate; SavingsAccount mySavingsAccount(amount, rate); SavingsAccount mySavingsAccountCopy = mySavingsAccount; mySavingsAccount.SetRate(rate + 1.0); cout << "Initial amount saved: "; mySavingsAccount.Print(); SimulateGrowth(mySavingsAccount, 5); cout << endl; cout << "Custom value interest rate" << endl; mySavingsAccountCopy.Print(); return 0; } 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning