Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Redo your definition of the class CDAccount from your currentprogramming > project so that it has the same interface but a different implementation. > The
Redo your definition of the class CDAccount from your currentprogramming > project so that it has the same interface but a different implementation. > The new implementation for the classCDAccount will record the balance as > two values of type int:one for dollars and one for cents. The member > variable for theinterest rate will store the interest rate as a fraction > ratherthan as a percentage. For example, an interest rate of 5.9 % willbe > stored as the value of 0.059 of type double. #include #include using namespace std; class CDAccount { public: CDAccount(); //defaultconstructor CDAccount (int new_dollars,int new_cents,double new_interest_rate,int new_term); //parameterizedconstruction int get_initial_dollars();//function declaration int get_dollars_at_maturity(); int get_initial_cents();//function declaration int get_cents_at_maturity(); double get_interest_rate(); int get_term (); void input (istream&istr); void output (ostream&ostr); private://variable declaration int dollars; //balance int cents; double interest_rate;//interest rate in % int term; //month cd willmature in }; int main()//declaring objects with parameters { CDAccount account (100,0, 10,6); account.output(cout); cout interest rate, and term.\" account.input(cin); ofstream file_out; file_out.open(\"Account_info.txt\"); if (file_out.fail()) { cout \"could> exit(1); } account.output(file_out); file_out.close(); system(\"pause\"); return 0; } CDAccount::CDAccount() { dollars = 0; cents=0; interest_rate = 0; term = 0; } CDAccount::CDAccount (int new_dollars,int new_cents, double new_interest_rate, int new_term) : dollars(new_dollars),cents(new_cents),interest_rate(new_interest_rate/10 0.), term(new_term) { } int CDAccount::get_initial_dollars () { return dollars;//returnsbalance-original } int CDAccount::get_initial_cents () { return cents;//returnsbalance-original } int CDAccount::get_dollars_at_maturity() { double interest = (dollars+(cents/100)) *interest_rate * (term/12.0); return (int)(dollars+ interest);//returnsfinal balance after maturity } int CDAccount::get_cents_at_maturity () { double interest = (dollars+(cents/100) ) *interest_rate * (term/12.0); return (int)(dollars+(cents/100) +interest)%100;//returns final balance after maturity } double CDAccount::get_interest_rate () { return interest_rate;//return interestrate } int CDAccount::get_term () { return term;//returns term } void CDAccount::input (istream&istr)//data inputting { istr >> dollars; istr >> cents; istr >> interest_rate; interest_rate/=100.; istr >> term; } void CDAccount::output(ostream &ostr)//outputting member of class { ostr.setf(ios::fixed); ostr.setf(ios::showpoint); ostr.precision(2); ostr ;> ostr ostr endl;//cd maturity period inmonths ostr ()> ostr }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started