You are on page 1of 8

//***************************************************************

// HEADER FILE USED IN PROJECT
//****************************************************************

#include<fstream>
#include <sstream>
#include<ctype.h>
#include<iomanip>
#include<conio.h>
#include<stdio.h>
#include <iostream>
#include <string>
#include <windows.h>
#include <mysql.h>
using namespace std;

void clrscr() {
system("cls");
}

//***************************************************************
// CLASS USED IN PROJECT
//****************************************************************

class account
{
//char name[50];

string name;
unsigned int balance;
int deposit,acno;
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 from balance
amount
void report(); //function to show data in tabular format
int retacno(); //function to return account number
int retdeposit(); //function to return balance amount
char rettype(); //function to return type of account
}; //class ends here

void account::create_account()
{
MYSQL* conn;
MYSQL_ROW row;
MYSQL_RES *res;
int qstate;
conn = mysql_init(0);
if(conn)
cout<<"connection object ok"<<endl;
else
cout<<"conn object problem: "<<mysql_error(conn);

q).type. query << "INSERT INTO userac(name. //cin.. cout<<name. qstate = mysql_query(conn. " << balance << ")"."banking". : "<<acno. } void account::modify() { cout<<"\nThe account No."root". cin>>type. cout<<"\nAccount Holder Name : ".getline(name. cout<<"\nBalance amount : "<<deposit. while(row=mysql_fetch_row(res)) { cout<<"id: "<<row[0]<< " " <<"name: "<<row[1]<< " " <<"type: "<<row[2]<< " " <<"balance: "<<row[3]<< " "<<endl. } void account::show_account() { cout<<"\nAccount No.0. else cout<<"query problem: "<<mysql_error(conn)<<endl. cout<<"\nEnter Type of The account (C/S) : "."".ignore(). } } else { cout<<"query error: "<<mysql_error(conn)<<endl. '" << type << "'.. . if(!qstate) { res = mysql_store_result(conn). stringstream query.NULL.0). cout<<"\nEnter The Initial amount(>=500 for Saving and >=1000 for current ) : ".". //type=toupper(type)."localhost". } cout<<"\n\n\nAccount Created.c_str()..balance)" " VALUES ('" << name << "'. if(!qstate) cout<<"record inserted successfully."<<endl. conn = mysql_real_connect(conn. qstate = mysql_query(conn. //cin. cin>>balance. cout<<"\nType of Account : "<<type.50). cout<<"query is: "<<q<<endl.str(). const char* q = query."<<acno. cin>>name."select * from userac"). cout<<"\n\nEnter The Name of The account Holder : ".

} void account::draw(int x) { deposit-=x. //gets(name). //function to display all account details void deposit_withdraw(int. //function to display account details given by user void modify_account(int). } int account::retdeposit() { return deposit. type=toupper(type). cin>>type. } char account::rettype() { return type. cout<<"\n\nEnter The Name of The account Holder : ". cin>>name. cout<<"\nEnter Type of The account (C/S) : ". //function to write record in binary file void display_sp(int). cin>>deposit. } void account::report() { cout<<acno<<setw(10)<<" "<<name<<setw(10)<<" "<<type<<setw(6)<<deposit<<endl. //function to delete record of file void display_all(). } //*************************************************************** // function declaration //**************************************************************** void connection(). } void account::dep(int x) { deposit+=x. //introductory screen function //*************************************************************** // THE MAIN FUNCTION OF PROGRAM //**************************************************************** . void write_account(). int). cout<<"\nEnter The amount : ". //function to modify record of file void delete_account(int). } int account::retacno() { return acno. // function to desposit/withdraw amount for given account void intro().

break. cout<<"\n\n\t04. : ". int num. cout<<"\n\n\t07. delete_account(num). default :cout<<"\a". deposit_withdraw(num. case '5': display_all(). break. break. cout<<"\n\n\t05.int main() { account a. cout<<"\n\n\t03. cout<<"\n\n\n\tMAIN MENU". clrscr(). cin>>num. EXIT". MODIFY AN ACCOUNT". cin>>num. cin>>ch. cout<<"\n\n\tSelect Your Option (1-8) ". case '7': cout<<"\n\n\tEnter The account No. deposit_withdraw(num. CLOSE AN ACCOUNT". cin>>num. switch(ch) { case '1': a. cin>>num. case '3': cout<<"\n\n\tEnter The account No. cout<<"\n\n\t08. intro(). cout<<"\n\n\t02. : ". } getch(). break. case '4': cout<<"\n\n\tEnter The account No. break. display_sp(num). return 0. cin>>num. cout<<"\n\n\t01. case '2': cout<<"\n\n\tEnter The account No. break. WITHDRAW AMOUNT". case '6': cout<<"\n\n\tEnter The account No. : ". : ". }while(ch!='8'). 2). clrscr(). 1). . ALL ACCOUNT HOLDER LIST". DEPOSIT AMOUNT". break. cout<<"\n\n\t06.create_account(). break. do { clrscr(). modify_account(num). char ch. : ". NEW ACCOUNT". case '8': cout<<"\n\n\tThanks for using bank managemnt system". BALANCE ENQUIRY".

".. while(inFile. int flag=0.open("account. ac.dat".close().close(). return. fstream File.} //*************************************************************** // function to write in file //**************************************************************** void write_account() { /*account ac. */ } //*************************************************************** // function to read specific record from file //**************************************************************** void display_sp(int n) { account ac..dat". inFile. outFile. ofstream outFile. } } inFile. if(!inFile) { cout<<"File could not be open !! Press any Key.show_account(). sizeof(account)).open("account. flag=1. .create_account(). sizeof(account))) { if(ac. outFile. } //*************************************************************** // function to modify record of file //**************************************************************** void modify_account(int n) { int found=0. account ac. } cout<<"\nBALANCE DETAILS\n". if(flag==0) cout<<"\n\nAccount number does not exist".retacno()==n) { ac.ios::binary).write((char *) &ac.ios::binary|ios::app).read((char *) &ac. ifstream inFile. outFile.

} //*************************************************************** // function to display all accounts deposit list . inFile.write((char *) &ac. } } inFile. int pos=(-1)*sizeof(account).modify(). remove("account."account.ios::binary|ios::in|ios::out).. cout<<"\n\n\t Record Updated". cout<<"\n\n\tRecord Deleted . rename("Temp. sizeof(account)) && found==0) { if(ac. File. ac. if(found==0) cout<<"\n\n Record Not Found ".close(). sizeof(account)).dat").. } outFile.ios::binary).seekp(pos.retacno()==n) { ac. if(!inFile) { cout<<"File could not be open !! Press any Key. found=1.read((char *) &ac.dat". inFile.ios::beg). ofstream outFile.dat".dat").".. } } File.open("Temp. return. cout<<"\n\nEnter The New Details of account"<<endl. sizeof(account))) { if(ac.open("account.open("account..show_account(). ifstream inFile.seekg(0. sizeof(account)).retacno()!=n) { outFile.". if(!File) { cout<<"File could not be open !! Press any Key.read((char *) &ac. } while(File. File. return. outFile. while(inFile.write((char *) &ac..dat".ios::binary).ios::cur).close(). File.dat".".close(). } //*************************************************************** // function to delete record of file //**************************************************************** void delete_account(int n) { account ac.

} //*************************************************************** // function to deposit and withdraw amounts //**************************************************************** void deposit_withdraw(int n. inFile.report(). sizeof(account)) && found==0) { if(ac. if(!File) { cout<<"File could not be open !! Press any Key. } cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n". cout<<"\n\nEnter The amount to be withdraw". cout<<"A/c no.dat". cin>>amt. NAME Type Balance\n".retdeposit()-amt.ios::binary).open("account. if((bal<500 && ac. File.read((char *) &ac. if(option==1) { cout<<"\n\n\tTO DEPOSITE AMOUNT ". } inFile.rettype()=='C')) .close(). while(inFile.rettype()=='S') || (bal<1000 && ac. ifstream inFile. sizeof(account))) { ac. return...open("account. } if(option==2) { cout<<"\n\n\tTO WITHDRAW AMOUNT ".//**************************************************************** void display_all() { account ac.dat".. account ac.dep(amt). fstream File. if(!inFile) { cout<<"File could not be open !! Press any Key.retacno()==n) { ac.. } while(File. ios::binary|ios::in|ios::out).read((char *) &ac. int found=0.show_account(). cout<<"====================================================\n".". ac. cout<<"====================================================\n". int bal=ac. int option) { int amt. cout<<"\n\nEnter The amount to be deposited". return.". cin>>amt.

close().write((char *) &ac. File.ios::cur). } //*************************************************************** // INTRODUCTION FUNCTION //**************************************************************** void intro() { cout<<"\n\n\n\t BANK". else ac. cout<<"\n\n\tMANAGEMENT". File.draw(amt). } } File. } //*************************************************************** // END OF PROJECT //*************************************************************** . cout<<"\n\n\n\nMADE BY : YASH & ANUKUMAR". cout<<"\n\n\t Record Updated". found=1. cout<<"\n\n\t SYSTEM". getch().seekp(pos. cout<<"\n\nCOLLEGE : SIESCOMS". } int pos=(-1)* sizeof(ac). sizeof(account)). if(found==0) cout<<"\n\n Record Not Found ". cout<<"Insufficience balance".