Computer Science Project
Computer Science Project
Name:
Signature:
---------------------------
--------------------------
1|Page
Signature
Signature
(Subject Teacher)
(Examiner)
2|Page
1. Introduction
2. System Requirements
3. Scope of Project
4. Source Code
5. Output
6. Bibliography
3|Page
4|Page
5|Page
//*************************************************
// Header file used in Project
//*************************************************
#include<fstream.h>
#include<ctype.h>
#include<iomanip.h>
#include<conio.h>
#include<stdio.h>
//*************************************************
// Class used in Project
//*************************************************
class account
{
int acno;
char name[20];
int deposit;
char type;
public:
void create_account();
//function to get data from user
void show_account(); //function to show data on screen
void modify();
//function to get new data from user
void dep (int);
//function to accept amount and add to balance amount
void draw(int);
//function to accept amount and subtract to balance amount
void report();
//function to show data in tabular format
int retacno();
//function to return account number
int retdeposit();
//function to return account number
int rettype();
//function to return type of account
}; //class ends here
void account :: create_account()
{
cout<<"\nEnter The Account No. :: ";
cin>>acno;
cout<<"\n\nEnter The Name of account Holder :: ";
gets(name);
cout<<"Enter Type of the Account (C/S) :: ";
cin>>type;
type = toupper(type);
cout<<"\nEnter the initial amount(>=500 for saving and >=1000 for current) :: ";
cin>>deposit;
cout<<"\n\n\nAccount Created...";
6|Page
}
void account :: show_account()
{
cout<<"\nAccount No. :: "<<acno;
cout<<"\nAccount Holder Name :: "<<name;
cout<<"\nType of Account :: "<<type;
cout<<"\nBalance Amount :: "<<deposit;
}
void account :: modify()
{
cout<<"\nThe acciunt No.:: "<<acno;
cout<<"\n\nEnter The Name of account Holder :: ";
gets(name);
cout<<"Enter Type of the Account (C/S) :: ";
cin>>type;
type = toupper(type);
cout<<"\nEnter the initial amount(>=500 for saving and >=1000 for current) :: ";
cin>>deposit;
}
void account :: dep(int x)
{
deposit+=x;
}
void account :: draw(int x)
{
deposit-=x;
}
//*************************************************
// Function declaration
//*************************************************
void write_account();
//function to write record in binary file
void display_sp(int);
//function to display account details given by user
void modify_account(int);//function to modify record of file
void delete_account(int); //function to delete record of file
void display_all();
//function to display all account details
void deposit_withdraw(int,int);
//function to deposit/withdraw amount for
given account
void intro();
//introduction screen function
//*************************************************
// The main function of program
//*************************************************
int main()
{
char ch;
int num;
clrscr();
intro();
do
{
clrscr();
cout<<"\n\n\n\tMain Menu";
cout<<"\n\n\t01. New Account";
cout<<"\n\n\t02. Deposit Amount";
cout<<"\n\n\t03. Withdraw Amount";
cout<<"\n\n\t04. Balance Enquiry";
cout<<"\n\n\t05. All Account Holder List";
cout<<"\n\n\t06. Close An Account";
cout<<"\n\n\t07. Modify An Account";
cout<<"\n\n\t08. Exit";
cout<<"\n\n\tSelect Your Option(1-8) :: ";
cin>>ch;
clrscr();
switch(ch)
{
case '1' :
write_account();
break;
case '2' : cout<<"\n\n\tEnter Account No. :: ";
cin>>num;
deposit_withdraw(num,1);
break;
case '3' : cout<<"\n\n\tEnter Account No. :: ";
cin>>num;
deposit_withdraw(num,2);
8|Page
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
default :
}
getch();
}while(ch!='8');
return 0;
break;
cout<<"\n\n\tEnter Account No. :: ";
cin>>num;
display_sp(num);
break;
display_all();
break;
cout<<"\n\n\tEnter Account No. :: ";
cin>>num;
delete_account(num);
break;
cout<<"\n\n\tEnter Account No. :: ";
cin>>num;
modify_account(num);
break;
cout<<"\n\n\tThanks for using bank management system";
break;
cout<<"\a";
}
//*************************************************
// Funtion to write in file
//*************************************************
void write_account()
{
account ac;
ofstream outfile;
outfile.open("account.dat",ios::binary|ios::app);
ac.create_account();
outfile.write((char*)&ac,sizeof(account));
outfile.close();
}
9|Page
//*************************************************
// Funtion to read specific record from file
//*************************************************
void display_sp(int n)
{
account ac;
int flag=0;
ifstream infile;
infile.open("account.dat",ios::binary);
if(!infile)
{
cout<<"File could not be open !! \nPress any Key...";
return;
}
cout<<"\nBalance Details\n";
while(infile.read((char*)&ac,sizeof(account)))
{
if(ac.retacno()==n)
{
ac.show_account();
flag=1;
}
}
infile.close();
if(flag==0)
cout<<"\n\nAccount Number Does Not Exist";
}
10 | P a g e
//*************************************************
// Funtion to modify record of file
//*************************************************
void modify_account(int n)
{
int found=0;
account ac;
fstream file;
file.open("account.dat",ios::binary|ios::in|ios::out);
if(!file)
{
cout<<"File could not be open !! \nPress any Key...";
return;
}
while(file.read((char*)&ac,sizeof(account))&&found == 0)
{
if(ac.retacno()==n)
{
ac.show_account();
cout<<"\n\nEnter The New Details of Account "<<endl;
ac.modify();
int pos = (-1)*sizeof(account);
file.seekp(pos,ios::cur);
file.write((char*)&ac,sizeof(account));
cout<<"\n\n\tRecord Updated...";
found = 1;
}
}
file.close();
if(found==0)
cout<<"\n\nRecord Not Found";
}
//*************************************************
// Funtion to delete record of file
//*************************************************
void delete_account(int n)
{
account ac;
ifstream infile;
ofstream outfile;
infile.open("account.dat",ios::binary);
if(!infile)
{
cout<<"File could not be open !! \nPress any Key...";
return;
}
outfile.open("Temp.dat",ios::binary);
11 | P a g e
infile.seekg(0,ios::beg);
while(infile.read((char*)&ac,sizeof(account)))
{
if(ac.retacno()!=n)
{
outfile.write((char*)&ac,sizeof(account));
}
}
infile.close();
outfile.close();
remove("account.dat");
rename("Temp.dat","account.dat");
cout<<"\n\n\tRecord Deleted...";
}
//*************************************************
// Funtion to display all account deposit list
//*************************************************
void display_all()
{
account ac;
ifstream infile;
infile.open("account.dat",ios::binary);
if(!infile)
{
cout<<"File could not be open !! \nPress any Key...";
return;
}
cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n";
cout<<"=====================================================\n";
cout<<"A/c no.
NAME
Type Balance\n";
cout<<"=====================================================\n";
while(infile.read((char*)&ac,sizeof(account)))
{
ac.report();
}
infile.close();
}
//*************************************************
// Funtion to deposit and withdraw amounts
//*************************************************
void deposit_withdraw(int n,int option)
{
int amt;
int found=0;
account ac;
fstream file;
file.open("account.dat",ios::binary|ios::in|ios::out);
12 | P a g e
if(!file)
{
cout<<"File could not be open !! \nPress any Key...";
return;
}
while(file.read((char*)&ac,sizeof(account))&&found == 0)
{
if(ac.retacno()==n)
{
ac.show_account();
if(option==1)
{
cout<<"\n\n\tTO DEPOSIT AMOUNT";
cout<<"\n\nEnter the amount to be deposit";
cin>>amt;
ac.dep(amt);
}
if(option==2)
{
cout<<"\n\n\tTO WITHDRAW AMOUNT";
cout<<"\n\nEnter the amount to be withdraw";
cin>>amt;
int bal=ac.retdeposit()-amt;
if((bal<500&&ac.rettype()=='S')||(bal<1000&&ac.rettype()=='c'))
cout<<"Insufficient Balance";
else
ac.draw(amt);
}
int pos=(-1)*sizeof(ac);
file.seekp(pos,ios::cur);
file.write((char*)&ac,sizeof(account));
cout<<"\n\n\tRecord Updated...";
found = 1;
}
}
file.close();
if(found==0)
cout<<"\n\nRecord Not Found";
}
13 | P a g e
//*************************************************
// Introduction Funtion
//*************************************************
void intro()
{
cout<<"\n\n\n\t BANK";
cout<<"\n\n\tMANAGEMENT";
cout<<"\n\n\t SYSTEM";
cout<<"\n\n\n\nMADE BY : Amit Sawai";
cout<<"\n\nSCHOOL : Kendriya Vidyalaya Andrews Ganj";
getch();
}
//*************************************************
// End of Coding
//*************************************************
14 | P a g e
15 | P a g e
16 | P a g e
17 | P a g e
18 | P a g e
19 | P a g e
20 | P a g e