Program to create a saving account using class.

This is a basic c++ program to crate a saving account using class.

 

INPUT – time, rate of interest & balance

OUTPUT – Balance after that time.

Description:

We have to take the balance, rate of interest and time [in months] as input from user and display the balance which user will have after that time interval.

 

Code:

#include<iostream>
using namespace std;
class bank
{

 static float rate;;
    static float rate1;
    static float bal;
    int time;
    int amount;
    int case1;
public:
    void getdata();
    void display();
};
float bank::rate;
float bank::bal;
float bank::rate1;

int main()
{
    bank b1,b2;
    b1.getdata();
    b1.display();
}

void bank::getdata()
{
    cout<<"Enter your current balance"<<endl;
    cin>>bal;
    cout<<"Enter the time (in months) after which you want to deposit/withdraw."<<endl;
    cin>>time;
    cout<<"Enter the rate of interest"<<endl;
    cin>>rate;
    cout<<"Choose Operation"<<endl<<"1. Withdraw"<<endl<<"2. Deposit"<<endl;
    cin>>case1;
    cout<<"Enter the amount"<<endl;
    cin>>amount;

}

void bank::display()
{
    rate1=0.01*rate;
    switch(case1)
    {
    case 1:
    bal+=(bal*rate1*time)/12-amount;
    break;

    case 2:
        bal+=(bal*rate1*time)/12+amount;
        break;

    default:
        cout<<"Invalid option."<<endl;

    }
    cout<<"Your current balance is "<<bal;

}

 

Leave a Reply

Your email address will not be published.