You are on page 1of 9

#include<iostream>

#include<fstream>
#include<string>
#include<iomanip>
#include<stdlib.h>
#include<stdio.h>
#include<windows.h>
#include<process.h>
#include<conio.h>
const int size=50;
using namespace std;

class NewAccount
{
int account_id,pass,age; float balance; char name[size],address[size];
void storeInfo();
void depositFunds();
void withdrawFunds();
void updateAccount();
void deleteAccount();
void showInfo();
public:
NewAccount() : account_id(),pass(),balance(),age()
{
strcpy(name,"");
strcpy(address,"");
}
class AError{};
class BError{};
void signupAccount();
void signinAccount();
void viewAllInfo();

};

void NewAccount :: signupAccount()


{
cout << "\n\t\t\t\t***Create New Account***"<<endl;
cin.ignore();
cout << "\n\t* Enter Your Full Name: "; cin.getline(name,49);
cout << "\n\t* Enter Your Password: "; cin>>pass;
cout << "\n\t* Enter Your Age: "; cin>>age;
if(age>=18)
{
cin.ignore();
cout << "\n\t* Enter Your Address: "; cin.getline(address,49);
cout << "\n\t* Deposit Your Initial Balance(minimum 500.00$): ";
cin>>balance;
if(balance>=500)
{
storeInfo();
cout << "\n\nCongratulation!! Your Bank Account is
Sucessfully Created!!"<<endl;
}
else
{
throw BError();
}
}
else
{
throw AError();
}
}

void NewAccount :: storeInfo()


{
ofstream fout;
if(pass==0 && balance==0)
{
cout << "\n\tError! Your Account is not Sucessfully Created" << endl;
}
else
{
fout.open("Bank.txt",ios::app|ios::binary);
fout.write(reinterpret_cast<char*> (this) , sizeof(*this));
fout.close();
}
}

void NewAccount ::signinAccount()


{
char n[size] ; int password,choice; bool log=false; NewAccount temp; string
ch;
cin.ignore();
cout << "\n\t\t\t**** SignIn Account ****"<<endl;
cout << "\nEnter Your Name: "; cin.getline(n,size);
cout << "Enter Your Password: "; cin>>password;
fstream file;
file.open("Bank.txt",ios::in|ios::out|ios::ate|ios::binary);
if(!file)
{
cout << "\n\t\t**Data Not Found**!!" << endl;
}
else
{
file.seekg(0);
file.read(reinterpret_cast<char*>(this) , sizeof(*this) );
while(!file.eof())
{
if(!strcmp(name,n) && pass == password)
{
int c1,c2;
log = true;
cout << "\tSucessfully logged in!\n" << endl;

system("pause");
system("CLS");
cout << "\n Welcome " << name << "!" << endl;
cout << "Please Follow the Instruction Given
Below"<<endl;
cout << "\n* Press 1) to Deposit Funds"<<endl;
cout << "* Press 2) to Withdraw Funds"<<endl;
cout << "* Press 3) to View Account Details"<<endl;
cout << "* Press 4) to Update Account Details"<<endl;
cout << "* Press 5) to Delete Your Account"<<endl;
cout << "* Press 6) to Exit Your Account"<<endl;
cout << "\nEnter Your Choice: "; cin>> choice;
while(1)
{
switch(choice)
{
case 1:
system("CLS");
depositFunds();
c1 = file.tellg();
c2 = sizeof*this;
file.seekg(c1-c2);

file.write(reinterpret_cast<char*>(this) , sizeof(*this) );
break;
case 2:
system("CLS");
withdrawFunds();
c1 = file.tellg();
c2 = sizeof*this;
file.seekg(c1-c2);

file.write(reinterpret_cast<char*>(this) , sizeof(*this) );
system("pause");
break;
case 3:
system("CLS");
showInfo();
system("pause");
break;
case 4:
system("CLS");
temp = *this;
temp.updateAccount();
cout << "\n\t\t* Enter 'Y' to save these
Changes" << endl;
cout << "\n\t\t* Enter any key to Discard
these Changes" << endl;
cout << "Enter Your Choice: "; cin >>
ch;
if(ch=="Y" || ch == "y")
{
*this = temp;
c1 = file.tellg();
c2 = sizeof*this;
file.seekg(c1-c2);

file.write(reinterpret_cast<char*>(this) , sizeof(*this) );
cout << "\n\t* Changes are
Sucessfully Saved!!" << endl;
system("pause");
break;
}
else
{
break;
}
case 5:
file.close();
system("CLS");
cout << "\n\n\t\t* Enter 'Y' to Delete
Your Account" << endl;
cout << "\n\t\t* Enter any key to Discard
Deletion" << endl;
cout << "Enter Your Choice: "; cin >>
ch;
if(ch=="Y" || ch == "y")
{
deleteAccount();
system("pause");
}
break;
case 6:
file.close();
system("CLS");
cout << "\n\t\t** You Account is Sign out
**"<< endl;
cout << "\n\tThanks For Using Our Bank
Service!\n"<<endl;
system("pause");
break;
default:
cout << "Error! Your Entry is Invalid"
<<endl;
system("pause");
break;
}
system("CLS");
if(choice!=6 && choice !=5)
{
cout << "\t\t\t***** Welcome " << name << "
****" << endl;
cout << "Please Follow the Instruction Given
Below"<<endl;
cout << "\n* Press 1) to Deposit Funds"<<endl;
cout << "* Press 2) to Withdraw Funds"<<endl;
cout << "* Press 3) to View Account
Details"<<endl;
cout << "* Press 4) to Update Account
Details"<<endl;
cout << "* Press 5) to Delete Your
Account"<<endl;
cout << "* Press 6) to Exit Your
Account"<<endl;
cout << "\nEnter Your Choice: "; cin>> choice;
system("CLS");
}
else
{
break;
}
}
}
file.read(reinterpret_cast<char*>(this) ,
sizeof(*this) );
}
if(log==false)
{
cout << "\tLogin Failed!" << endl;
system("pause");
}
file.close();
}
}

