Chapter 6
Example 1 :Program to illustrates Mixed Inheritance Hierarchy with Abstract Classes
#include <iostream.h>
#include <string.h>
/*------Class Interfaces------*/
class Account // Abstract Base class
{
protected :
int number;
char name[10];
public :
Account(int, char*);
virtual void display() = 0;// pure virtual function
};
class SavingsAccount : public Account
{
int balance;
public:
SavingsAccount(int,char*,int);
void display();
};
class Deposit // Abstract Base class
{
protected :
int amount;
char maturity_date[9];
public:
Deposit(int, char*);
virtual void display() = 0;// pure virtual function
};
class DepositAccount : public Account, public Deposit
{
protected :
char opening_date[9];
public:
DepositAccount(int,char*,int,char*,char*);
virtual void display() = 0;// pure virtual function
};
class ShortTerm : public DepositAccount
{
int no_of_months;
public:
ShortTerm(int,char*,int,char*,char*,int);
void display();
};
class LongTerm : public DepositAccount
{
int no_of_years;
int loan_taken;
public:
LongTerm(int,char*,int,char*,char*,int,int);
void display();
};
/*------Class Implementations------*/
// member function definitions for 'Account'
void Account::Account(int a, char* b)
{
number = a;
strcpy(name, b);
}
// member function definitions for 'SavingsAccount'
void SavingsAccount::SavingsAccount(int a, char* b, int c) :
Account(a,b)
{
balance = c;
}
void SavingsAccount::display()
{
cout < "Savings Account Details --- \n";
cout < "Number : " < number < "\n";
cout < "Name : " < name < "\n";
cout < "Balance : " < balance < "\n";
}
// member function definitions for 'Deposit'
void Deposit::Deposit(int a, char* b)
{
amount = a;
strcpy(maturity_date, b);
}
// member function definitions for 'DepositAccount'
void DepositAccount::DepositAccount(int a, char* b, int c, char*
d, char* e)
: Account(a,b), Deposit(c,d)
{
strcpy(opening_date, e);
}
// member function definitions for 'ShortTerm'
void ShortTerm::ShortTerm(int a, char* b, int c, char* d, char*
e, int f)
: DepositAccount(a,b,c,d,e)
{
no_of_months = f;
}
void ShortTerm::display()
{
cout < "Short Term Deposit Account Details --- \n";
cout < "Number : " < number < "\n";
cout < "Name : " < name < "\n";
cout < "Amount : " < amount < "\n";
cout < "Maturity Date : " < maturity_date < "\n";
cout < "Date of Opening : " < opening_date < "\n";
cout < "Duration in Months : " < no_of_months < "\n";
}
// member function definitions for 'LongTerm'
void LongTerm::LongTerm(int a, char* b, int c, char* d, char* e,
int f, int g)
: DepositAccount(a,b,c,d,e)
{
no_of_years = f;
loan_taken = g;
}
void LongTerm::display()
{
cout < "Long Term Deposit Account Details --- \n";
cout < "Number : " < number < "\n";
cout < "Name : " < name < "\n";
cout < "Amount : " < amount < "\n";
cout < "Maturity Date : " < maturity_date < "\n";
cout < "Date of Opening : " < opening_date < "\n";
cout < "Duration in Years : " < no_of_years < "\n";
cout < "Loan Taken : " < loan_taken < "\n";
}
/*------Class definitions ends here------*/
void main(void)
{
Account *top1;// base class pointer
top1 = new SavingsAccount(1323, "Stavan", 10000);
top1->display();
delete top1;
cout < "\n";
DepositAccount *top2; // base class pointer
cout < "Deposit Display using pointer";
cout <" of type base class 'DepositAccount' - \n";
top2 = new ShortTerm(17099, "Kush", 25000, "12/05/02", "12/02/02", 3);
top2->display();
delete top2;
cout < "\n";
top2 = new LongTerm(17169, "Samarth", 30000, "15/03/04",
"15/03/02", 2, 1000);
top2->display();
delete top2;
cout < "\n";
}
Output :
Savings Account Details ---
Number : 1323
Name : Stavan
Balance : 10000
Deposit Display using pointer of type base class 'DepositAccount' -
Short Term Deposit Account Details ---
Number : 17099
Name : Kush
Amount : 25000
Maturity Date : 12/05/02
Date of Opening : 12/02/02
Duration in Months : 3
Long Term Deposit Account Details ---
Number : 17169
Name : Samarth
Amount : 30000
Maturity Date : 15/03/04
Date of Opening : 15/03/02
Duration in Years : 2
Loan Taken : 1000
Example 2 :Array of Pointers to objects
#include <iostream.h>
class A
{
int a1;// private data member
public :
int a2;// public data member
void set_a1(int);
void display_a1a2();
};
/*------Class Implementations------*/
// member function definitions for class A
void A::set_a1(int x)
{
a1 = x;
}
void A::display_a1a2()
{
cout < "a1 = " < a1 < "\n";
cout < "a2 = " < a2 < "\n";
}
void main(void)
{
A obj[5];// array of objects declaration
for (int i=0; i<5; i++)// array of objects initialisation
{
obj[i].set_a1(i+1);
obj[i].a2 = (i+1)*10;
}
A *p[5];// array of pointers to objects - declaration
for (i=0; i<5; i++) // array of pointers to objects - initialisation
p[i] = &obj[i];
for (i=0; i<5; i++) // usage of array of pointers to objects
{
cout < "Object - " < i+1 < ":\n";
p[i]->display_a1a2();
cout < "\n";
}
}
Output :
Object - 1:
a1 = 1
a2 = 10
Object - 2:
a1 = 2
a2 = 20
Object - 3:
a1 = 3
a2 = 30
Object - 4:
a1 = 4
a2 = 40
Object - 5:
a1 = 5
a2 = 50
Example 3 :Program : constructor, destructor in multiple inheritance
#include<iostream.h>
#include<conio.h>
class base1
{
public:
base1()
{
cout<"Inside base1 constructor"<endl;
}
~base1()
{
cout<"Inside base1 destructor"<endl;
}
};//end of base class
class base2
{
public:
base2()
{
cout<"Inside base2 constructor"<endl;
}
~base2()
{
cout<"Inside base2 destructor"<endl;
}
};//end of derived class
class derived : public base1,public base2
{
public:
derived()
{
cout<"Inside derived constructor"<endl;
}
~derived()
{
cout<"Inside derived destructor"<endl;
}
};//end of derived class
void main()
{
clrscr();
derived obj;
}
Output :
Inside base1 constructor
Inside base2 constructor
Inside derived constructor
Inside derived destructor
Inside base2 destructor
Inside base1 destructor
Example 4 :Program : constructor, destructor in multilevel inheritance
#include<iostream.h>
#include<conio.h>
class base
{
protected:
int a;
public:
base(int x)
{
a=x;
cout<"Inside base constructor"<endl;
}
~base()
{
cout<"Inside base destructor"<endl;
}
};//end of base class
class derived1 : public base
{
protected:
int b;
public:
derived1(int x,int y):base(x)
{
b=y;
cout<"Inside derived1 constructor"<endl;
}
~derived1()
{
cout<"Inside derived1 destructor"<endl;
}
};//end of derived class
class derived2 : public derived1
{
int c;
public:
derived2(int x,int y,int z):derived1(x,y)
{
c=z;
cout<"Inside derived2 constructor"<endl;
}
~derived2()
{
cout<"Inside derived2 destructor"<endl;
}
void show()
{
cout<"a : "<a<" "<"b : "<b<" "<"c : "<c<endl;
}
};//end of derived class
void main()
{
clrscr();
derived2 obj(3,4,5);
obj.show();
}
Output :
Inside base constructor
Inside derived1 constructor
Inside derived2 constructor
a : 3 b : 4 c : 5
Inside derived2 destructor
Inside derived1 destructor
Inside base destructor
Example 5 :Program : constructor, destructor in multilevel inheritance
#include<iostream.h>
#include<conio.h>
class base
{
public:
base()
{
cout<"Inside base constructor"<endl;
}
~base()
{
cout<"Inside base destructor"<endl;
}
};//end of base class
class derived1 : public base
{
public:
derived1()
{
cout<"Inside derived1 constructor"<endl;
}
~derived1()
{
cout<"Inside derived1 destructor"<endl;
}
};//end of derived class
class derived2 : public derived1
{
public:
derived2()
{
cout<"Inside derived2 constructor"<endl;
}
~derived2()
{
cout<"Inside derived2 destructor"<endl;
}
};//end of derived class
void main()
{
clrscr();
derived2 obj;
}
Example 6 :Program : constructor, destructor in multiple inheritance
#include<iostream.h>
#include<conio.h>
class base1
{
protected:
int a;
public:
base1(int x)
{
a=x;
cout<"Inside base1 constructor"<endl;
}
~base1()
{
cout<"Inside base1 destructor"<endl;
}
};//end of base class
class base2
{
protected:
int b;
public:
base2(int y)
{
b=y;
cout<"Inside base2 constructor"<endl;
}
~base2()
{
cout<"Inside base2 destructor"<endl;
}
};//end of derived class
class derived : public base1,public base2
{
int c;
public:
derived(int x,int y,int z):base1(y),base2(z)
{
c=x;
cout<"Inside derived constructor"<endl;
}
~derived()
{
cout<"Inside derived destructor"<endl;
}
void show()
{
cout<"a : "<a<" "<"b : "<b<" "<"c : "<c<endl;
}
};//end of derived class
void main()
{
clrscr();
derived obj(3,4,5);
obj.show();
}
Example 7 :Program : constructor, destructor in multiple inheritance
#include<iostream.h>
#include<conio.h>
class base1
{
protected:
int a;
public:
base1(int x)
{
a=x;
cout<"Inside base1 constructor"<endl;
}
~base1()
{
cout<"Inside base1 destructor"<endl;
}
};//end of base class
class base2
{
protected:
int b;
public:
base2(int y)
{
b=y;
cout<"Inside base2 constructor"<endl;
}
~base2()
{
cout<"Inside base2 destructor"<endl;
}
};//end of derived class
class derived : public base1,public base2
{
public:
derived(int x,int y):base1(x),base2(y)
{
cout<"Inside derived constructor"<endl;
}
~derived()
{
cout<"Inside derived destructor"<endl;
}
void show()
{
cout<"a : "<a<" "<"b : "<b<endl;
}
};//end of derived class
void main()
{
clrscr();
derived obj(3,4);
obj.show();
}
Example 8 :Program : constructor, destructor in single inheritance
#include<iostream.h>
class base
{
public:
base()
{
cout<"Inside base constructor"<endl;
}
~base()
{
cout<"Inside base destructor"<endl;
}
};//end of base class
class derived : public base
{
public:
derived()
{
cout<"Inside derived constructor"<endl;
}
~derived()
{
cout<"Inside derived destructor"<endl;
}
};//end of derived class
void main()
{
derived obj;
}
Example 9 :
#include<iostream.h>
#include<conio.h>
class person
{
public:
char name[20];
int code;
void get_name( )
{
cout<"\nEnter name : ";
cin>name;
}
void get_code( )
{
cout<"\nEnter code : ";
cin>code;
}
void put_namecode( )
{
cout<"\nName of person is:"<name;
cout<"\nCode is:"<code;
}
};
class account: virtual public person
{
protected :
int pay;
public:
void get_pay( )
{
cout<"\nEnter amount to be paid : ";
cin>pay;
}
void put_pay( )
{
cout<"\nAmount to be paid : ";
cout<pay;
}
};
class admin: virtual public person
{
protected :
int exp;
public:
void get_exp( )
{
cout<"\nEnter experience : ";
cin>exp;
}
void put_exp( )
{
cout<"\nExperience of person is : ";
cout<exp;
}
};
class master : public account, public admin
{
public:
void getdata( )
{
get_name();
get_code();
get_pay();
get_exp();
}
void showdata()
{
put_namecode( );
put_pay( );
put_exp( );
}
};
void main( )
{
master m[20];
int ch,i, code,n,ans=1;
do
{
clrscr();
cout<"\nMenu";
cout<"\n1.Create";
cout<"\n2.Display";
cout<"\n3.Update";
cin>ch;
switch(ch)
{
case 1:cout<"\nEnter no.of persons : ";
cin>n;
for(int i=0;i<n;i++)
{
m[i].getdata();
}
break;
case 2: cout<"\nDisplay all entries";
for(i=0;i<n;i++)
m[i].showdata();
break;
case 3: cout<"\nEnter employee code : ";
cin>code;
for(i=0;i<n;i++)
if(m[i].code==code)
{
m[i].get_name();
m[i].get_pay();
m[i].get_exp();
break;
}
if(i==n)
cout<"\nEmp code not found";
break;
}
cout<"\nDo u want to continue(1/0) ?";
cin>ans;
}
while(ans==1);
getch();
}
Example 10 :
#include<iostream.h>
#include<conio.h>
class student
{
protected:
int rno;
public:
void get_number()
{
cout<"\nEnter roll no : ";
cin>rno;
}
void put_number()
{
cout<"\nRoll no:"<rno;
}
};
class test:public student
{
protected :
int mk1,mk2;
public:
void get_marks()
{
cout<"\nEnter marks1,marks2 : ";
cin>mk1>mk2;
}
void put_marks()
{
cout<"\nMarks are:\n ";
cout<"Marks1 = "<mk1<"\t Marks2 = "<mk2;
}
};
class sports
{
protected:
int score;
public:
void get_score( )
{
cout<"\nEnter score:";
cin>score;
}
void put_score( )
{
cout<"\nScore of sports is:"<score;
}
};
class result:public test, public sports
{
private:
int total;
public:
void display( )
{
total =mk1+mk2+score;
put_number( );
put_marks( );
put_score( );
cout<"\nTotal is :"<total;
}
};
void main( )
{
result R;
R.get_number( );
R.get_marks( );
R.get_score( );
R.display( );
getch( );
}
Example 11 :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";
}
Example 12 :Program to illustrates Hybrid 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 Deposite
{
int amount;
char maturity_date[9];
public:
void set(int, char*);
void display();
};
class DepositeAccount : public Account, public Deposite
{
char opening_date[9];
public:
void set(int,char*,int,char*,char*);// Overriding functions
void display();
};
class ShortTerm : public DepositeAccount
{
int no_of_months;
public:
void set(int,char*,int,char*,char*,int);// Overriding functions
void display();
};
class LongTerm : public DepositeAccount
{
int no_of_years;
int loan_taken;
public:
void set(int,char*,int,char*,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 'Deposite'
void Deposite::set(int a, char* b)
{
amount = a;
strcpy(maturity_date, b);
}
void Deposite::display()
{
cout < "Amount : " < amount < "\n";
cout < "Maturity Date : " < maturity_date < "\n";
}
// member function definitions for 'DepositeAccount'
void DepositeAccount::set(int a, char* b, int c, char* d, char* e)
{
Account::set(a,b);
Deposite::set(c,d);
strcpy(opening_date, e);
}
void DepositeAccount::display()
{
Account::display();
Deposite::display();
cout < "Date of Opening : " < opening_date < "\n";
}
// member function definitions for 'ShortTerm'
void ShortTerm::set(int a, char* b, int c, char* d, char* e, int f)
{
DepositeAccount::set(a,b,c,d,e);
no_of_months = f;
}
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, char* e, int f, int g)
{
DepositeAccount::set(a,b,c,d,e);
no_of_years = f;
loan_taken = g;
}
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/05/02", "12/02/02", 3);
ST.display();
cout < "\n";
LongTerm LT;
LT.set(17169, "Vishwas", 30000, "15/03/04", "15/03/02", 2, 1000);
LT.display();
cout < "\n";
}
Example 13 :
#include<iostream.h>
#include<stdio.h>
class shape
{
protected:
double bs,ht;
public:
void getdata();
virtual void displayarea()
{
cout<"\nArea : ";
}
};
void shape::getdata()
{
cout<"\nEnter base : ";
cin>bs;
cout<"\nEnter height : ";
cin>ht;
}
class triangle:public shape
{
double area;
public:
void displayarea()
{
area=0.5*bs*ht;
cout<"\nArea of triangle is:"<area;
}
};
class rect:public shape
{
double area;
public:
void displayarea()
{
area=bs*ht;
cout<"\nArea of rect is:"<area;
}
};
void main()
{
shape *p,s;
triangle t;
rect r;
t.getdata();
p=&t;
p->displayarea();
r.getdata();
p=&r;
p->displayarea();
}
Example 14 :
#include<iostream.h>
#include<conio.h>
class staff
{
private:
int code;
char name[50];
char add[100];
public:
void getdata()
{
cout<"\nEnter code :";
cin>code;
cout<"\nEnter name : ";
cin>name;
cout<"\nEnter Address : ";
cin>add;
}
void showdata()
{
cout<"\nCode = "<code;
cout<"\nName = "<name;
cout<"\nAddress ="<add;
}
};
class teacher:public staff
{
private:
char sub[20];
char pub[20];
public:
void getdata()
{
staff::getdata();
cout<"\nEnter subject and publication:";
cin>sub>pub;
}
void showdata()
{
staff::showdata();
cout<"\nSubject is:"<sub;
cout<"\nPublication is:"<pub;
}
};
class officer:public staff
{
private:
char grade[5];
public:
void getdata()
{
staff::getdata();
cout<"\nEnter grade:";
cin>grade;
}
void showdata()
{
staff::showdata();
cout<"\nGrade is:"<grade;
}
};
class typist:public staff
{
private:
int speed;
public:
void getdata()
{
staff::getdata();
cout<"\nEnter speed : ";
cin>speed;
}
void showdata()
{
staff::showdata();
cout<"\nSpeed is : "<speed;
}
};
class casual:public typist
{
private :
int dailywages;
public:
void getdata()
{
typist::getdata();
cout<"\nEnter daily wages :";
cin>dailywages;
}
void showdata()
{
typist::showdata();
cout<"\nDailywages are :"<dailywages;
}
};
class regular:public typist
{
private:
int pay;
public:
regular() {}
void showdata()
{
typist::showdata();
cout<"\nMonthly pay is:"<pay;
}
};
void main()
{
casual c;
officer o;
teacher t;
regular r;
c.getdata();
o.getdata();
t.getdata();
r.getdata();
c.showdata();
o.showdata();
t.showdata();
r.showdata();
}
Example 15 :
# include <iostream.h>
# include <conio.h>
class B1
{
int x;
public :
B1(int i)
{
x = i;
cout<"\nB1 initialised";
}
~B1()
{
cout <"\nB1 destroyed";
}
};
class B2
{
float y;
public :
B2(float j)
{
y = j;
cout<"\nB2 initialized";
}
~B2()
{
cout<"\nB2 destroyed";
}
};
class D : public B1, public B2
{
int m, n;
public :
D(int a, float b, int c, int d) : B1(a), B2(b)
{
m=c;
n=d;
cout<"\nD is initialised";
}
void show_mn (void)
{
cout<"\nm="<m<"\n"
<"n="<n<"\n";
}
~D()
{
cout<"\nD is destroyed";
}
};
main( )
{
clrscr( );
{
D d(5, 10.75, 20, 30);
cout<"\n";
d.show_mn();
}
getch();
return 0;
}
Output :
B1 initialised
B2 initialized
D is initialised
m=20
n=30
D is destroyed
B2 destroyed
B1 destroyed
Example 16 :Program to illustrates Mixed Inheritance Hierarchy with Abstract Classes
#include <iostream.h>
#include <string.h>
/*------Class Interfaces------*/
class Account // Abstract Base class
{
protected :
int number;
char name[10];
public :
Account(int, char*);
virtual void display() = 0; // pure virtual function
};
class SavingsAccount : public Account
{
int balance;
public:
SavingsAccount(int,char*,int);
void display();
};
class Deposit // Abstract Base class
{
protected :
int amount;
char maturity_date[9];
public:
Deposit(int, char*);
virtual void display() = 0; // pure virtual function
};
class DepositAccount : public Account, public Deposit
{ // Abstract Base class
protected :
char opening_date[9];
public:
DepositAccount(int,char*,int,char*,char*);
virtual void display() = 0; // pure virtual function
};
class ShortTerm : public DepositAccount
{
int no_of_months;
public:
ShortTerm(int,char*,int,char*,char*,int);
void display();
};
class LongTerm : public DepositAccount
{
int no_of_years;
int loan_taken;
public:
LongTerm(int,char*,int,char*,char*,int,int);
void display();
};
/*------Class Implementations------*/
// member function definitions for 'Account'
void Account::Account(int a, char* b)
{
number = a;
strcpy(name, b);
}
// member function definitions for 'SavingsAccount'
void SavingsAccount::SavingsAccount(int a, char* b, int c) :
Account(a,b)
{
balance = c;
}
void SavingsAccount::display()
{
cout < "Savings Account Details --- \n";
cout < "Number : " < number < "\n";
cout < "Name : " < name < "\n";
cout < "Balance : " < balance < "\n";
}
// member function definitions for 'Deposit'
void Deposit::Deposit(int a, char* b)
{
amount = a;
strcpy(maturity_date, b);
}
// member function definitions for 'DepositAccount'
void DepositAccount::DepositAccount(int a, char* b, int c, char* d, char* e)
: Account(a,b), Deposit(c,d)
{
strcpy(opening_date, e);
}
// member function definitions for 'ShortTerm'
void ShortTerm::ShortTerm(int a, char* b, int c, char* d, char*
e, int f)
: DepositAccount(a,b,c,d,e)
{
no_of_months = f;
}
void ShortTerm::display()
{
cout < "Short Term Deposit Account Details --- \n";
cout < "Number : " < number < "\n";
cout < "Name : " < name < "\n";
cout < "Amount : " < amount < "\n";
cout < "Maturity Date : " < maturity_date < "\n";
cout < "Date of Opening : " < opening_date < "\n";
cout < "Duration in Months : " < no_of_months < "\n";
}