Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. Banks offer various types of accounts, such as savings, checking, certificate

ID: 3859432 • Letter: 5

Question

5. Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market, to attract customers as well as meet their specific needs. Two of the most commonly used accounts are savings and checking. Each of these accounts has various options. For example, you may have a savings account that requires no minimum balance but has a lower interest rate. Similarly, you may have a checking account that limits the number of checks you may write. Another type of account that is used to save money for the long term is certificate of deposit (CD). In this programming exercise, you use abstract classes and pure virtual functions to design classes to manipulate various types of accounts. For simplicity, assume that the bank offers three types of accounts: savings, checking, and certificate of deposit, as described next. Savings accounts: Suppose that the bank offers two types of savings accounts: one that has no minimum balance and a lower interest rate and another that requires a minimum balance and has a higher interest rate. Checking accounts: Suppose that the bank offers three types of checking accounts: one with a monthly service charge, limited check writing, no minimum balance, and no interest; another with no monthly service charge, a minimum balance requirement, unlimited check writing and lower interest; and a third with no monthly service charge, a higher minimum requirement, a higher interest rate, and unlimited check writing. Certificate of deposit (CD): In an account of this type, money is left for some time, and these accounts draw higher interest rates than savings or checking accounts. Suppose that you purchase a CD for six months. Then we say that the CD will mature in six months. The penalty for early withdrawal is stiff. Figure 12-25 shows the inheritance hierarchy of these bank accounts.

Note that the classes bankAccount and checkingAccount are abstract. That is, we cannot instantiate objects of these classes. The other classes in Figure 12-25 are not abstract. bankAccount: Every bank account has an account number, the name of the owner, and a balance. Therefore, instance variables such as name, accountNumber, andbalance should be declared in the abstract class bankAccount. Some operations common to all types of accounts are retrieve account owner’s name, account number, and account balance; make deposits; withdraw money; and create monthly statements. So include functions to implement these operations. Some of these functions will be pure virtual. checkingAccount: A checking account is a bank account. Therefore, it inherits all the properties of a bank account. Because one of the objectives of a checking account is to be able to write checks, include the pure virtual function writeCheck to write a check. serviceChargeChecking: A service charge checking account is a checking account. Therefore, it inherits all the properties of a checking account. For simplicity, assume that this type of account does not pay any interest, allows the account holder to write a limited number of checks each month, and does not require any minimum balance. Include appropriate named constants, instance variables, and functions in this class. noServiceChargeChecking: A checking account with no monthly service charge is a checking account. Therefore, it inherits all the properties of a checking account. Furthermore, this type of account pays interest, allows the account holder to write checks, and requires a minimum balance. highInterestChecking: A checking account with high interest is a checking account with no monthly service charge. Therefore, it inherits all the properties of a no service charge checking account. Furthermore, this type of account pays higher interest and requires a higher minimum balance than the no service charge checking account. savingsAccount: A savings account is a bank account. Therefore, it inherits all the properties of a bank account. Furthermore, a savings account also pays interest. highInterestSavings: A high-interest savings account is a savings account. Therefore, it inherits all the properties of a savings account. It also requires a minimum balance. certificateOfDeposit: A certificate of deposit account is a bank account. Therefore, it inherits all the properties of a bank account. In addition, it has instance variables to store the number of CD maturity months, interest rate, and the current CD month. Write the definitions of the classes described in this programming exercise and a program to test your classes.

I really need help with this. Its in C++ language

Explanation / Answer

#include<iostream> //For Turbo C++, write iostream.h
#include<fstream> //For Turbo C++, write fstream.h
#include<cctype> //For Turbo C++, write cctype.h
#include<iomanip> //For Turbo C++, write iomanip.h
using namespace std; //Not required for Turbo C++, So you can safely remove in that

class acc //Class definition starts
{
int ano;
char name[100];
int dep;
char type;
public:
void createaccount(); //function to create a new account
void showacccount() const; //function to show account details
void modify(); //function to modify account details
void adep(int); //function to accept deposit amount
void draw(int); //function to subtract withdrawal amount
void report() const; //function to show data in tabular format
int retano() const; //For returning account number
int retbal() const; //For returning balance amount
char qtype() const; //For returning type of account
}; //Class definition ends

void acc::createaccount()
{
cout<<" Enter The Account Number :";
cin>>ano;
cout<<" Enter, Name of The Account Holder : ";
cin.ignore();
cin.getline(name,100);
cout<<" Enter Type of Account(Current/Savings) : ";
cin>>type;
cout<<" Enter The Initial amount(>=500 for Saving and >=1000 for current ) : ";
cin>>dep; //We have set the minimum initial amount for savings be 500 & for current be 1000
cout<<" Congrats Account Has Been Created..";
}

void acc::showacccount() const
{
cout<<" Account Number : "<<ano;
cout<<" Account Holder Name : ";
cout<<name;
cout<<" Type of Account : "<<type;
cout<<" Balance amount : "<<dep;
}


void acc::modify()
{
cout<<" Account Number : "<<ano;
cout<<" Modify Account Holder Name : ";
cin.ignore();
cin.getline(name,100);
cout<<" Modify Type of Account : ";
cin>>type;
cout<<" Modify Balance amount : ";
cin>>dep;
}

void acc::adep(int x)
{
dep+=x;
}
  
void acc::draw(int x)
{
dep-=x;
}
  
void acc::report() const
{
cout<<ano<<setw(10)<<" "<<name<<setw(10)<<" "<<type<<setw(6)<<dep<<endl;
}
  
int acc::retano() const
{
return ano;
}

int acc::retbal() const
{
return dep;
}

char acc::qtype() const
{
return type;
}

void write_acc(); //function to write record in binary file
void display_sp(int); //function to display account details given by user
void modify_acc(int); //function to modify record of file
void delete_acc(int); //function to delete record of file
void display_all(); //function to display all account details
void dep_withdraw(int, int); // function to desposit/withdraw amount for given account
void intro(); //introductory screen function

int main()
{
char ch;
int num;
intro();
do
{
system("cls"); //Clear The Screen
cout<<" ACTION MENU";
cout<<" 01. NEW ACCOUNT";
cout<<" 02. DEPOSIT";
cout<<" 03. WITHDRAW";
cout<<" 04. BALANCE ENQUIRY";
cout<<" 05. COMPLETE ACCOUNT HOLDERS LIST";
cout<<" 06. CLOSE AN ACCOUNT";
cout<<" 07. MODIFY AN ACCOUNT";
cout<<" 08. EXIT";
cout<<" Select Your Option (1-8) ";
cin>>ch;
system("cls"); //Clear The Screen
switch(ch)
{
case '1':
write_acc();
break;
case '2':
cout<<" Enter The Account Number : "; cin>>num;
dep_withdraw(num, 1);
break;
case '3':
cout<<" Enter The Account Number : "; cin>>num;
dep_withdraw(num, 2);
break;
case '4':
cout<<" Enter The Account Number : "; cin>>num;
display_sp(num);
break;
case '5':
display_all();
break;
case '6':
cout<<" Enter The Account Number : "; cin>>num;
delete_acc(num);
break;
case '7':
cout<<" Enter The Account Number : "; cin>>num;
modify_acc(num);
break;
case '8':
cout<<" Thanks For Visiting Our Bank!";
break;
default :cout<<"";
}
cin.ignore();
cin.get();
}while(ch!='8');
return 0;
}// Function To write the account data to .dat file
void write_acc()
{
acc ac;
ofstream x;
x.open("info.dat",ios::binary|ios::app);
ac.createaccount();
x.write(reinterpret_cast<char *> (&ac), sizeof(acc));
x.close();
}