void NewAccount ::viewAllInfo()


{
ifstream fin;
fin.open("Bank.txt",ios::binary);
if(!fin)
{
cout << "\n\t\t**Data Not Found**!!" << endl;
}
else
{
fin.read(reinterpret_cast<char*>(this) , sizeof(*this) );

while(!fin.eof())
{
showInfo();
fin.read(reinterpret_cast<char*>(this) , sizeof(*this) );
}
fin.close();
}
}

void NewAccount::depositFunds()
{
float b;
cout << "Enter the Deposit Balance: "; cin>>b;
balance += b;
}

void NewAccount :: withdrawFunds()


{
float b;
cout << "Enter the Withdraw Balance: "; cin>>b;
if(b < (balance-500))
{
balance -= b;
}
else
{
cout << "\t* Error! Your Withdraw is Failed"<<endl;
}
}

void NewAccount :: updateAccount()


{
char n[size],ad[size];
int choice,a,p;
system("CLS");
cout << "\n\t\t\t**** Update Your Profile ****" << endl;
cout << "\n\n\t* Press 1) to Update Your Name"<<endl;
cout << "\t* Press 2) to Update Your Password"<<endl;
cout << "\t* Press 3) to Update Your Age"<<endl;
cout << "\t* Press 4) to Update Your Address"<<endl;
cout << "\t* Press 5) to Update Your Whole Profile"<<endl;
cout << "\t* Press 6) to Discard Any Update"<<endl;
cout << "\nEnter Your Choice: ";
cin>> choice;
while(1)
{
switch(choice)
{
case 1:
cin.ignore();
cout << "\n\t* Enter Your New Name: "; cin.getline(name,49);
break;
case 2:
cout << "\n\t* Enter New Password: "; cin>>pass;
break;
case 3:
cout << "\n\t* Enter Your Age: "; cin>>a;
if(a>=18)
{
age = a;
}
else
{
cout << "Error! your Age is Less than 18" <<endl;
}
break;
case 4:
cin.ignore();
cout << "\n\t* Enter Your Address: "; cin.getline(address,49);
break;
case 5:
cin.ignore();
cout << "\n\t* Enter Your Full Name: "; cin.getline(n,49);
cout << "\n\t* Enter Your Password: "; cin>>p;
cout << "\n\t* Enter Your Age: "; cin>>a;
if(a>=18)
{
cin.ignore();
cout << "\n\t* Enter Your Address: "; cin.getline(ad,49);
age = a; pass = p;
for(int i=0;i<size;i++)
{
name[i] = n[i];
address[i] = ad[i];
}

break;
}
else
{
cout << "Error! your Age is Less than 18" <<endl;
break;
}
case 6:
break;
default:
cout << "Error! Your Entry is Invalid" << endl;
break;
}
if(choice<1 || choice>6 )
{
system("CLS");
cout << "\n\t\t\t**** Update Your Profile ****" << endl;
cout << "\n\t\t* Press 1) to Update Your Name"<<endl;
cout << "\t* Press 2) to Update Your Password"<<endl;
cout << "\t* Press 3) to Update Your Age"<<endl;
cout << "\t* Press 4) to Update Your Address"<<endl;
cout << "\t* Press 5) to Update Your Whole Profile"<<endl;
cout << "\t* Press 6) to Discard Any Update"<<endl;
cout << "\nEnter Your Choice: ";
cin>> choice;
}
else
break;
}
}
void NewAccount :: deleteAccount()
{
NewAccount temp; bool y=false;
ifstream fin; ofstream fout;
fin.open("Bank.txt",ios::binary);
if(!fin)
{
cout << "\nError! Data file not found" << endl;
}
else
{
fin.read(reinterpret_cast<char*>(&temp),sizeof(temp));
fout.open("Temp.txt",ios::binary);
while(!fin.eof())
{
if( strcmp(name , temp.name) && !(pass == temp.pass) )
{
fout.write(reinterpret_cast<char*>(&temp),sizeof(temp));
y = true;
}

fin.read(reinterpret_cast<char*>(&temp),sizeof(temp));
}
if(y == false)
{
cout << "\n\n\t\t*** Deletion Unsucessful ***" << endl;
}
else
{
cout << "\n\n\t\t *** Your Account is Sucessfully Deleted ***" <<
endl;
}
fin.close(); fout.close();
remove("Bank.txt");
rename("Temp.txt","Bank.txt");
}
}

