1. Redefine CDAccount from Display 10.1 so that it is a class rather than a stru
ID: 3881071 • Letter: 1
Question
1. Redefine CDAccount from Display 10.1 so that it is a class rather than a structure. Use the same member variables as in Display 10.1 but make them private. Include member functions for each of the following: one to return the initial balance, one to return the balance at maturity, one to return the interest rate, and one to return the term. Include a constructor that sets all of the member variables to any specified values, as well as a default constructor. Embed your class definition in a test program 2. Redo your definition of the class CDAccount from Practice Program 1 so that it has the same interface but a different implementation. The new implementation is in many ways similar to the second implementation for the class BankAccount given in Display 10.7. Your new implementation for the class CDAccount will record the balance as two values of type int: one for the dollars and one for the cents. The member variable for the interest rate will store the interest rate as a fraction rather than as a percentage. For example, an interest rate of 4.3% will be stored as the value 0.043 of type double. Store the term in the same wav as in Display 10.1Explanation / Answer
1) void CDAccount::input(istream& in){
private double balance;
in >> balance;
private double interest_rate;
in >> interest_rate;
private int term;
in >> term;
CDAccount();
CDAccount(double new_balance, double new_interest_rate, int new_term){
balance = new_balance;
interest_rate = new_interest_rate;
term = new_term;
}
public double get_initial_balance(){
return balance;
}
public double get_balance_at_maturity(){
return balance+balance*interest_rate/100*term;
}
double get_interest_rate(){
return interest_rate;
}
}
2) void CDAccount::input(istream& in){
private double balance;
in >> balance;
private int dollar = (int) balance;
private int cent = (int) ( (balance-dollar)*100 );
private double interest_rate;
in >> interest_rate;
interest_rate /= 100;
private int term;
in >> term;
CDAccount();
CDAccount(double new_balance, double new_interest_rate, int new_term){
balance = new_balance;
dollar = (int) balance;
cent = (int) ( (balance-dollar)*100 );
interest_rate = new_interest_rate/100;
term = new_term;
}
public double get_initial_balance(){
return balance;
}
public double get_balance_at_maturity(){
return balance+balance*interest_rate*term;
}
double get_interest_rate(){
return interest_rate;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.