Assume that a bank maintains two kinds of accounts, are called as saving account and current account. The saving account provides compound interest and withdrawal facilities but no cheque book facility. The current account provides cheque book facility but no interest. Current account holders should also maintain a minimum balance and if the balance falls below the level, a service charge is imposed. Create a class account that stores customer name, account number and type of account. From this derive the classes cur_acct and sav_acct to make them more specific to their requirements. Include necessary member functions in order to achieve the following tasks: a.Include constructor for all the three classes. b.Accept deposit amount from the customer and update the balance. c.Display the balance. d.Compute and deposit interest. e.Permit withdrawal and update the balance. f. Check for minimum balance, impose penalty, necessary and update the balance.



#include <iostream>
#include<cstring>
#include <cmath>
using namespace std;
#define minimum 500
#define service_charge 100
#define r 0.15
class account
{
protected:
    char name[100];
    int ac_number;
    char ac_type[100];

public:
    void creat(char *t);
};
void account::creat(char *t)
{
    cout << " Enter customer name :";
    gets(name);
    strcpy(ac_typet);
    cout << " Enter account number :";
    cin >> ac_number;
}
class cur_acct : public account
{
private:
    float balance;

public:
    void deposite(float d);
    void withdraw(float w);
    void display();
};
void cur_acct::deposite(float d)
{
    balance = d;
}
void cur_acct::withdraw(float w)
{
    if (balance < w)
        cout << " sorry your balance is less than your withdrawal amount \n";
    else
    {
        balance -= w;
        if (balance < minimum)
            cout << "\n your current balance is :" << balance << " which is less than" << minimum << "\n your account is discharged by " << service_charge << " TK \n "
                 << " You must store " << minimum << " TK to avoid discharge \n "
                 << " Do you want to withdraw? press 1 for yes press 0 for no \n "
                 << " what is your option ? ";
        int test;
        cin >> test;
        if (test == 0)
            balance += w;
    }
}
void cur_acct::display()
{
    cout << "\n Now balance = " << balance << "\n";
}
class sav_acct : public account
{
    float balance;
    int dmy;

public:
    void deposite(float d);
    void withdraw(float w);
    void display();
    void set_date(int aint bint c)
    {
        d = a;
        m = b;
        y = c;
    }
    void interest();
};
void sav_acct::deposite(float d)
{
    int xyz;
    cout << " Enter today's date(i,e day,month,year) : ";
    cin >> x >> y >> z;
    set_date(xyz);
    balance = d;
}
void sav_acct::withdraw(float w)
{
    if (balance < w)
        cout << " sorry your balance is less than your withdrawal amount \n";
    else
    {
        balance -= w;
        if (balance < minimum)
        {
            cout << "\n your current balance is :" << balance << " which is less than" << minimum << "\n your account is discharged by " << service_charge << "TK \n"
                 << " You must store  " << minimum << " TK to avoid discharge \n "
                 << " Do you want to withdraw ? press 1 for yes press 0 for no \n "
                 << " what is your option ? ";
            int test;
            cin >> test;
            if (test == 0)
                balance += w;
        }
    }
}
void sav_acct::display()
{
    cout << "\n Now balance = " << balance;
}
void sav_acct::interest()
{
    int D[12] = {312831303130313130313031};
    int d1y1m1;
    cout << " Enter today's date :(i,e day,month,year) ";
    cin >> d1 >> m1 >> y1;
    int idayfday;
    iday = d;
    fday = d1;
    for (int i = 0i < m1i++)
    {
        fday += D[i];
    }
    for (int i = 0i < mi++)
    {
        iday += D[i];
    }
    int tday;
    tday = fday - iday;
    float ty;
    ty = float(tday) / 365 + y1 - y;
    float intrst;
    intrst = ty * r * balance;
    cout << " Interest is : " << intrst << "\n";
    balance += intrst;
}
int main()
{
    sav_acct santo;
    santo.creat("savings");
    float d;
    cout << " Enter your deposit amount : ";
    cin >> d;
    santo.deposite(d);
    santo.display();
    int t;
    cout << "\n press 1 to see your interest : \n"
         << " press 0 to skip : ";
    cin >> t;
    if (t == 1)
        santo.interest();
    cout << "\n Enter your withdrawal amount :";
    float w;
    cin >> w;
    santo.withdraw(w);
    santo.display();
    return 0;
}


output :
Enter customer name :Rahul Enter account number :3323 Enter your deposit amount : 700 Enter today's date(i,e day,month,year) : 23 4 2018 Now balance = 700 press 1 to see your interest : press 0 to skip : 1 Enter today's date :(i,e day,month,year) 5 6 2021 Interest is : 327.37 Enter your withdrawal amount :600 your current balance is :427.37 which is less than500 your account is discharged by 100TK You must store 500 TK to avoid discharge Do you want to withdraw ? press 1 for yes press 0 for no what is your option ? 1 Now balance = 427.37


Comments