Computer Science Project-1
Computer Science Project-1
PROJECT FILE
17/FCA/BCA/032
BCA-3(A)
1|Page
Ind
1. ex Introduction
2. Source Code
3. Output
4. Bibliography
2|Page
Introduc
tion
The functioning of
the program is so designed that it is
very easy to understand and
operate.
3|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
4|Page
type = toupper(type);
cout<<"\nEnter the initial amount(>=500 for saving and >=1000 for current) :: ";
cin>>deposit;
cout<<"\n\n\nAccount Created...";
}
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;
}
5|Page
int account :: rettype()
{
return type;
}
//*************************************************
// 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;
6|Page
deposit_withdraw(num,1);
break;
case '3': cout<<"\n\n\tEnter Account No. :: ";
cin>>num;
deposit_withdraw(num,2);
break;
case '4': cout<<"\n\n\tEnter Account No. :: ";
cin>>num;
display_sp(num);
break;
case '5': display_all();
break;
case '6': cout<<"\n\n\tEnter Account No. :: ";
cin>>num;
delete_account(num);
break;
case '7': cout<<"\n\n\tEnter Account No. :: ";
cin>>num;
modify_account(num);
break;
case '8': cout<<"\n\n\tThanks for using bank management system";
break;
default : cout<<"\a";
}
getch();
}while(ch!='8');
return 0;
}
//*************************************************
// 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();
}
//*************************************************
// Funtion to read specific record from file
//*************************************************
void display_sp(int n)
{
account ac;
7|Page
int flag=0;
ifstream infile;
infile.open("account.dat",ios::binary);
if(!infile)
{
//*************************************************
// 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);
8|Page
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);
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);
9|Page
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);
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;
10 | P a g e
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";
}
//*************************************************
// 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 :Gundeep Singh";
cout<<"\n\nCOLLEGE : MRIIRS";
getch();
}
//*************************************************
// End of Coding
//*************************************************
11 | P a g e
Output
s
12 | P a g e
13 | P a g e
14 | P a g e
15 | P a g e
16 | P a g e
17 | P a g e
Bibliogr
aphy
Book Sie
cppforschool.
Sumita Arora
com
18 | P a g e