Name your source code as .cpp (replace the text with o with your last name and f
ID: 3805996 • Letter: N
Question
Name your source code as .cpp (replace the text with o with your last name and first name, in that order) and upload to blackboard. The goal of this assignment is to design and implement classes. We will continue the lesson from the 2/27 lecture on the banking model. Write a program that implements a class model for storing and managing the following data: Test Data: Create a customer using your name and address. Create two accounts for yourself, a Checking and a Savings. Start with a $100 Credit balance in each account. Fill in the other required data as you like (date opened, time stamp). The customer should be able to perform the following actions: Customer: Get the current balance of funds in a specific account identified by the account ID value. Get the total amount of funds across ALL accounts Add money to an account specified by the ID Retrieve money from an account specified by an ID Once you have built your Class Model, write your program to implement your class by outputting to standard output the following transactions: Get balance info for your checking account. Add $10 to both checking and savings account. Retrieve $50 from your checking account Get the total available balance you now have in both accounts.Explanation / Answer
#include<iostream.h>
#include<fstream.h>
#include<cctype.h>
#include<iomanip.h>
class Account2
{
int acno;
char name[50];
int Depositosit;
char type;
public:
void NewAccount2();
void ShowAccount2() const;
void UpdateAccount2();
void Deposit(int);
void withdraw(int);
void report() const;
int retacno() const;
int retDepositosit() const;
char rettype() const;
};
void Account2::NewAccount2()
{
cout<<" Enter The Account2 No. :";
cin>>acno;
cout<<" Enter The Name of The Account2 Holder : ";
cin.ignore();
cin.getline(name,50);
cout<<" Enter Type of The Account2 (C/S) : ";
cin>>type;
type=toupper(type);
cout<<" Enter The Initial amount(>=500 for Saving and >=1000 for current ) : ";
cin>>Depositosit;
cout<<" Account2 Created..";
}
void Account2::ShowAccount2() const
{
cout<<" Account2 No. : "<<acno;
cout<<" Account2 Holder Name : ";
cout<<name;
cout<<" Type of Account2 : "<<type;
cout<<" Balance amount : "<<Depositosit;
}
void Account2::UpdateAccount2()
{
cout<<" Account2 No. : "<<acno;
cout<<" UpdateAccount2 Account2 Holder Name : ";
cin.ignore();
cin.getline(name,50);
cout<<" UpdateAccount2 Type of Account2 : ";
cin>>type;
type=toupper(type);
cout<<" UpdateAccount2 Balance amount : ";
cin>>Depositosit;
}
void Account2::Deposit(int x)
{
Depositosit+=x;
}
void Account2::withdraw(int x)
{
Depositosit-=x;
}
void Account2::report() const
{
cout<<acno<<setw(10)<<" "<<name<<setw(10)<<" "<<type<<setw(6)<<Depositosit<<endl;
}
int Account2::retacno() const
{
return acno;
}
int Account2::retDepositosit() const
{
return Depositosit;
}
char Account2::rettype() const
{
return type;
}
void write_Account2();
void display_sp(int);
void UpdateAccount2_Account2(int);
void delete_Account2(int); /
void display_all();
void Depositosit_withwithdraw(int, int);
void intro();
int main()
{
char ch;
int num;
intro();
do
{
system("cls");
cout<<" MAIN MENU";
cout<<" 01. NEW ACCOUNT2";
cout<<" 02. DEPOSITOSIT AMOUNT";
cout<<" 03. WITHWITHDRAW AMOUNT";
cout<<" 04. BALANCE ENQUIRY";
cout<<" 05. ALL ACCOUNT2 HOLDER LIST";
cout<<" 06. CLOSE AN ACCOUNT2";
cout<<" 07. UPDATEACCOUNT2 AN ACCOUNT2";
cout<<" 08. EXIT";
cout<<" Select Your Option ";
cin>>ch;
system("cls");
switch(ch)
{
case '1':
write_Account2();
break;
case '2':
cout<<" Enter The Account2 No. : "; cin>>num;
Depositosit_withwithdraw(num, 1);
break;
case '3':
cout<<" Enter The Account2 No. : "; cin>>num;
Depositosit_withwithdraw(num, 2);
break;
case '4':
cout<<" Enter The Account2 No. : "; cin>>num;
display_sp(num);
break;
case '5':
display_all();
break;
case '6':
cout<<" Enter The Account2 No. : "; cin>>num;
delete_Account2(num);
break;
case '7':
cout<<" Enter The Account2 No. : "; cin>>num;
UpdateAccount2_Account2(num);
break;
case '8':
cout<<" Thanks for using bank managemnt system";
break;
default :cout<<"";
}
cin.ignore();
cin.get();
}while(ch!='8');
return 0;
}
void write_Account2()
{
Account2 ac;
ofstream outFile;
outFile.open("Account2.dat",ios::binary|ios::app);
ac.NewAccount2();
outFile.write(reinterpret_cast<char *> (&ac), sizeof(Account2));
outFile.close();
}
void display_sp(int n)
{
Account2 ac;
bool flag=false;
ifstream inFile;
inFile.open("Account2.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
return;
}
cout<<" BALANCE DETAILS ";
while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(Account2)))
{
if(ac.retacno()==n)
{
ac.ShowAccount2();
flag=true;
}
}
inFile.close();
if(flag==false)
cout<<" Account2 number does not exist";
}
void UpdateAccount2_Account2(int n)
{
bool found=false;
Account2 ac;
fstream File;
File.open("Account2.dat",ios::binary|ios::in|ios::out);
if(!File)
{
cout<<"File could not be open !! Press any Key...";
return;
}
while(!File.eof() && found==false)
{
File.read(reinterpret_cast<char *> (&ac), sizeof(Account2));
if(ac.retacno()==n)
{
ac.ShowAccount2();
cout<<" Enter The New Details of Account2"<<endl;
ac.UpdateAccount2();
int pos=(-1)*static_cast<int>(sizeof(Account2));
File.seekp(pos,ios::cur);
File.write(reinterpret_cast<char *> (&ac), sizeof(Account2));
cout<<" Record Updated";
found=true;
}
}
File.close();
if(found==false)
cout<<" Record Not Found ";
}
void delete_Account2(int n)
{
Account2 ac;
ifstream inFile;
ofstream outFile;
inFile.open("Account2.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
return;
}
outFile.open("Temp.dat",ios::binary);
inFile.seekg(0,ios::beg);
while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(Account2)))
{
if(ac.retacno()!=n)
{
outFile.write(reinterpret_cast<char *> (&ac), sizeof(Account2));
}
}
inFile.close();
outFile.close();
remove("Account2.dat");
rename("Temp.dat","Account2.dat");
cout<<" Record Deleted ..";
}
void display_all()
{
Account2 ac;
ifstream inFile;
inFile.open("Account2.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
return;
}
cout<<" ACCOUNT2 HOLDER LIST ";
cout<<"==================================================== ";
cout<<"A/c no. NAME Type Balance ";
cout<<"==================================================== ";
while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(Account2)))
{
ac.report();
}
inFile.close();
}
void Depositosit_withwithdraw(int n, int option)
{
int amt;
bool found=false;
Account2 ac;
fstream File;
File.open("Account2.dat", ios::binary|ios::in|ios::out);
if(!File)
{
cout<<"File could not be open !! Press any Key...";
return;
}
while(!File.eof() && found==false)
{
File.read(reinterpret_cast<char *> (&ac), sizeof(Account2));
if(ac.retacno()==n)
{
ac.ShowAccount2();
if(option==1)
{
cout<<" TO DEPOSITOSITE AMOUNT ";
cout<<" Enter The amount to be Depositosited";
cin>>amt;
ac.Deposit(amt);
}
if(option==2)
{
cout<<" TO WITHWITHDRAW AMOUNT ";
cout<<" Enter The amount to be withwithdraw";
cin>>amt;
int bal=ac.retDepositosit()-amt;
if((bal<500 && ac.rettype()=='S') || (bal<1000 && ac.rettype()=='C'))
cout<<"Insufficience balance";
else
ac.withdraw(amt);
}
int pos=(-1)*static_cast<int>(sizeof(ac));
File.seekp(pos,ios::cur);
File.write(reinterpret_cast<char *> (&ac), sizeof(Account2));
cout<<" Record Updated";
found=true;
}
}
File.close();
if(found==false)
cout<<" Record Not Found ";
}
void intro()
{
cout<<"welcome Bank Management System"
cin.get();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.