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;...
Utilize the code from last week Add a default, full, and copy constructor. Also add a...
Utilize the code from last week Add a default, full, and copy constructor. Also add a constructor that allows you to specify only the name of the video game with no high score or times played specified. Adjust your code to demonstrate use of all 4 constructors and output of the resulting objects. #include <iostream> #include <string> #include <iomanip> using namespace std; class VideoGame { private:     string name;     int highScore;     int numOfPlays; public:     VideoGame() {        ...
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();...
How do i stop the loop if no next value in the list and prevent it...
How do i stop the loop if no next value in the list and prevent it from exit the program instead back to main menu. Let say i add food detail then i display it. It will display the detail but it will exit after it. struct food{ int order_id; string food_code,flavor,customer_id; string address,name; int weight,unit_price,qty,contact_number; struct food *next; }; void Foodsystem::Place_Order(){ temp=new food; cout<<endl; cin.ignore(); cout<<"Enter your Name"; getline(cin,temp->name); cout<<"enter contact number::"; cin>>temp->contact_number; cin.ignore(); cout<<"enter address::"; getline(cin,temp->address); cout<<"customer_id::"; getline(cin,temp->customer_id);...
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...
Write a program that reads a string and outputs the number of lowercase vowels in the...
Write a program that reads a string and outputs the number of lowercase vowels in the string. Your program must contain a function with a parameter of a char variable that returns an int. The function will return a 1 if the char being passed in is a lowercase vowel, and a 0 for any other character. The output for your main program should be: There are XXXX lowercase vowels in string yyyyyyyyyyyyyyyyyyyyyy Where XXXX is the count of lowercase...
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...
15.4 Zip code and population (class templates) Complete the TODOs in StatePair.h and main.cpp. StatePair.h Define...
15.4 Zip code and population (class templates) Complete the TODOs in StatePair.h and main.cpp. StatePair.h Define a class StatePair with two template types (T1 and T2), and constructor, mutators, accessors, and PrintInfo() member functions which will work correctly with main.cpp. Note, the three vectors (shown below) have been pre-filled with StatePair data in main() and do not require modification. vector<StatePair <int, string>> zipCodeState: ZIP code - state abbreviation pairs vector<StatePair<string, string>> abbrevState: state abbreviation - state name pairs vector<StatePair<string, int>>...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT