Google PlusFacebookTwitter

Classes – Accounts

By on Apr 11, 2007 in On A Whim | 0 comments

Share On GoogleShare On FacebookShare On Twitter

/* Copyright © 2007 Ankur Banerjee. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library 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 Lesser General Public License for more details. http://www.fsf.org/licensing/licenses/lgpl.html */

/* Classes – Program to manage accounts */

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

int i, n, amt;
char tran;

class account
{
int num;
char name[50];
float bal;
static float tot, totd, totw;
public:
void accept()
{
cout<<endl<<“Enter data for account “<<i + 1<<endl
<<“Enter account number : “;
cin>>num;
cout<<“Enter account name : “;
gets(name);
cout<<“Enter balance amount : “;
cin>>bal;
}
void disp(int no)
{
if (no == num)
{
cout<<endl<<“Displaying data for requested “<<“account”
<<endl<<“Accountnumber : “<<num<<endl
<<“Account name : “<<name<<endl
<<“Account balance : “<<bal;
}
}
void trans(int no, char t, float a)
{
if (no == num)
{
if (t == ‘d’)
{
bal += a;
totd += a;
}
else if (t == ‘w’)
{
bal -= a;
totw += a;
}
}
tot = totd – totw;
}
static void total()
{
cout<<endl<<“Total deposits by all account holders : “<<totd<<endl
<<“Total withdrawals made by all account holders : “<<totw<<endl
<<“Total of all transactions done by all account holders : “<<tot;
}
} acc[5];

float account::tot = 0.0;
float account::totd = 0.0;
float account::totw = 0.0;

void main()
{clrscr();
int ch;
char choice;
cout<<endl<<“Account Management Program\n \n”
<<“Enter initial details for all accounts”<<endl;
for (i = 0; i < 5; i++)
acc[i].accept();
do
{
cout<<endl<<“Program Menu”<<endl
<<“1. Display data for particular account”<<endl
<<“2. Carry out transaction”<<endl
<<“3. Display total withdrawal and total deposits”<<endl
<<“Enter your choice : “;
cin>>ch;
if
(ch == 1)
{
cout<<endl<<“Enter account number for required account : “;
cin>>n;
for (int i = 0; i < 10; i++)
acc[i].disp(n);
}
else if (ch == 2)
{
cout<<endl<<“Enter account number associated with transaction : “;
cin>>n;
cout<<“Enter type of transaction – d for deposit and w for withdrawal : “;
cin>>tran;
cout<<“Enter transaction amount : “;
cin>>amt;
for (i = 0; i < 5; i++)
acc[i].trans(n, tran, amt);
cout<<“Account balance for account number “<<n
<<” has been updated”;
}
else if (ch == 3)
{
acc[0].total();
}

else cout<<endl<<“You entered an incorrect choice”;
cout<<“\n \nDo you wish to continue – y / n : “;
cin>>choice;
} while (choice == ‘y’ || choice == ‘Y’);
cout<<endl;
getch();
}

/* Output */

Account Management Program

Enter initial details for all accounts

Enter data for account 1
Enter account number : 42
Enter account name : Ankur Banerjee
Enter balance amount : 875

Program Menu
1. Display data for particular account
2. Carry out transaction
3. Display total withdrawal and total deposits
Enter your choice : 1

Enter account number for required account : 42

Displaying data for requested account
Account number : 42
Account name : Ankur Banerjee
Account balance : 875

Program Menu
1. Display data for particular account
2. Carry out transaction
3. Display total withdrawal and total deposits
Enter your choice : 2

Enter account number associated with transaction : 42
Enter type of transaction – d for deposit and w for withdrawal : d
Enter transaction amount : 420

Account balance for account number 42 has been updated

Program Menu
1. Display data for particular account
2. Carry out transaction
3. Display total withdrawal and total deposits
Enter your choice : 3

Total deposits by all account holders : 420
Total withdrawals made by all account holders : 0
Total of all transactions done by account holders : 420



Submit a Comment

Your email address will not be published. Required fields are marked *