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
#include <iostream>
#include <string>
using namespace std;
class Fixed_Deposit{
private:
long P_Amount;
int Years;
float Rate, R_Value;
public:
Fixed_Deposit(){
}
Fixed_Deposit(long p, int y, float r = 0.12){
P_Amount = p;
Years = y;
Rate = r;
R_Value = P_Amount + P_Amount*Rate*Years;
}
Fixed_Deposit(long p, int y, string r){
P_Amount = p;
Years = y;
Rate = stof(r)/100;
R_Value = P_Amount + P_Amount*Rate*Years;
}
void display(){
cout<<"P_Amount: "<<P_Amount<<"\nR_Value: "<<R_Value;
}
~Fixed_Deposit(){
cout<<"\n\nCalling destructor...";
}
};
int main(){
long P_Amount;
int Years, choice;
float Rate;
string rate;
Fixed_Deposit FD;
cout<<"Choose one of the following input formats:\n";
cout<<"1. Amount, Period and Interest in decimal form\n";
cout<<"2. Amount, Period and Interest in percentage form\n";
cout<<"3. Amount and Period\n";
cin>>choice;
cout<<"Enter Principal Amount\n";
cin>>P_Amount;
cout<<"Enter Period\n";
cin>>Years;
if(choice != 3){
cout<<"Enter Rate\n";
if(choice == 1){
cin>>Rate;
FD = Fixed_Deposit(P_Amount, Years, Rate);
}
if(choice == 2){
cin>>rate;
FD = Fixed_Deposit(P_Amount, Years, rate);
}
}
else FD = Fixed_Deposit(P_Amount, Years);
FD.display();
return 0;
}
Comments
Leave a comment