C++ Programming: Program Design Including Data Structures, 7th Edition Chapter 1
ID: 3860200 • Letter: C
Question
C++ Programming: Program Design Including Data Structures, 7th Edition
Chapter 12
PE #5
C++, using Visual Studio
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, and balance 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
bankAccoun checkingåccount ceificateofpeposit savingsAccount rt serviceChargeChecking noServiceChargeChecking highInterestSavings highInterestCh eckingExplanation / Answer
The required code is as follows:
BankAccount.cpp
#include<fstream.h>
#include<ctype.h>
#include<iomanip.h>
#include<conio.h>
#include<stdio.h>
class acc
{
int ac;
char nm[50];
int depo;
char bty;
public:
void new_acc();
void modify_acc();
void alter();
void deposit(int);
void withdraws(int);
void reporting();
int reAcNo();
int reDepo();
char reTypes();
};
void acc::new_acc()
{
cout<<" Enter The acc No.";
cin>>ac;
cout<<" Enter The Name of The acc Holder : ";
gets(nm);
cout<<" Enter Type of The acc (C/S) : ";
cin>>bty;
bty=toupper(bty);
cout<<" Enter The Initial amount(>=500 for Saving and >=1000 for current ) : ";
cin>>depo;
cout<<" Account Created..";
}
void acc::modify_acc()
{
cout<<" Account No. : "<<ac;
cout<<" Account Holder Name : ";
cout<<nm;
cout<<" Type of Account : "<<bty;
cout<<" Balance amount : "<<depo;
}
void acc::alter()
{
cout<<" The acc No."<<ac;
cout<<" Enter The Name of The acc Holder : ";
gets(nm);
cout<<" Enter Type of The acc (C/S) : ";
cin>>bty;
bty=toupper(bty);
cout<<" Enter The amount : ";
cin>>depo;
}
void acc::deposit(int io)
{
depo+=io;
}
void acc::withdraws(int io)
{
depo-=io;
}
void acc::reporting()
{
cout<<ac<<setw(10)<<" "<<nm<<setw(10)<<" "<<bty<<setw(6)<<depo<<endl;
}
int acc::reAcNo()
{
return ac;
}
int acc::reDepo()
{
return depo;
}
char acc::reTypes()
{
return bty;
}
void fill_acc();
void print(int);
void altering_acc(int);
void del_acc(int);
void print_all();
void depo_with(int, int);
void introductory();
int main()
{
char choice;
int no;
clrscr();
introductory();
do
{
clrscr();
cout<<" MAIN MENU";
cout<<" 01. NEW ACCOUNT";
cout<<" 02. DEPOSIT AMOUNT";
cout<<" 03. WITHDRAW AMOUNT";
cout<<" 04. BALANCE ENQUIRY";
cout<<" 05. ALL ACCOUNT HOLDER LIST";
cout<<" 06. CLOSE AN ACCOUNT";
cout<<" 07. MODIFY AN ACCOUNT";
cout<<" 08. EXIT";
cout<<" Select Your Option (1-8) ";
cin>>choice;
clrscr();
switch(choice)
{
case '1':
fill_acc();
break;
case '2':
cout<<" Enter The acc No. : "; cin>>no;
depo_with(no, 1);
break;
case '3':
cout<<" Enter The acc No. : "; cin>>no;
depo_with(no, 2);
break;
case '4':
cout<<" Enter The acc No. : "; cin>>no;
print(no);
break;
case '5':
print_all();
break;
case '6':
cout<<" Enter The acc No. : "; cin>>no;
del_acc(no);
break;
case '7':
cout<<" Enter The acc No. : "; cin>>no;
altering_acc(no);
break;
case '8':
cout<<" Thanks for using bank managemnt system";
break;
default :cout<<"";
}
getch();
}while(choice!='8');
return 0;
}
void fill_acc()
{
acc ac;
ofstream of;
of.open("acc.dat",ios::binary|ios::app);
ac.new_acc();
of.write((char *) &ac, sizeof(acc));
of.close();
}
void print(int n)
{
acc ac;
int sym=0;
ifstream iFl;
iFl.open("acc.dat",ios::binary);
if(!iFl)
{
cout<<"fll could not be open !! Press any Key...";
return;
}
cout<<" BALANCE DETAILS ";
while(iFl.read((char *) &ac, sizeof(acc)))
{
if(ac.reAcNo()==n)
{
ac.modify_acc();
sym=1;
}
}
iFl.close();
if(sym==0)
cout<<" Account number does not exist";
}
void altering_acc(int n)
{
int fnd=0;
acc ac;
fstream fll;
fll.open("acc.dat",ios::binary|ios::in|ios::out);
if(!fll)
{
cout<<"fll could not be open !! Press any Key...";
return;
}
while(fll.read((char *) &ac, sizeof(acc)) && fnd==0)
{
if(ac.reAcNo()==n)
{
ac.modify_acc();
cout<<" Enter The New Details of acc"<<endl;
ac.alter();
int pos=(-1)*sizeof(acc);
fll.seekp(pos,ios::cur);
fll.write((char *) &ac, sizeof(acc));
cout<<" Record Updated";
fnd=1;
}
}
fll.close();
if(fnd==0)
cout<<" Record Not Found ";
}
void del_acc(int n)
{
acc ac;
ifstream iFl;
ofstream of;
iFl.open("acc.dat",ios::binary);
if(!iFl)
{
cout<<"fll could not be open !! Press any Key...";
return;
}
of.open("Temp.dat",ios::binary);
iFl.seekg(0,ios::beg);
while(iFl.read((char *) &ac, sizeof(acc)))
{
if(ac.reAcNo()!=n)
{
of.write((char *) &ac, sizeof(acc));
}
}
iFl.close();
of.close();
remove("acc.dat");
rename("Temp.dat","acc.dat");
cout<<" Record Deleted ..";
}
void print_all()
{
acc ac;
ifstream iFl;
iFl.open("acc.dat",ios::binary);
if(!iFl)
{
cout<<"fll could not be open !! Press any Key...";
return;
}
cout<<" ACCOUNT HOLDER LIST ";
cout<<"==================================================== ";
cout<<"A/c no. NAME Type Balance ";
cout<<"==================================================== ";
while(iFl.read((char *) &ac, sizeof(acc)))
{
ac.reporting();
}
iFl.close();
}
void depo_with(int n, int chances)
{
int amount;
int fnd=0;
acc ac;
fstream fll;
fll.open("acc.dat", ios::binary|ios::in|ios::out);
if(!fll)
{
cout<<"fll could not be open !! Press any Key...";
return;
}
while(fll.read((char *) &ac, sizeof(acc)) && fnd==0)
{
if(ac.reAcNo()==n)
{
ac.modify_acc();
if(chances==1)
{
cout<<" TO DEPOSITE AMOUNT ";
cout<<" Enter The amount to be deposited";
cin>>amount;
ac.deposit(amount);
}
if(chances==2)
{
cout<<" TO WITHDRAW AMOUNT ";
cout<<" Enter The amount to be withdraw";
cin>>amount;
int bal=ac.reDepo()-amount;
if((bal<500 && ac.reTypes()=='S') || (bal<1000 && ac.reTypes()=='C'))
cout<<"Insufficience balance";
else
ac.withdraws(amount);
}
int pos=(-1)* sizeof(ac);
fll.seekp(pos,ios::cur);
fll.write((char *) &ac, sizeof(acc));
cout<<" Record Updated";
fnd=1;
}
}
fll.close();
if(fnd==0)
cout<<" Record Not Found ";
}
void introductory()
{
cout<<" BANK";
cout<<" MANAGEMENT";
cout<<" SYSTEM";
cout<<" MADE BY : Akshay Bisht";
cout<<" ID : XXXXXXXXXXXXXXXXXX;
getch();
}
Please rate the answer if it helped......Thankyou
Hope it helps.....
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.