void display_sp(int n) //function to retrive a record from file stored
{
acc ac;
bool flag=false;
ifstream x;
x.open("info.dat",ios::binary);
if(!x)
{
cout<<"File could not be opened!! Press any Key to exit...";
return;
}
cout<<" BALANCE DETAILS ";

while(x.read(reinterpret_cast<char *> (&ac), sizeof(acc)))
{
if(ac.retano()==n)
{
ac.showacccount();
flag=true;
}
}
x.close();
if(flag==false)
cout<<" Account number does not exist";
}//function to modify record of an account which is stored in file
void modify_acc(int n)
{
bool found=false;
acc ac;
fstream x;
x.open("info.dat",ios::binary|ios::in|ios::out);
if(!x)
{
cout<<"File could not be open !! Press any Key...";
return;
}
while(!x.eof() && found==false)
{
x.read(reinterpret_cast<char *> (&ac), sizeof(acc));
if(ac.retano()==n)
{
ac.showacccount();
cout<<" Enter The New Details of account"<<endl;
ac.modify();
int pos=(-1)*static_cast<int>(sizeof(acc));
x.seekp(pos,ios::cur);
x.write(reinterpret_cast<char *> (&ac), sizeof(acc));
cout<<" Record Updated";
found=true;
}
}
x.close();
if(found==false)
cout<<" Record Not Found ";
}//function to delete a record from file
void delete_acc(int n)
{
acc ac;
ifstream x;
ofstream y;
x.open("info.dat",ios::binary);
if(!x)
{
cout<<"File could not be open !! Press any Key...";
return;
}
y.open("Temp.dat",ios::binary);
x.seekg(0,ios::beg);
while(x.read(reinterpret_cast<char *> (&ac), sizeof(acc)))
{
if(ac.retano()!=n)
{
y.write(reinterpret_cast<char *> (&ac), sizeof(acc));
}
}
x.close();
y.close();
remove("info.dat");
rename("Temp.dat","info.dat");
cout<<" Record Deleted ..";
}// function to display account details from the stored file
void display_all()
{
acc ac;
ifstream x;
x.open("info.dat",ios::binary);
if(!x)
{
cout<<"File could not be open !! Press any Key...";
return;
}
cout<<" ACCOUNT HOLDER LIST ";
cout<<"==================================================== ";
cout<<"A/c no. NAME Type Balance ";
cout<<"==================================================== ";
while(x.read(reinterpret_cast<char *> (&ac), sizeof(acc)))
{
ac.report();
}
x.close();
}// function to withdraw amout from the account
void dep_withdraw(int n, int option)
{
int amt;
bool found=false;
acc ac;
fstream x;
x.open("info.dat", ios::binary|ios::in|ios::out);
if(!x)
{
cout<<"File could not be open !! Press any Key...";
return;
}
while(!x.eof() && found==false)
{
x.read(reinterpret_cast<char *> (&ac), sizeof(acc));
if(ac.retano()==n)
{
ac.showacccount();
if(option==1)
{
cout<<" TO DEPOSITE AMOUNT ";
cout<<" Enter The amount to be deposited";
cin>>amt;
ac.adep(amt);
}
if(option==2)
{
cout<<" TO WITHDRAW AMOUNT ";
cout<<" Enter The amount to be withdraw";
cin>>amt;
int bal=ac.retbal()-amt;
if((bal<500 && ac.qtype()=='S') || (bal<1000 && ac.qtype()=='C'))
cout<<"Insufficience balance";
else
ac.draw(amt);
}
int pos=(-1)*static_cast<int>(sizeof(ac));
x.seekp(pos,ios::cur);
x.write(reinterpret_cast<char *> (&ac), sizeof(acc));
cout<<" Record Updated";
found=true;
}
}
x.close();
if(found==false)
cout<<" Record Not Found ";
}//The Entry/Welcome Screen
void intro()
{
cout<<" Welcome To XYZ BANK MANAGEMENT SYSTEM";
cout<<" A C++ Code Project by Student, Student At Army School Ranikhet";
//Note: All the data of the new account entered will be stored in the disk
//So Please use with Admin Privilage for the compiled .exe, so that it could access the disk space
cout<<" Press Enter To Continue........";
cin.get();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote