Question

a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...

a. Define the class bankAccount to store a bank customer’s account
number and balance. Suppose that account number is of type int, and
balance is of type double. Your class should, at least, provide the
following operations: set the account number, retrieve the account
number, retrieve the balance, deposit and withdraw money, and print
account information. Add appropriate constructors.
b. Every bank offers a checking account. Derive the class
checkingAccount from the class bankAccount (designed in part
(a)). This class inherits members to store the account number and the
balance from the base class. A customer with a checking account typically
receives interest, maintains a minimum balance, and pays service charges if
the balance falls below the minimum balance. Add member variables to
store this additional information. In addition to the operations inherited
from the base class, this class should provide the following operations: set
interest rate, retrieve interest rate, set minimum balance, retrieve minimum
balance, set service charges, retrieve service charges, post interest, verify if
the balance is less than the minimum balance, write a check, withdraw
(override the method of the base class), and print account information. Add
appropriate constructors.
c. Every bank offers a savings account. Derive the class
savingsAccount from the class bankAccount (designed in part
(a)). This class inherits members to store the account number and
the balance from the base class. A customer with a savings account
typically receives interest, makes deposits, and withdraws money. In
addition to the operations inherited from the base class, this class
should provide the following operations: set interest rate, retrieve
interest rate, post interest, withdraw (override the method of the base
class), and print account information. Add appropriate constructors.
d. Write a program to test your classes designed in parts (b) and (c).

Here is what I have so far:


#include <iostream>
#include <string>
using namespace std;
class bankAccount{ // bank class
private: //private data members
string holderName;
string accountType;
int accountNumber;
float balance;
float interestRate;
float round(float valuee) // private function to round off value
{
    float num = (int)(valuee * 100 + .5);
    return (float)num/ 100;
}
public:
bankAccount(){ //default cnstructor
accountNumber=0;
balance=0.00;
interestRate=0.00;
}
// mutator function of the data members
void setHolderName(string h){
holderName=h;
}
void setAccountType(string a){
accountType=a;
}
void setAccountNumber(int n){
accountNumber=n;
}
void setBalance(float bal){
round(bal);
balance=bal;
}
void setIntersetRate(float rat){
interestRate =rat;
}
// accessor function for the data members (private)
string getHolderName(){
return holderName;
}
string getAccountType(){
return accountType;
}
int getAccountNumber(){
return accountNumber;
}
float getBalance(){
return balance;
}
float getInterestRate(){
return interestRate;
}
};
void menu(){ // menu to display functions
cout<<endl;
cout<<"1: Enter 1 to add a new customer. "<<endl;
cout<<"2: Enter 2 for an existing customer."<<endl;
cout<<"3: Enter 3 to print customers data. "<<endl;
cout<<"9: Enter 9 to exit the program. "<<endl;
}
int main() {
string name;
string type;
    int num = 0;
float balance;
float rate;
bankAccount customer[10]; // array of size 10
int count=0; // will let us know the record and will only show the record that have data stored
int choice;
while(1){ // until user presses 9
menu();
cin>>choice;
if(choice==1){ // insert data
num=num % 10000+100; // get random account number
cout<<"Enter customer's name: ";
cin.ignore();
getline(cin,name);
cout<<"Enter account type (checking/savings): ";
getline(cin,type);
cout<<"Enter amount to be deposited to open account: ";
cin>>balance;
cout<<"Enter interest rate (as a percent): ";
cin>>rate;
// store data into the array
customer[count].setHolderName(name);
customer[count].setAccountType(type);
customer[count].setAccountNumber(num);
customer[count].setBalance(balance);
customer[count].setIntersetRate(rate);
count++;
}
else if(choice==2){
// search function for existing users to update and view record
cout<<"Enter Account Name to update record: ";
cin>>name;
for(int i=0;i<count;i++){
if(name==customer[i].getHolderName()){
    cout<<"---------- RECORD FOUND ---------"<<endl;
    cout<<"Account Number: "<<customer[i].getAccountNumber()<<endl;
  
    cout<<"Account Holder Name: "<<customer[i].getHolderName()<<endl;
  
    cout<<"Account Type: "<<customer[i].getAccountType()<<endl;
  
    cout<<"Account Balance: "<<customer[i].getBalance()<<endl;
  
    cout<<"Account Interest Rate: "<<customer[i].getInterestRate()<<endl;

    cout<<"--------------------------"<<endl;
  
cout<<"Enter data to update "<<endl<<endl;
cout<<"Enter customer's name: ";
cin.ignore();
getline(cin,name);
cout<<"Enter account type (checking/savings): ";
getline(cin,type);
cout<<"Enter amount to be deposited to open account: ";
cin>>balance;
cout<<"Enter interest rate (as a percent): ";
cin>>rate;
customer[i].setHolderName(name);
customer[i].setAccountType(type);
customer[i].setAccountNumber(num);
customer[i].setBalance(balance);
customer[i].setIntersetRate(rate);
}

}
}
else if(choice==3){

//.. view all record of bank
cout<<endl<<"*********** ACCOUNT RECORDS ***********"<<endl;
for(int i=0;i<count;i++){
cout<<endl<<"-------------------------------"<<endl;
cout<<"Account Number: "<<customer[i].getAccountNumber()<<endl;
  
    cout<<"Account Holder Name: "<<customer[i].getHolderName()<<endl;
  
    cout<<"Account Type: "<<customer[i].getAccountType()<<endl;
  
    cout<<"Account Balance: $"<<customer[i].getBalance()<<endl;
  
    cout<<"Account Interest Rate: "<<customer[i].getInterestRate()<<"%"<<endl;
}
}
else if(choice==9){ //.. exit function
return 0;
}
else{
cout<<"Invalid choice"<<endl;
    break;
}
}
}

