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

C++ Programming: Program Design Including Data Structures, 7th Edition Chapter 1

ID: 665453 • Letter: C

Question

C++ Programming: Program Design Including Data Structures, 7th Edition

Chapter 12

PE #5

C++, using Visual Studio, please label each file

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 ecking

Explanation / Answer

//***************************************************************
//        HEADER FILEs NEEDED FOR Banking Application
//****************************************************************

#include<iostream.h>
#include<fstream.h>
#include<cctype.h>
#include<iomanip.h>
//using namespace std;

//***************************************************************
//                   CLASS USED IN PROJECT
//****************************************************************


class account
{
   int AccountNumber;
   char AccountOwnerName[50]; // AccountOwnerName of the account owner
   int Deposit;    // account balance
   char type;   // account type
public:
   void openAccount();   //function to get data from user
   void retrieveAccDetails(); // will return accOwnerName, AccNumber, AccBalance,
   void DisplayAccount() const;   //function to show data on screen
   void Change();   //function to add new data
   void Deposit(int);   //function to make deposit = accept amount and add to balance amount
   void WithDrawal(int);   //function to accept amount and subtract from balance amount
   void monthlyStatements();   // account Statement every month
   void report() const;   //function to show data in tabular format
   int retAccountNumber() const;   //function to return account number
   int retDeposit() const;   //function to return balance amount
   char rettype() const;   //function to return type of account
};         //class ends here

void account::openAccount()
{
   cout<<" Enter The account No. :";
   cin>>AccountNumber;
   cout<<" Enter The AccountOwnerName of The account Holder : ";
   cin.ignore();
   cin.getline(AccountOwnerName,50);
   cout<<" Enter Type of The account (C/S) : ";
   cin>>type;
   type=toupper(type);
   cout<<" Input the starting value (>=500 for Saving and >=1000 for checking ) : ";
   cin>>deposit;
   cout<<" Account Created..";
}

void account::DisplayAccount() const
{
   cout<<" Account No. : "<<AccountNumber;
   cout<<" Account Holder AccountOwnerName : ";
   cout<<AccountOwnerName;
   cout<<" Type of Account : "<<type;
   cout<<" Balance amount : "<<deposit;
}

void account::retrieveAccDetails()
{
   cout<<" Account No. : "<<AccountNumber;
   cout<<" Account Holder AccountOwnerName : ";
   cout<<AccountOwnerName;
   cout<<" Type of Account : "<<type;
   cout<<" Balance amount : "<<deposit;
}
void account::monthlyStatements()
{
   cout << " Bank Account statement ";
   cout << " Bank of America, 11/22, 42nd street, New York, USA"
   cout << " Date:    Time:       ";
   cout << " Account Number: " << AccountNumber ;
   cout << " Date Description      Debit      Credit      Balance ";
   cout << "    Initial Deposit           10000.00      10000.00+"
   cout << "    Withdraw           500                 9500.00+"
   cout << "    Cash Deposit                  200          9700.00+"
}

void account::Change()
{
   cout<<" Account No. : "<<AccountNumber;
   cout<<" Change Account Holder AccountOwnerName : ";
   cin.ignore();
   cin.getline(AccountOwnerName,50);
   cout<<" Change Type of Account : ";
   cin>>type;
   type=toupper(type);
   cout<<" Change Balance amount : ";
   cin>>deposit;
}

  
void account::Deposit(int x)
{
   deposit+=x;
}
  
void account::WithDrawal(int x)
{
   deposit-=x;
}
  
void account::report() const
{
   cout<<AccountNumber<<setw(10)<<" "<<AccountOwnerName<<setw(10)<<" "<<type<<setw(6)<<deposit<<endl;
}

  
int account::retAccountNumber() const
{
   return AccountNumber;
}

int account::retdeposit() const
{
   return deposit;
}

char account::rettype() const
{
   return type;
}


//***************************************************************
//       function declaration
//****************************************************************
void write_account();   //function to write record in binary file
void display_sp(int);   //function to display account details given by user
void Change_account(int);   //function to Change record of file
void delete_account(int);   //function to delete record of file
void display_all();       //function to display all account details
void deposit_withWithDrawal(int, int); // function to desposit/withWithDrawal amount for given account
void intro();   //introductory screen function

//***************************************************************
//       THE MAIN FUNCTION OF PROGRAM
//****************************************************************


