Categories
Uncategorised

Inheritance – Account Managment

/* Copyright (C) 2007 Ankur Banerjee. This program is free software: you can redistribute it and / or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. For a copy of the GNU General Public License see http://www.gnu.org/licenses/gpl.html /

/ Inheritance – Account Management /

#include <iostream.h>
#include <conio.h>
#include <stdio.h>

class account
{
protected:
int num;
char name[30];
float bal;
public:
void getdata()
{
cout<<endl<<“Enter details for customer account”
<<endl<<“Enter account number : “;
cin>>num;
cout<<“Enter name : “;
gets(name);
cout<<“Enter account balance : “;
cin>>bal;
}
void showdata()
{
cout<<endl<<“Displaying details of customer”
<<endl<<“Account number : “<<num
<<endl<<“Customer name : “<<name
<<endl<<“Account balance : “<<bal;
}
};


class transaction : private account
{
char t;
float amt;
public:
char type;
float amount;
void trans()
{
cout<<endl<<“Enter type of transaction – ‘d’ for “
<<“deposit and ‘w’ for withdrawal : “;
cin>>t;
cout<<“Enter transaction amount : “;
cin>>amt;
update(t, amt);
}
void update(char type, float
amount)
{
if (type==’d’)
{
bal += amount;
cout<<endl<<“Transaction successful”;
showdata();
}
else if (type==’w’)
{
if (bal > amount)
{
bal -= amount;
cout<<endl<<“Transaction successful”;
showdata();
}
else
{
cout<<“Sorry! Not enough balance to carry out transaction”<<endl
<<“Do you want to enter
the withdrawal amount again (y / n)? : “;
char ch;
cin>>ch;
if (ch==’y’)
trans();
}
}
}
void get()
{
getdata();
}
void show()
{
showdata();
} < /span>
};

transaction t[3];

void main()
{
clrscr();
int i, c, n;
char ans;
cout<<“\n\nAccount Management Program”
<<endl<<“Enter initial account data”;
for (i = 0; i < 3; i++)
t[i].get();
do
{
cout<<endl<<“Program Menu”
<<endl<<“1. Display account details”
<<endl<<“2. Carry out transaction”
<<endl<<“Enter your choice : “;
cin>>c;
cout<<“Enter required account number : “;
cin>>n;
switch(c)
{
case 1 : t[n-1].show();
break;
case 2 : t[n-1].trans();
break;
default : cout<<endl<<“You entered a wrong choice!”;
}
cout<<endl<<“Do wish to continue (y / n)? : “;
cin>>ans;
}
while (ans==’y’ || ans==’Y’);

cout<<endl;
getch();
}

/ Output /

Account Management Program
Enter initial account data
Enter details for customer account

Enter account number : 1
Enter name : Ankur Banerjee
Enter account balance : 456

Enter details for customer account
Enter account number : 2
Enter name : Naman Bagga
Enter account balance : 741

Enter details for customer account
Enter account number : 3
Enter name : Rachit Agarwal
Enter account balance : 132

Program Menu
1. Display account details
2. Carry out transaction
Enter your choice : 1
Enter required account number : 2

Displaying details of customer
Account number : 2
Customer name : Naman Bagga
Account balance : 741

Program Menu
1. Display account details
2. Carry out transaction
Enter your choice : 2
Enter required account number : 1

Enter type of transaction – ‘d’
for deposit and ‘w’ for withdrawal : d
Enter transaction amount : 200

Transaction successful
Displaying details of customer
Account number : 1
Customer name : Ankur Banerjee
Account balance : 656

Program Menu
1. Display account details
2. Carry out transaction
Enter your choice : 2
Enter required account number : 3

Enter type of transaction – ‘d’
for deposit and ‘w’ for withdrawal : w
Enter transaction amount : 500
Sorry! Not enough balance to carry
out transaction
Do you want to enter the
withdrawal amount again (y / n)? : y

Enter type of transaction – ‘d’
for deposit
and ‘w’ for withdrawal : w

Enter transaction amount : 100

Transaction successful
Displaying details of customer
Account number : 3
Customer name : Rachit Agarwal
Account balance : 32

/ Program limitations: For the program to work, it is essential to enter sequential account numbers starting from one. Could have been accomplished by automatically assigning numbers too. */

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.