Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Homework HelpRSS Feeds

CREATING A CLASS ACCOUNTS FROM WHICH ARE DERIVED TWO CLASSES CURRENT AND SAVINGS AND THEN ASK THE USER FOR THE TYPE OF ACCOUNT HE WANTS TO CREATE

Posted By: Faith Hughes     Category: C++ Programming     Views: 11761

PROGRAM FOR CREATING A CLASS ACCOUNTS FROM WHICH ARE DERIVED TWO CLASSES CURRENT AND SAVINGS AND THEN ASK THE USER FOR THE TYPE OF ACCOUNT HE WANTS TO CREATE.

Code for CREATING A CLASS ACCOUNTS FROM WHICH ARE DERIVED TWO CLASSES CURRENT AND SAVINGS AND THEN ASK THE USER FOR THE TYPE OF ACCOUNT HE WANTS TO CREATE in C++ Programming

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<iomanip.h>


class account
{
    protected:

        char name[30];
        int ano;
        char type;
    public:
        account(){}
};

class save_acct:private account
{
    float balance;
    float deposit;
    float withdraw;
    float rate;
    int term;
    public:
        save_acct()
        {
            balance=0.0;
            deposit=0.0;
            withdraw=0.0;
            rate=0.0;
            term=0;
        }
        void getdata(char acname[],int acno,char atype)
        {
            clrscr();
            cout<<"\nDETAILS FOR THE SAVINGS ACCOUNT";
            strcpy(name,acname);
            cout<<"\n\nACCOUNT HOLDERS NAME      :"<<name;
            ano=acno;
            cout<<"\nACCOUNT NUMBER            :"<<ano;
            type=atype;
            cout<<"\nACCOUNT TYPE              :"<<type;
            while(1)
            {
                cout<<"\nENTER THE BALANCE         :";
                cin>>balance;
                if(balance<=0)
                {
                    cout<<"\nBALANCE MUST BE GREATER THAN ZERO";
                    getch();
                    continue;
                }
                elsebreak;
            }
            while(1)
            {
                cout<<"ENTER THE INTEREST RATE   :";
                cin>>rate;
                if(rate<=0)
                {
                    cout<<"\nRATE MUST BE GREATER THAN ZERO";
                    getch();
                    continue;
                }
                elsebreak;
            }
            while(1)
            {
                cout<<"ENTER THE TERM            :";
                cin>>term;
                if(term<=0)
                {
                    cout<<"\nTERM MUST BE GREATER THAN ZERO";
                    getch();
                    continue;
                }
                elsebreak;
            }
            cout<<"\n\nCHEQUE BOOKS NOT ISSUED FOR SAVINGS ACCOUNT";
            getch();
        }
        void sdeposit()
        {
            while(1)
            {
                clrscr();
                cout<<"\nMONEY DEPOSIT SCREEN";
                cout<<"\n\nENTER THE AMOUNT YOU WANT TO DEPOSIT        :";
                cin>>deposit;
                if(deposit<=0)
                {
                    cout<<"\nDEPOSIT MUST BE OVER Rs. 0";
                    getch();
                    continue;
                }
                else
                {
                    balance=balance+deposit;
                    cout<<"\n\nTHE BALANCE AFTER MAKING DEPOSIT IS        :"<<balance;
                    getch();
                    break;
                }
        }
        }
        void swithdraw()
        {
            clrscr();
            cout<<"\nMONEY WITHDRAWAL SCREEN";
            cout<<"\n\nENTER THE WITHDRAWAL AMOUNT            :";
            cin>>withdraw;
            float temp;
            temp=balance-withdraw;
            if(temp<0)
            {
                cout<<"\nILLEGAL WITHDRAWAL BALANCE COMES TO LESS THAN ZERO";
                cout<<"\n\nCANNOT ALLOW TO WITHDRAW";
                getch();
            }
            else
            {
                balance=balance-withdraw;
                cout<<"\n\nTHE BALANCE AFTER WITHDRAWAL IS    :"<<balance;
                getch();
            }
        }
        void interest()
        {
            clrscr();
            cout<<"\nINTEREST CALCULATION SCREEN";
            cout<<"\n\nINTEREST CALCULATED AT "<<rate<<"% FOR "<<term<<" YEARS";
            float ibal;
            for(int ctr=1;ctr<=term;ctr++)
            {
                ibal=(balance*rate)/100;
                balance=balance+ibal;
            }
            cout<<"\n\nBALANCE AFTER ADDING INTEREST IS        :"<<setprecision(3)<<balance;
            getch();
        }
        void sdisplay()
        {
            clrscr();
            cout<<"\n\nLATEST BALANCE IS        : Rs. "<<balance;
            getch();
        }

};