void NewAccount :: showInfo()


{
cout << "\n\t\t **** "<<name<<" Account Info****"<<endl;
cout << "\n\t* Your Full Name: " << name<<endl;
cout << "\t* Your Account id: " << account_id<<endl;
cout << "\t* Your Password: " << pass<<endl;
cout << "\t* Your Age: " << age <<endl;
cout <<"\t* Your Current Balance: " << balance << "$" << endl;
cout << "\t* Your Address: " << address << endl;
}

int main()
{
try
{
NewAccount obj; int choice;
//obj.viewAllInfo();

system("color 1B");

Sleep(1000);
cout<<"\n\t\t****Project Title: Bank Account System****\n\n";
Sleep(1000);
cout<<"Group Members: "<<endl<<endl;
Sleep(1000);
cout<<"(1). Rana Muhmmad Usman Shahid "<<endl;
Sleep(1000);
cout<<"\n(2). Hafiz Muhammad Awais Bajwa "<<endl;
Sleep(1000);
cout<<"\n(3). Junaid Ahmad Shahid "<<endl;
Sleep(2000);

system("CLS");

cout << "\n\t\t\t****Welcome to MCB Bank Limited****"<<endl;


cout << "Please Follow the Instruction Given Below"<<endl;
cout<<"\n\t* Press 1) to Signup Account"<<endl;
cout<<"\t* Press 2) to Signin Account"<<endl;
cout<<"\t* Press 3) to Exit"<<endl;
cout << "\nEnter Your Choice: ";
cin>> choice;
while(1)
{
switch(choice)
{
case 1:
system("CLS");
obj.signupAccount();
system("pause");
break;
case 2:
system("CLS");
obj.signinAccount();
break;
case 3:
exit(1);
break;
default:
cout << "Error! Your Entry is Invalid" << endl;
system("pause");
break;
}
system("CLS");
cout << "\n\t\t\t**** Welcome to MCB Bank Limited ****"<<endl;
cout << "Please Follow the Instruction Given Below"<<endl;
cout<<"\n\t* Press 1) to Signup Account"<<endl;
cout<<"\t* Press 2) to Signin Account"<<endl;
cout<<"\t* Press 3) to Exit"<<endl;
cout << "\nEnter Your Choice: ";
cin>> choice;
}
}
catch(NewAccount::AError)
{
cout << "\n\tSorry! You are not eligible for using this service"<<endl;
}
catch(NewAccount::BError)
{
cout << "\n\tSorry! Your Information doesn't meet the requirments of
Bank"<<endl;
}
system("pause");

You might also like