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 * Years * Rate;
}
void display(){
cout<<"P_Amount: "<<P_Amount<<"\nR_Value: "<<R_Value;
}
~Fixed_Deposit(){
}
};
int main(){
long P_Amount;
float Rate;
int Years, option;
string r;
Fixed_Deposit F;
cout<<"Pick an input format:\n";
cout<<"1. Interest in decimal form, Amount, and Period\n";
cout<<"2. Interest in percentage form, Amount, and Period\n";
cout<<"3. Only Amount and Period\n";
cin>>option;
cout<<"Input Principal Amount: ";
cin>>P_Amount;
cout<<"Input Period: ";
cin>>Years;
if(option != 3){
cout<<"Input Rate: ";
if(option == 1){
cin>>Rate;
F = Fixed_Deposit(P_Amount, Years, Rate);
}
if(option == 2){
cin>>r;
F = Fixed_Deposit(P_Amount, Years, r);
}
}
else F = Fixed_Deposit(P_Amount, Years);
F.display();
return 0;
}
Comments
Leave a comment