Program to illustrates Hierarchical Inheritance


#include <iostream.h>
#include <string.h>
/*----------------------Class Interfaces-------------------------*/
class Account
{
        int number;
        char name[10];
    public :
        void set(int, char*);
        void display();
};
class SavingsAccount : public Account
{
        int balance;
    public:
        void set(int,char*,int);// Overriding functions
        void display();
};
class DepositeAccount : public Account
{
        int amount;
        char opening_date[9];
    public:
        void set(int,char*,int,char*);// Overriding functions
        void display();
};
class ShortTerm : public DepositeAccount
{
        int no_of_months;
    public:
        void set(int,char*,int,char*,int);// Overriding functions
        void display();
};
class LongTerm : public DepositeAccount
{
        int no_of_years;
        int loan_taken;
    public:
        void set(int,char*,int,char*,int,int);// Overriding functions
        void display();
};

/*----------------------Class Implementations---------------------*/

// member function definitions for 'Account'
void Account::set(int a, char* b)
{
    number = a;
    strcpy(name, b);
}
void Account::display()
{
    cout << "Number : " << number << "\n";
    cout << "Name   : " << name << "\n";
}

// member function definitions for 'SavingsAccount'
void SavingsAccount::set(int a, char* b, int c)
{
    Account::set(a,b);
    balance = c;
}
void SavingsAccount::display()
{
    cout << "Savings Account Details --- \n";
    Account::display();
    cout << "Balance : " << balance << "\n";
}
// member function definitions for 'DepositeAccount'
void DepositeAccount::set(int a, char* b, int c, char* d)
{
    Account::set(a,b);
    amount = c;
    strcpy(opening_date, d);
}
void DepositeAccount::display()
{
    Account::display();
    cout << "Amount          : " << amount << "\n";
    cout << "Date of Opening : " << opening_date << "\n";
}

// member function definitions for 'ShortTerm'
void ShortTerm::set(int a, char* b, int c, char* d, int e)
{
    DepositeAccount::set(a,b,c,d);
    no_of_months = e;
}
void ShortTerm::display()
{
    cout << "Short Term Deposite Account Details --- \n";
    DepositeAccount::display();
    cout << "Duration in Months : " << no_of_months << "\n";
}
// member function definitions for 'LongTerm'
void LongTerm::set(int a, char* b, int c, char* d, int e, int f)
{
    DepositeAccount::set(a,b,c,d);
    no_of_years = e;
    loan_taken = f;
}
void LongTerm::display()
{
    cout << "Long Term Deposite Account Details --- \n";
    DepositeAccount::display();
    cout << "Duration in Years : " << no_of_years << "\n";
    cout << "Loan Taken        : " << loan_taken << "\n";
}
/*----------------------Class definitions ends here---------------*/
void main(void)
{
    SavingsAccount S;
    S.set(1323, "Stavan", 10000);
    S.display();
    cout << "\n";

    ShortTerm ST;
    ST.set(17099, "Kush", 25000, "12/02/07", 3);
    ST.display();
    cout << "\n";

    LongTerm LT;
    LT.set(17169, "Saachi", 30000, "15/03/07", 2, 1000);
    LT.display();
    cout << "\n";
}

1 comments:

Anonymous said...

WOW just what I was looking for. Came here by searching
for aydame

My web page - cellulite treatment

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|