Homework Answers

Answer #1

Main.cpp

#include <iostream>
using namespace std;

class BankAccount
   {
       public:
       int accountNumber;
       double Balance;

public:
   BankAccount(int Accno,double Bal)
   {
       accountNumber = Accno;
       Balance = Bal;
   }
   BankAccount()
   {
   }
public:
   double getBal()
   {
       return(Balance);
   }
   int getAccNo()
   {
       return(accountNumber);
   }
   void setBal(double amount)
   {
       Balance = amount;
   }
   void setAccNo(int Accno)
   {
       accountNumber = Accno;
   }
   void virtual showAccNo()
   {
           cout << " ---------------------------------" << endl;
           cout << " ||        Account Info           " << endl;
           cout << " ---------------------------------" << endl;
           cout << " || Account Number :" << accountNumber << endl;
           cout << " || Account Balance:" << Balance << endl;
           cout << " ---------------------------------" << endl;
           cout << endl;
   }

   double virtual depAmnt(double dAmnt)
   {
       Balance = Balance + dAmnt;
       return(Balance);
   }

   double virtual wdrawAmnt(double wAmnt)
   {
       Balance = Balance - wAmnt;
       return(Balance);
   }
};

class CheckingAccount : BankAccount
{
   double Intrst;
   double minBal;
   double serChge;

public:
   CheckingAccount(int pAccno,double pAmnt,double pIntrst):BankAccount(pAccno,pAmnt)
   {
       Intrst = pIntrst;
       minBal = 500;//By default
   }

   void setIntRate(double intRate)
   {
       Intrst = intRate;
   }

   double retIntRate()
   {
       return(Intrst);
   }

   void setMinBal(double mBal)
   {
       minBal = mBal;
   }

   double retMinBal()
   {
       return(minBal);
   }

   void setSerChge(double sCharge)
   {
       serChge = sCharge;
   }

   double retSerChge()
   {
       return(serChge);
   }

   double depAmnt(double dAmnt)
   {
       Balance = Balance + dAmnt;
       return(Balance);
   }

   double wdrawAmnt(double wAmnt)
   {
       if(wAmnt <= Balance)
           Balance = Balance - wAmnt;
       else
           cout << "You have insufficient funds!" << endl;
       return(Balance);
   }

