Answer to Question #174184 in C++ for Harini.M

Question #174184

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


1
Expert's answer
2021-03-26T16:23:04-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){
		this->P_Amount = p;
		this->Years = y;
		this->Rate = r;
		this->R_Value = P_Amount;
		for(int i=1;i<=y;i++){
			this->R_Value*=(1.0+r);
		}
	}
	//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){
		this->P_Amount = p;
		this->Years = y;
		this->Rate = r/100.0;
		this->R_Value = P_Amount;
		for(int i=1;i<=y;i++){
			this->R_Value*=(1.0+this->Rate);		
		}
	}
	//display() Function to display the P_Amount and R_Value
	void display(){
		cout<<"\nPrincipal Amount: "<<this->P_Amount<<"\n";
		cout<<"Return Value: "<<this->R_Value<<"\n\n";
	}
	//~Fixed_Deposit() Destructor to destroy the data objects
	~Fixed_Deposit(){}
};
int main(){
	Fixed_Deposit fixed_Deposit;
	long int P_Amount;
	float Rate;
	int Years;
	int choice=-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(choice<1 || choice>3){
		cout<<"Your choice: ";
		cin>>choice;
	}
	
	cout<<"Enter Principal Amount: ";
	cin>>P_Amount;
	cout<<"Enter Period: ";
	cin>>Years;
	if(choice ==1 || choice==2){
		cout<<"Enter Rate: ";
		cin>>Rate;
		if(choice == 1){
			fixed_Deposit = Fixed_Deposit(P_Amount, Years, Rate);
		}
		if(choice == 2){
			fixed_Deposit = Fixed_Deposit(P_Amount, Years,(int)Rate);
		}
	}
	else{
		fixed_Deposit = Fixed_Deposit(P_Amount, Years);
	} 


	fixed_Deposit.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
New on Blog
APPROVED BY CLIENTS