Write a C++ program: Redefine CDAccount from Display 10.1 so that it is a class
ID: 3771069 • Letter: W
Question
Write a C++ program:
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 rat 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.
Explanation / Answer
#include<iostream>
using namespace std;
class CDAccount{
private:
double balance,maturity,rate,term; \private member variables
public:
CDAccount(){ \default contructor
balance=0;
maturity=0;
rate=0;
term=0;}
CDAccount(double b,double m,double r,double t) \constructor that sets values as defined
{
balance= b;
maturity=m;
rate=r;
term=t;
}
double getBalance() \function to get balance
{
return balance;
}
double getMaturity() \function to get maturity
{
return maturity;
}
double getInterestRate() \function to get rate
{
return rate;
}
double getTerm() \function to get term
{
return term;
}
};
int main() \test function
{
CDAccount c1();
CDAccount c2(100.25,3000,5.25,7);
cout<<"Account balance: " <<c2.getBalance()<<endl;
cout<<"Maturity : "<<c2.getMaturity()<<endl;
cout<<"Interest Rate : "<<c2.getInterestRate()<<endl;
cout<<"Term : "<<c2.getTerm()<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.