Answer to Question #194364 in C++ for Sarivinkumar M

Question #194364

Define a class Fixed_Deposit with the following specifications, the program uses three overloaded constructors. The parameter values to these constructors are provided at run time. The user can provide input in the following forms.


1. Amount, period and interest in decimal form.


2. Amount, period and interest in percent form.


3. Amount and period.


PRIVATE DATA MEMBERS:


P_Amount long int type Years integer type Rate float type R_value float type


PUBLIC MEMBER FUNCTIONS:


Fixed_Deposit() Null constructor


Fixed_Deposit(p, y, r=0.12) Parameterized constructor with default arguments to accept values for P_Amount, Years and Rate(in Percent e.g., 0.12, 0.09)


Fixed_Deposit(p, y, r) Parameterized constructor with default arguments to accept values for P_Amount, Years and Rate(in Decimal e.g, 12%, 8%)


display() Function to display the P_Amount and R_Value


~Fixed_Deposit() Destructor to destroy the data objects


Directories in your current workspace

\Home

Files in your current workspace

File Name


1
Expert's answer
2021-05-18T13:01:53-0400
#include <iostream>
using namespace std;


class Fixed_Deposit{


private:
	//P_Amount long int type Years integer type Rate float type R_value float type
	long int P_Amount;
	int Years;
	float Rate;
	float R_Value;


public:
	//Fixed_Deposit() Null constructor
	Fixed_Deposit(){
		
	}
	//Fixed_Deposit(p, y, r=0.12) Parameterized constructor with default arguments to accept values for P_Amount, Years and Rate(in Percent e.g., 0.12, 0.09)
	Fixed_Deposit(long int p, int y, float r = 0.12){
		P_Amount = p;
		Years = y;
		Rate = r;
		R_Value = P_Amount;
		for(int i=1;i<=y;i++){
			R_Value*=(1.0+Rate);		
		}
	}
	//Fixed_Deposit(p, y, r) Parameterized constructor with default arguments to accept values for P_Amount, Years and Rate(in Decimal e.g, 12%, 8%)
	Fixed_Deposit(long int p, int y, int r){
		P_Amount = p;
		Years = y;
		Rate = r/100.0;
		R_Value = P_Amount;
		for(int i=1;i<=y;i++){
			R_Value*=(1.0+Rate);		
		}
	}
	//display() Function to display the P_Amount and R_Value
	void display(){
		cout<<"\nPrincipal Amount: "<<P_Amount<<"\n";
		cout<<"Return Value: "<<R_Value<<"\n\n";
	}
	//~Fixed_Deposit() Destructor to destroy the data objects
	~Fixed_Deposit(){}
};
int main(){
	Fixed_Deposit fd;
	long int pa;
	float r;
	int y;
	int ch=-1;


	cout<<"1. Amount period and interest in decimal form.\n";
	cout<<"2. Amount period and interest in percent form.\n";
	cout<<"3. Amount and period.\n";
	while(ch<1 || ch>3){
		cout<<"> ";
		cin>>ch;
	}
	
	cout<<"Enter principal amount: ";
	cin>>pa;
	cout<<"Enter period: ";
	cin>>y;
	if(ch ==1 || ch==2){
		cout<<"Enter rate: ";
		cin>>r;
		if(ch == 1){
			fd = Fixed_Deposit(pa, y,(int)r);
		}else{
			fd = Fixed_Deposit(pa, y, r);	
		}
	}
	else{
		fd = Fixed_Deposit(pa, y);
	} 


	fd.display();
	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

LATEST TUTORIALS
APPROVED BY CLIENTS