Define a class Deposit that has a principal, a rate of interest, which is fixed for all
deposits and a period in terms of years. Write member functions to
(i) alter(float) which can change the rate of interest.
(ii) interest() which computes the interest and returns it.
(iii) print() which prints data as shown below. Note that the width of each column is 20.
�
#include <iostream>
#include <iomanip>
using namespace std;
class Deposit{
private:
float principal;
float rateInterest;
int years;
public:
Deposit(){
this->principal=1100.00;
this->rateInterest=2;
this->years=1;
}
//(i) alter(float) which can change the rate of interest.
void alter(float newRateInterest){
this->rateInterest=newRateInterest;
}
//(ii) interest() which computes the interest and returns it.
float interest(){
return (this->principal*this->years*this->rateInterest)/100.0;
}
//(iii) print() which prints data as shown below. Note that the width of each column is 20.
void print(){
cout<<fixed<<"Principal"<<setw(20)<<"Year"<<setw(20)<<"Interest\n";
cout<<setprecision(2)<<principal<<setw(20)<<years<<setw(20)<<interest()<<"\n";
}
};
int main() {
Deposit deposit;
deposit.print();
system("pause");
return 0;
}
Comments
Leave a comment