Redo your definition of the class CDAccount from your currentprogramming > proje
ID: 3644964 • Letter: R
Question
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 <iostream>
#include <fstream>
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 << "Enter the CD initial balance (dollars and cents separately),
interest rate, and term."<< endl;
account.input(cin);
ofstream file_out;
file_out.open("Account_info.txt");
if (file_out.fail())
{
cout <<"Could not open file." << endl;
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 << "CD Account interest rate: " <<get_interest_rate()*100.
<<endl;// interest rate
ostr << "CD Account initial balance: " <<get_initial_dollars()
<<"."<<get_initial_cents()<< endl;//initial balance
ostr << "When your CD matures in " << get_term()<< " months," <<
endl;//cd maturity period inmonths
ostr << "it will have a balance of "
<<get_dollars_at_maturity()<<"."<<get_cents_at_maturity() << " dollars."
<< endl;//finalbalance after maturity
ostr << endl;
}
Explanation / Answer
//Modified Code #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 > term; } void CDAccount::output(ostream &ostr)//outputting member of class { ostr.setf(ios::fixed); ostr.setf(ios::showpoint); ostr.precision(2); ostrRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.