#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";
}
// 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, "Vikram", 10000);
top1->display();
delete top1;
cout << "\n";
cout << "Deposit Display using pointer";
cout << " of type base class 'Account' - \n";
top1 = new ShortTerm(17099, "Vilas", 25000, "12/05/02", "12/02/02", 3);
top1->display();
delete top1;
cout << "\n";
top1 = new LongTerm(17169, "Vishwas", 30000, "15/03/04",
"15/03/02", 2, 1000);
top1->display();
delete top1;
cout << "\n";
Deposit *top2; // base class pointer
cout << "Deposit Display using pointer";
cout << " of type second base class 'Deposit' - \n";
top2 = new ShortTerm(17099, "Vilas", 25000, "12/05/02", "12/02/02", 3);
top2->display();
delete top2;
cout << "\n";
top2 = new LongTerm(17169, "Vishwas", 30000, "15/03/04",
"15/03/02", 2, 1000);
top2->display();
delete top2;
cout << "\n";
}
0 comments:
Post a Comment