**C++ program**
Mini Bank Account Management System: This system aimed to computerize the bank account management operations such as open an account, withdraw money, deposit money etc.
Modules: There are three main parts of the system:
1) Person, Student and Teacher objects, where Person needs to be declared as an abstract base class and Student & Teacher should be declared as derived class.
2) Bank Account containing the account holder
3) Bank transactions such as open an account, withdraw and deposit money
Main Menu: Main Manu consists of the following items:
1) Main Menu
2) Administrator Menu
3) Open Account
4) Close Account
5) Withdraw Money
6) Deposit Money
7) Display Account holder with maximum deposit
8) Exit If user choose the Administrator menu then system will display another submenu, which will show the following submenu options:
1) Create Student Record
2) Display All Student Records
3) Display All Students by Last Name
4) Display Specific Student Record
5) Modify Student Record
6) Delete Student Record
7) Create Teacher Record
8) Display All Teacher Records
9) Display Specific Teacher Record
10) Modify Teacher Record
11) Delete Teacher Record
12) Return to Main Menu
Data storage: data can be stored in a text file. Therefore, you must use the file read and write operations for data retrieval and storage. For this system, three files required: Student.txt, Teacher.txt and Bank Account.txt.
N.B: The above requirements can be considered as a guideline for this project. You can provide more functionalities for the proposed system. However, the above features must be present to achieve full credits from this Term Project. All inputs must be considered and displayed a proper error message. You can create a simple console based project with the above menu, where the system will prompt the user to enter the corresponding number from the keyboard to execute an operation. e.g. user needs to enter 3 for opening a bank account.
Expert Answer
#include<iostream>
#include<fstream>
#include<cstdlib>
using std::cout;
using std::cin;
using std::endl;
using std::fstream;
using std::ofstream;
using std::ifstream;
using std::ios;
class account_query
{
private:
char account_number[10];
char firstName[08];
char lastName[08];
float total_Balance;
public:
void read_data();
void show_data();
void write_rec();
void read_rec();
void search_rec();
void edit_rec();
void delete_rec();
};
void account_query::read_data()
{
cout<<“nEnter Account Number: “;
cin>>account_number;
cout<<“Enter First Name: “;
cin>>firstName;
cout<<“Enter Last Name: “;
cin>>lastName;
cout<<“Enter Balance: “;
cin>>total_Balance;
cout<<endl;
}
void account_query::show_data()
{
cout<<“Account Number: “<<account_number<<endl;
cout<<“First Name: “<<firstName<<endl;
cout<<“Last Name: “<<lastName<<endl;
cout<<“Current Balance: Rs. “<<total_Balance<<endl;
cout<<“—————–“<<endl;
}
void account_query::write_rec()
{
ofstream outfile;
outfile.open(“record.bank”, ios::binary|ios::app);
read_data();
outfile.write(reinterpret_cast<char *>(this), sizeof(*this));
outfile.close();
}
void account_query::read_rec()
{
ifstream infile;
infile.open(“record.bank”, ios::binary);
if(!infile)
{
cout<<“Error in Opening! File Not Found!!”<<endl;
return;
}
cout<<“n****Data from file****”<<endl;
while(!infile.eof())
{
if(infile.read(reinterpret_cast<char*>(this), sizeof(*this))>0)
{
show_data();
}
}
infile.close();
}
void account_query::search_rec()
{
int n;
ifstream infile;
infile.open(“record.bank”, ios::binary);
if(!infile)
{
cout<<“nError in opening! File Not Found!!”<<endl;
return;
}
infile.seekg(0,ios::end);
int count = infile.tellg()/sizeof(*this);
cout<<“n There are “<<count<<” record in the file”;
cout<<“n Enter Record Number to Search: “;
cin>>n;
infile.seekg((n-1)*sizeof(*this));
infile.read(reinterpret_cast<char*>(this), sizeof(*this));
show_data();
}
void account_query::edit_rec()
{
int n;
fstream iofile;
iofile.open(“record.bank”, ios::in|ios::binary);
if(!iofile)
{
cout<<“nError in opening! File Not Found!!”<<endl;
return;
}
iofile.seekg(0, ios::end);
int count = iofile.tellg()/sizeof(*this);
cout<<“n There are “<<count<<” record in the file”;
cout<<“n Enter Record Number to edit: “;
cin>>n;
iofile.seekg((n-1)*sizeof(*this));
iofile.read(reinterpret_cast<char*>(this), sizeof(*this));
cout<<“Record “<<n<<” has following data”<<endl;
show_data();
iofile.close();
iofile.open(“record.bank”, ios::out|ios::in|ios::binary);
iofile.seekp((n-1)*sizeof(*this));
cout<<“nEnter data to Modify “<<endl;
read_data();
iofile.write(reinterpret_cast<char*>(this), sizeof(*this));
}
void account_query::delete_rec()
{
int n;
ifstream infile;
infile.open(“record.bank”, ios::binary);
if(!infile)
{
cout<<“nError in opening! File Not Found!!”<<endl;
return;
}
infile.seekg(0,ios::end);
int count = infile.tellg()/sizeof(*this);
cout<<“n There are “<<count<<” record in the file”;
cout<<“n Enter Record Number to Delete: “;
cin>>n;
fstream tmpfile;
tmpfile.open(“tmpfile.bank”, ios::out|ios::binary);
infile.seekg(0);
for(int i=0; i<count; i++)
{
infile.read(reinterpret_cast<char*>(this),sizeof(*this));
if(i==(n-1))
continue;
tmpfile.write(reinterpret_cast<char*>(this), sizeof(*this));
}
infile.close();
tmpfile.close();
remove(“record.bank”);
rename(“tmpfile.bank”, “record.bank”);
}
int main()
{
account_query A;
int choice;
cout<<“***Acount Information System***”<<endl;
while(true)
{
cout<<“Select one option below “;
cout<<“nt1–>Add record to file”;
cout<<“nt2–>Show record from file”;
cout<<“nt3–>Search Record from file”;
cout<<“nt4–>Update Record”;
cout<<“nt5–>Delete Record”;
cout<<“nt6–>Quit”;
cout<<“nEnter your choice: “;
cin>>choice;
switch(choice)
{
case 1:
A.write_rec();
break;
case 2:
A.read_rec();
break;
case 3:
A.search_rec();
break;
case 4:
A.edit_rec();
break;
case 5:
A.delete_rec();
break;
case 6:
exit(0);
break;
default:
cout<<“nEnter corret choice”;
exit(0);
}
}
system(“pause”);
return 0;
}