   void showAccNo()
   {
           cout << " ---------------------------------" << endl;
           cout << " ||        Account Info           " << endl;
           cout << " ---------------------------------" << endl;
           cout << " || Account Number :" << accountNumber << endl;
           cout << " || Account Balance:" << Balance << endl;
           cout << " ---------------------------------" << endl;
           cout << endl;
   }
};

class SavingAccount:BankAccount
   {
       double minBal;
   public:
       SavingAccount(int pAccno,double pAmnt):BankAccount(pAccno,pAmnt)
       {
           minBal = 500;
       }
       double depAmnt(double dAmnt)
       {
           Balance = Balance + dAmnt;
           return(Balance);
       }
       double wdrawAmnt(double wAmnt)
       {
           if(wAmnt <= Balance)
               Balance = Balance - wAmnt;
           else
               cout << "You have in sufficient funds!" << endl;
           return(Balance);
       }
       void setMinBal(double mBal)
       {
           minBal = mBal;
       }
       void showAccNo()
       {
           cout << endl;
           cout << " ---------------------------------" << endl;
           cout << " ||        Account Info           " << endl;
           cout << " ---------------------------------" << endl;
           cout << " || Account Number :" << accountNumber << endl;
           cout << " || Account Balance:" << Balance << endl;
           cout << " ---------------------------------" << endl;
           cout << endl;
       }
};

int main()
   {
       double amount;
       int choice;
       do
       {
           cout << endl;
           cout << "       Create an Account      " << endl;
           cout << " *****************************" << endl;
           cout << " ** 1 - Checking Account   **" << endl;
           cout << " ** 2 - Saving Account     **" << endl;
           cout << " ** 3 - Exit               **" << endl;
           cout << " *****************************" << endl;
           cin >> choice;
           cout << endl;
          
           if(choice==1)
           {
               cout << "Enter account number: " << endl;
               int Accno;
               cin >> Accno;
               cout << "Enter opening balance: " << endl;
               double newBal;
               cin >> newBal;
               double intRate;
               cout << "Enter interest rate: " << endl;
               cin >> intRate;
               CheckingAccount obj(Accno,newBal,intRate);
               int accChoice;
               do
               {
                   cout << endl;
                   cout << " *************************" << endl;
                   cout << " ** 1 - Deposit        **" << endl;
                   cout << " ** 2 - Withdraw       **" << endl;
                   cout << " ** 3 - Account Info   **" << endl;
                   cout << " ** 4 - Exit           **" << endl;
                   cout << " *************************" << endl;
                   cin >> accChoice;
                   cout << endl;
                   switch(accChoice)
                   {
                   case 1:
                       cout << "Enter amount: " << endl;
                       cin >> amount;
                       double dAmnt;
                       dAmnt = obj.depAmnt(amount);
                       cout << "Available balance: " << dAmnt << endl;
                       break;
                   case 2:
                       cout << "Enter amount: " << endl;
                       cin >> amount;
                       double wAmnt;
                       wAmnt = obj.wdrawAmnt(amount);
                       cout << "Available balance: "<< wAmnt << endl;
                       break;
                   case 3:
                       obj.showAccNo();
                       break;
                   }
               }

               while(accChoice!=4);
           }
           else if(choice==2)
           {
               cout << "Enter account number:" << endl;
               int pAccno;
               cin >> pAccno;
               cout << "Enter opening balance:" << endl;
               double pnewBal;
               cin >> pnewBal;
               double _irate;
               cout << "Enter interest rate:" << endl;
               cin >> _irate;
               SavingAccount sObj(pAccno,pnewBal);
               int pChoice;
               do
               {
                   cout << endl;
                   cout << " *************************" << endl;
                   cout << " ** 1 - Deposit        **" << endl;
                   cout << " ** 2 - Withdraw       **" << endl;
                   cout << " ** 3 - Account Info   **" << endl;
                   cout << " ** 4 - Exit           **" << endl;
                   cout << " *************************" << endl;
                   cin>>pChoice;
                   cout << endl;
                   switch(pChoice)
                   {
                   case 1:
                       cout << "Enter amount:" << endl;
                       cin >> amount;
                       double _dAmnt;
                       _dAmnt = sObj.depAmnt(amount);
                       cout << "Available balance: " << _dAmnt;
                       break;
                   case 2:
                       cout << "Enter amount:" << endl;
                       cin >> amount;
                       double _wamount;
                       _wamount = sObj.wdrawAmnt(amount);
                       cout << "Available balance: " << _wamount;
                       break;
                   case 3:
                       sObj.showAccNo();
                       break;
                   case 4:
                       break;
                   default:
                       cout << "Invalid choice";
                       break;
                   }
               }
               while(pChoice!=4);
           }
       }
       while(choice!=3);
}