int main()
{
   char ch;
   int num;
   intro();
   do
   {
       system("cls");
       cout<<" MAIN MENU";
       cout<<" 01. NEW ACCOUNT";
       cout<<" 02. deposit AMOUNT";
       cout<<" 03. WITHWithDrawal AMOUNT";
       cout<<" 04. BALANCE ENQUIRY";
       cout<<" 05. ALL ACCOUNT HOLDER LIST";
       cout<<" 06. CLOSE AN ACCOUNT";
       cout<<" 07. Change AN ACCOUNT";
       cout<<" 08. EXIT";
       cout<<" Select Your Option (1-8) ";
       cin>>ch;
       system("cls");
       switch(ch)
       {
       case '1':
           write_account();
           break;
       case '2':
           cout<<" Enter The account No. : "; cin>>num;
           deposit_withWithDrawal(num, 1);
           break;
       case '3':
           cout<<" Enter The account No. : "; cin>>num;
           deposit_withWithDrawal(num, 2);
           break;
       case '4':
           cout<<" Enter The account No. : "; cin>>num;
           display_sp(num);
           break;
       case '5':
           display_all();
           break;
       case '6':
           cout<<" Enter The account No. : "; cin>>num;
           delete_account(num);
           break;
       case '7':
           cout<<" Enter The account No. : "; cin>>num;
           Change_account(num);
           break;
       case '8':
           cout<<" Thanks for using bank managemnt system";
           break;
       default :cout<<"";
       }
       cin.ignore();
       cin.get();
   }while(ch!='8');
   return 0;
}


//***************************************************************
//       function to write in file
//****************************************************************

void write_account()
{
   account ac;
   ofstream outFile;
   outFile.open("account.dat",ios::binary|ios::app);
   ac.openAccount();
   outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
   outFile.close();
}

//***************************************************************
//       function to read specific record from file
//****************************************************************

void display_sp(int n)
{
   account ac;
   bool flag=false;
   ifstream inFile;
   inFile.open("account.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(account)))
   {
       if(ac.retAccountNumber()==n)
       {
           ac.DisplayAccount();
           flag=true;
       }
   }
   inFile.close();
   if(flag==false)
       cout<<" Account number does not exist";
}


//***************************************************************
//       function to ALTER record from the file
//****************************************************************

void Change_account(int n)
{
   bool found=false;
   account ac;
   fstream File;
   File.open("account.dat",ios::binary|ios::in|ios::out);
   if(!File)
   {
       cout<<"uNABLE TO OPEN File !! Press a Key...";
       return;
   }
   while(!File.eof() && found==false)
   {
       File.read(reinterpret_cast<char *> (&ac), sizeof(account));
       if(ac.retAccountNumber()==n)
       {
           ac.DisplayAccount();
           cout<<" Enter The New Details of account"<<endl;
           ac.Change();
           int pos=(-1)*static_cast<int>(sizeof(account));
           File.seekp(pos,ios::cur);
           File.write(reinterpret_cast<char *> (&ac), sizeof(account));
           cout<<" Record Updated";
           found=true;
          }
   }
   File.close();
   if(found==false)
       cout<<" Record Not Found ";
}

//***************************************************************
//       function to delete record of file
//****************************************************************


void delete_account(int n)
{
   account ac;
   ifstream inFile;
   ofstream outFile;
   inFile.open("account.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(account)))
   {
       if(ac.retAccountNumber()!=n)
       {
           outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
       }
   }
   inFile.close();
   outFile.close();
   remove("account.dat");
   reAccountOwnerName("Temp.dat","account.dat");
   cout<<" Record Deleted ..";
}

//***************************************************************
//       function to display all accounts deposit list
//****************************************************************

void display_all()
{
   account ac;
   ifstream inFile;
   inFile.open("account.dat",ios::binary);
   if(!inFile)
   {
       cout<<"File could not be open !! Press any Key...";
       return;
   }
   cout<<" ACCOUNT HOLDER LIST ";
   cout<<"==================================================== ";
   cout<<"A/c no.      AccountOwnerName           Type Balance ";
   cout<<"==================================================== ";
   while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
   {
       ac.report();
   }
   inFile.close();
}

//***************************************************************
//       function for depositing and withWithDrawal of amounts
//****************************************************************

void deposit_withWithDrawal(int n, int option)
{
   int amt;
   bool found=false;
   account ac;
   fstream File;
   File.open("account.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(account));
       if(ac.retAccountNumber()==n)
       {
           ac.DisplayAccount();
           if(option==1)
           {
               cout<<" TO depositE AMOUNT ";
               cout<<" Enter The amount to be deposited";
               cin>>amt;
               ac.Deposit(amt);
           }
           if(option==2)
           {
               cout<<" TO WITHWithDrawal AMOUNT ";
               cout<<" Enter The amount to be withWithDrawal";
               cin>>amt;
               int bal=ac.retdeposit()-amt;
               if((bal<500 && ac.rettype()=='S') || (bal<1000 && ac.rettype()=='C'))
                   cout<<"Insufficience balance";
               else
                   ac.WithDrawal(amt);
           }
           int pos=(-1)*static_cast<int>(sizeof(ac));
           File.seekp(pos,ios::cur);
           File.write(reinterpret_cast<char *> (&ac), sizeof(account));
           cout<<" Record Updated";
           found=true;
           }
         }
   File.close();
   if(found==false)
       cout<<" Record Not Found ";
}


void intro()
{
   cout<<"    BANKING MANAGEMENT SYSTEM";
   cout<< endl;
   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