class curr_acct:public account
{
    float minbal;
    float balance;
    float deposit;
    float withdraw;
    float pen;
    public:
        curr_acct()
        {
            minbal=1000.00;
            balance=0.0;
            deposit=0.0;
            withdraw=0.0;
            pen=300.00;
        }
        void getdata(char acname[],int acno,char atype)
        {
            clrscr();
            cout<<"\nDETAILS FOR THE CURRENT ACCOUNT";
            strcpy(name,acname);
            cout<<"\n\nACCOUNT HOLDERS NAME      :"<<name;
            ano=acno;
            cout<<"\nACCOUNT NUMBER            :"<<ano;
            type=atype;
            cout<<"\nACCOUNT TYPE              :"<<type;
            while(1)
            {
                cout<<"\nENTER THE BALANCE         :";
                cin>>balance;
                if(balance<minbal)
                {
                    cout<<"\nBALANCE CANNOT BE LESS THAN Rs. "<<minbal;
                    continue;
                }
                elsebreak;
            }
            cout<<"\n\nCHEQUE BOOK ISSUED FOR ACCOUNT NUMBER "<<ano;
            getch();
        }
        void cdeposit()
        {
            clrscr();
            cout<<"\nMONEY DEPOSIT SCREEN";
            if(balance<minbal)
            {
                cout<<"\n\nBALANCE LESS THAN Rs. "<<minbal;
                cout<<"\nPENALTY OF Rs. "<<pen<<" IMPOSED";
                cout<<"\nKINDLY DEPOSIT THE AMOUNT ACCORDINGLY";
                cout<<"\n\nENTER THE AMOUNT YOU WANT TO DEPOSIT        :";
                cin>>deposit;
                float diff;
                diff=(minbal-balance)+pen;
                if(deposit<diff)
                {
                    cout<<"\nAMOUNT DEPOSITED NOT ENOUGH ";
                    diff=diff-deposit;
                    cout<<"\nAFTER IMPOSING PENALTY Rs. "<<diff<<" REMAINS TO BE PAID";
                    if(deposit>pen)
                        balance=balance+diff;
                    if(diff>0)
                    {
                        cout<<"\nSTILL Rs. "<<diff<<" UNDER LIMIT";
                        getch();
                    }
                }
                else
                {
                    diff=deposit-pen;
                    balance=balance+diff;
                }
            }
            else
            {
                cout<<"\n\nENTER THE AMOUNT YOU WANT TO DEPOSIT        :";
                cin>>deposit;
                balance=balance+deposit;
            }


            cout<<"\n\nTHE BALANCE AFTER MAKING DEPOSIT IS        :"<<balance;
            getch();
        }
        void cwithdraw()
        {
            int ch;
            while(1)
            {
                clrscr();
                cout<<"\nMONEY WITHDRAWAL SCREEN";
                cout<<"\n\nENTER THE WITHDRAWAL AMOUNT            :";
                cin>>withdraw;
                balance=balance-withdraw;
                if(balance<=0)
                {
                    cout<<"\n\nAFTER WITHDRAWAL BALANCE FALLING BELOW ZERO";
                    cout<<"\nCANNOT ALLOW TO WITHDRAW.........";
                    getch();
                    while(1)
                    {
                        cout<<"\n\nWOULD YOU LIKE WITHDRAW(1 FOR Y/2 FOR N) :";
                        cin>>ch;
                        if(ch==1)
                            break;
                        elseif(ch==2)
                            break;
                        else
                        {
                            cout<<"\nINVALID CHOICE";
                            continue;
                        }
                    }
                    if(ch==1)
                        continue;
                    elseif(ch==2)
                    {
                        cout<<"\n\nTHE BALANCE AFTER WITHDRAWAL IS    :"<<balance;
                        getch();
                        break;
                    }
                }
                elsebreak;
            }
        }
        void penalty()
        {
            clrscr();
            cout<<"\nPENALTY CALCULATION SCREEN";
            cout<<"\n\nPENALTY CALCULATED FOR BALANCE FALLING BELOW Rs. "<<minbal;
            if(balance<minbal)
            {
                    cout<<"\n\nPENALTY OF Rs. 300 IMPOSED AS BALANCE Rs. "<<balance;
                    getch();
             }
             else
             {
                    cout<<"\nNO PENALTY IMPOSED";
                    getch();
              }
        }
        void cdisplay()
        {
            cout<<"\n\nLATEST BALANCE IS        :"<<balance;
            getch();
        }

};




main()
{
    clrscr();
    int ans;
    while(1)
    {
        clrscr();
        char c;
        char acname[30];
        int acno;
        char atype;
        cout<<"\nACCOUNT OPENING SYSTEM ";
        cout<<"\n\nENTER THE CUSTOMER NAME              :";
        for(int i=0;(c=getche())!='\r';i++)
                 acname[i]=c;
        acname[i]='\0';
        cout<<"\nENTER THE ACCOUNT NUMBER             :";
        cin>>acno;
        int ch;
        while(1)
        {

            cout<<"\nENTER THE ACCOUNT TYPE(C FOR CURRENT/S FOR SAVINGS) :";
            cin>>atype;
            if(atype=='s')
            {
                save_acct s1;
                s1.getdata(acname,acno,atype);
                while(1)
                {
                    clrscr();
                    cout<<"\n\tSAVINGS ACCOUNT MENU";
                    cout<<"\n\n1. DEPOSIT";
                    cout<<"\n2. WITHDRAW";
                    cout<<"\n3. COMPUTE INTEREST";
                    cout<<"\n4. DISPLAY BALANCE";
                    cout<<"\n5. EXIT";
                    cout<<"\n\nENTER YOUR CHOICE :";
                    cin>>ch;
                    if(ch==1)
                        s1.sdeposit();
                    elseif(ch==2)
                        s1.swithdraw();
                    elseif(ch==3)
                        s1.interest();
                    elseif(ch==4)
                        s1.sdisplay();
                    elseif(ch==5)
                    {
                        s1.sdisplay();
                        break;
                    }
                    else
                    {
                        cout<<"\n\nINVALID CHOICE";
                        continue;
                    }

                }

            }
            elseif(atype=='c')
            {
                curr_acct c1;
                c1.getdata(acname,acno,atype);
                while(1)
                {
                    clrscr();
                    cout<<"\n\tCURRENT ACCOUNT MENU";
                    cout<<"\n\n1. DEPOSIT";
                    cout<<"\n2. WITHDRAW";
                    cout<<"\n3. PENALTY CHECK";
                    cout<<"\n4. DISPLAY BALANCE";
                    cout<<"\n5. EXIT";
                    cout<<"\n\nENTER YOUR CHOICE :";
                    cin>>ch;
                    if(ch==1)
                        c1.cdeposit();
                    elseif(ch==2)
                        c1.cwithdraw();
                    elseif(ch==3)
                        c1.penalty();
                    elseif(ch==4)
                        c1.cdisplay();
                    elseif(ch==5)
                    {
                        c1.cdisplay();
                        break;
                    }
                    else
                    {
                        cout<<"\n\nINVALID CHOICE";
                        continue;
                    }
                }
            }
            else
            {
                cout<<"\nINVALID CHOICE";
            }
            while(1)
            {

                cout<<"\n\nDO YOU WANT TO CONTINUE(1 FOR YES/2 FOR NO) :";
                cin>>ans;
                if(ans==1)
                    break;
                elseif(ans==2)
                    break;
                elsecontinue;
            }
            if(ans==1)
                break;
            elsebreak;
     }
    if(ans==1)
        continue;
    elseif(ans==2)
        break;
}
}
  
Share: 



Faith Hughes
Faith Hughes author of CREATING A CLASS ACCOUNTS FROM WHICH ARE DERIVED TWO CLASSES CURRENT AND SAVINGS AND THEN ASK THE USER FOR THE TYPE OF ACCOUNT HE WANTS TO CREATE is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!