Read in your tongue here..

Saturday, December 7, 2013

Function Overriding

#include<stdlib.h>
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class account{
    protected:
        char name[45],add[100],city[45],state[45],phone[11];
    public:
        account(char n[], char a[], char c[], char s[], char p[])
        {
            strcpy(name,n);
            strcpy(add,a);
            strcpy(city,c);
            strcpy(state,s);
            strcpy(phone,p);
        }
        void display(void)
        {
            cout<<"\n\tCustomer Details:\n";
            cout<<"\nName: "<<name<<"\nAddress: "<<add;
            cout<<"\nCity: "<<city<<"\nState: "<<state<<"\nContact Number: "<<phone<<endl;
        }
};
class current:public account
{
    protected:
        float crlim;
        char acno_c[11];
    public:
        current(char n[], char a[], char c[], char s[], char p[], float crl, char acnc[]):account(n,a,c,s,p)
        {
            crlim=crl;
            strcpy(acno_c,acnc);
        }
        void display(void)
        {
            cout<<"\n\n\tCurrent Account Details:";
            cout<<"\n\nAccount Number: "<<acno_c;
            cout<<"\nCredit Limit= "<<crlim<<endl;
        }
};
class savings:public current{
    protected:
        float bal;
        char acno_s[11];
    public:
        savings(char n[], char a[], char c[], char s[], char p[], float crl, char acnc[], float b, char acns[]):current(n,a,c,s,p,crl,acnc)
        {
            bal=b;
            strcpy(acno_s,acns);
        }
    void display(void)
    {
        cout<<"\n\n\tSavings Account details:";
        cout<<"\n\nAccount Number: "<<acno_s<<"\nBalance= "<<bal<<endl;
    }
};
class credit:public savings{
    protected:
        float amtcr;
    public:
        char cho;
        credit(char n[], char a[], char c[], char s[], char p[], float crl, char acnc[], float b, char acns[], float cr):savings(n,a,c,s,p,crl,acnc,b,acns)
        {
            if(cr==0);
            else
            {
                amtcr=cr;
                cout<<"\nEnter C for Current account or S for Savings account:";
                cho=getche();
                if(cho=='C'||cho=='c')
                {
                    if(crlim<amtcr)
                        cout<<"\nInsufficient Balance!!!\n";
                    else
                    {
                        cout<<"\nPrevious Limit=Rs."<<crlim;
                        crlim-=amtcr;
                        cout<<"\nAmount Credited=Rs."<<amtcr;
                        cout<<"\nNet Credit Limit=Rs."<<crlim<<endl;
                    }
                }
                else if(cho=='S'||cho=='s')
                {
                    if(bal<amtcr)
                        cout<<"\nInsufficient Balance!!!"<<endl;
                    else
                    {
                        cout<<"\nPrevious Balance=Rs."<<bal;
                        bal-=amtcr;
                        cout<<"\nAmount Credited=Rs."<<amtcr;
                        cout<<"\nNet Balance=Rs."<<bal<<endl;
                    }
                }
                else
                    cout<<"\nWrong Input!!!\n";
            }
        }
};
class debit:public credit{
    protected:
        float amtdr;
    public:
        char cho;
        debit(char n[], char a[], char c[], char s[], char p[], float crl, char acnc[], float b, char acns[], float cr, float dr):credit(n,a,c,s,p,crl,acnc,b,acns,cr)
        {
            amtdr=dr;
            cout<<"\nEnter C for Current account or S for Savings account:";
            cho=getche();
            if(cho=='C'||cho=='c')
            {
                cout<<"\nPrevious Limit=Rs."<<crlim;
                crlim+=amtdr;
                cout<<"\nAmount Debited=Rs."<<amtdr;
                cout<<"\nNet Credit Limti=Rs."<<crlim<<endl;
            }
            else if(cho=='S'||cho=='s')
            {
                cout<<"\nPrevious Balance=Rs."<<bal;
                bal+=amtdr;
                cout<<"\nAmount Debited=Rs."<<amtdr;
                cout<<"\nNet Balance=Rs."<<bal<<endl;
            }
            else
                cout<<"\nWrong Input!!!\n";
        }
};
void main()
{
    char n[45],a[45],c[45],s[45],p[45],acnc[11],acns[11];
    float crl,b,cr,dr;
    int cho;
    cout<<"\nEnter customer's details:\nName:";
    gets(n);
    cout<<"Address:";
    gets(a);
    cout<<"City:";
    gets(c);
    cout<<"State:";
    gets(s);
    cout<<"Contact Number:";
    gets(p);
    cout<<"Enter Current Account Details:\nCredit Limit:";
    cin>>crl;
    cout<<"Account Number:";
    gets(acnc);
    cout<<"Enter Savings Account Details:\nBalance:";
    cin>>b;
    cout<<"Account Number:";
    cin>>acns;
    while(1)
    {
        cout<<"\n1.Display Customer's Details\n2.Display Current Account Details\n3.Display Savings Account Details\n4.Credit\n5.Debit\n6.Exit\nEnter Choice:";
        cin>>cho;
        if(cho==1)
        {
            account cust(n,a,c,s,p);
            cust.display();
        }
        else if(cho==2)
        {
            current cust(n,a,c,s,p,crl,acnc);
            cust.display();
        }
        else if(cho==3)
        {
            savings cust(n,a,c,s,p,crl,acnc,b,acns);
            cust.display();
        }
        else if(cho==4)
        {
            cout<<"Enter amount to be credited:";
            cin>>cr;
            credit cust(n,a,c,s,p,crl,acnc,b,acns,cr);
        }
        else if(cho==5)
        {
            cout<<"Enter amount to be debited:";
            cin>>dr;
            debit cust(n,a,c,s,p,crl,acnc,b,acns,0,dr);
        }
        else if(cho==6)
        {
            clrscr();
            exit(0);
        }
        else
            cout<<"\nWrong Input!!!\n";
    }
}

No comments:

Post a Comment