Output:

Note: I hope the above provided solution is according to your description. If in case you find an error in the structure or in the method then please do let me know through comments. I'll try to resolve your issues. Thank You!!!

ThumbsUP!!!! Have a nice day...

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is up to you as long as you implement some form of inheritance. Below is my code however the credit and the actual menu isn't working. Can i get some help on getting the menu to work properly. // BankAccount.h #ifndef ACCOUNT_H #define ACCOUNT_H #include <string> #include <iostream> using namespace std; class BankAccount { protected : int noOfWithdrawls; private: // Declaring variables    float balance;...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....
How to stop the program from exiting after display detail. When there is food detail, it...
How to stop the program from exiting after display detail. When there is food detail, it will display and exit the program. What can i do to make it not exit the program and back to main menu. #include <iostream> #include <iomanip> #include<string.h> using namespace std; struct food{ int order_id; string food_code,flavor,customer_id; string address,name; int weight,unit_price,qty,contact_number; struct food *next; };    class Foodsystem{ food *head,*temp,*temp2,*end; static int id;    public: Foodsystem(){ head=NULL;end=NULL;} void Place_Order(); void View_food_details(); void Modify_food_details(); void Delete_food_details();...
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
In this assignment, you’ll make an inventory system for a store’s items, including produce and books....
In this assignment, you’ll make an inventory system for a store’s items, including produce and books. The starter program is an inventory system for only produce. 1. Include the price of an item by adding to the Item class the protected data member int priceInDollars that stores the price in dollars of an individual item. Write a public function SetPrice with a single int parameter prcInDllrs and returns nothing. SetPrice assigns the value of prcInDllrs to priceInDollars. Modify the AddItemToInventory...
No matter what I do I cannot get this code to compile. I am using Visual...
No matter what I do I cannot get this code to compile. I am using Visual Studio 2015. Please help me because I must be doing something wrong. Here is the code just get it to compile please. Please provide a screenshot of the compiled code because I keep getting responses with just code and it still has errors when I copy it into VS 2015: #include <iostream> #include <conio.h> #include <stdio.h> #include <vector> using namespace std; class addressbook {...
Need to get the following output by Editing ChekingAccount.h ,ChekingAccount.cpp CheckingAccount Derived class CheckingAccount that inherits...
Need to get the following output by Editing ChekingAccount.h ,ChekingAccount.cpp CheckingAccount Derived class CheckingAccount that inherits from base class Account and include an additional data member of type double that represents the fee charged per transaction (transactionFee). Write Checking- Account’s constructor that receives the initial balance, as well as a parameter indicating a transaction fee amount. If transaction fee is less than zero, the transactionFee will be set to zero. Write the chargeFee member function that updates the balance by...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are pointers or constant pointers. Directions: Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS = 3; // may only be declared within the main function string students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Be sure to compile using g++ -std=c++11 helpWithGradesPtr.cpp Write a C++ program to run a menu-driven program with the...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity  ...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity   Code   Description   Project   File   Line   Suppression State Warning   C6385   Reading invalid data from 'DynamicStack': the readable size is '(unsigned int)*28+4' bytes, but '56' bytes may be read.   Here is the C++ code were I'm having the warning. // Sstack.cpp #include "SStack.h" // Constructor SStack::SStack(int cap) : Capacity(cap), used(0) {    DynamicStack = new string[Capacity]; } // Copy Constructor SStack::SStack(const SStack& s) : Capacity(s.Capacity), used(s.used)...