Answer to Question #286078 in C++ for Khaleefah

Question #286078

Q1. 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.


1
Expert's answer
2022-01-09T10:43:48-0500


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment