Question

In: Computer Science

c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a...

c++ programming

1.1 Class definition
Define a class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data:
 Account holder’s name (string)
 Account number (int)
 Account type (string, check/savings/business)
 Balance (double)
 Interest rate (double) – store interest rate as a decimal number.
 Add appropriate member functions to manipulate an object. Use a static member in the
class to automatically assign account numbers.
1.2 Implement all appropriate member functions of a class.
1.3 Write a program that illustrate how to use your class. Your program should have the following:
 Declare an array of 20 components of type bankAccount to process up to 20 customers.
 void menu() – helps the user to select if the customer is new or if they already exist. Furthermore, it prints the customer’s data or exits the program.
 Use a switch statement which uses the value from menu() as an expression to call the following user-defined functions:
o void addCustomber() – this function enters/adds the customer details. You may
call one mutator function (setter) of a class in this function.
o void processCustomer() – this function calls the search() function. It also calls
and uses subMenu() function as an update and priming read. Furthermore, it uses the switch statement to call the other three class member functions to process the deposit, withdrawal, and print.
o void printCustomersData() – print all information of the customers.
 void submenu() – help the user to select between making a deposit, withdrawal, checking balance or exiting the submenu.
 int search() – search the customer’s details by using the customer’s account number. You may call one accessor function (getter) of a class in this function.
 main() function – this has the switch statement to call addCustomber(), processCustomer() and printCustomersData().
Hint: The listed user-defined functions are not the same as the class member functions. However, the user-defined functions can call the class member functions. The array that stored 20 components should be used as a parameter to access and process the customers’ details. Your program must have data validation to check whether or not there are 20 customers. You may use suitable string functions.

Solutions

Expert Solution

I have created whole program in one file and if you want to separate then separate it and add header in file #include "BankAccount.h" in header section of main() file.

still you have doubt just ping me or like it.

#include <iostream>
using namespace std;
//class BankAccount it has private member name, accountNo,accountType,balance,interestRate;
class BankAccount{
  string name;
  int accountNo;
  string accountType;
  double balance;
  double interestRate;
   public :
   //constructor which initilise the account no starting from 1000 and balance to 0;
   BankAccount()
    {
        assignAcc();
        balance = 0;
        interestRate = 0.09;
    }
    //it assigns the value to 20 customers
   void assignAcc()
   {
       static int x=1000;
       accountNo=x++;
   }
   //it returns the accountNo;
     int getAccNo()
    {
        return accountNo;
    }
    //it returns the balance
    double getbalance(){
        return balance;
    }
    //it returns the 0 1 based on account has customer or not.
    int getaccount(){
        return name.empty()?0:1;
    }
    //assign customer to account.
   void setHolderAcc(string name1,int type){
       name=name1;
       if(type==1)
       accountType="check";
       else if(type==2)
       accountType="saving";
       else if(type==3)
       accountType="business";
   }
   //deposit money to account.
   void deposit(int amount){
       balance+=amount;
   }
   //withdraw money t account
    void withdraw(int amount){
       balance-=amount;
   }
   //print the details of customer.
   void print(){
       cout<<"Account Number: "<<accountNo<<" Name:"<<name<<" Account type: "<<accountType<<" Balance: "<<balance<<endl;
   }
};
//search function search the account by accountNo and return obeject of BankAccount.
BankAccount search(BankAccount bankAccount[]){
    int accountNo;
    BankAccount account;
    cout<<"Enter the account no to search:";
    cin>>accountNo;
    for(int i=0;bankAccount[i].getaccount()!=0;i++){
        if(bankAccount[i].getaccount()==accountNo)
            return bankAccount[i];
    }
    return account;
}
//submenu using switch statement and deposite and withdraw and print based on selection.
void submenu(BankAccount bankAccount){
    int choice,amount;
    cout<<"Enter 1:deposit  2:withdraw  3:print :";
    cin>>choice;
    switch(choice){
        case 1:
        cout<<"Enter the amount to deposit: ";
        cin>>amount;
        bankAccount.deposit(amount);
        cout<<"Now your balance is "<<bankAccount.getbalance()<<endl;
        break;
        case 2:
        cout<<"Enter the amount to withdraw: ";
        cin>>amount;
        if(amount<=bankAccount.getbalance()){
        bankAccount.withdraw(amount);
        cout<<"Now your balance is "<<bankAccount.getbalance()<<endl;
        }
        else 
        cout<<"you don't have enough balance"<<endl;
        break;
        case 3:bankAccount.print();
        break;
    }
    return;
}

//it procedd customer and call the submenu with BankAccount object.
void processCustomer(BankAccount bankAccount[]){
 BankAccount account=search(bankAccount);  
 submenu(account);
}
//it add customer and shows Succesfully added or not.
void addCustomer(BankAccount bankAccount[],int n){
    string name;
    int type;
    int account=bankAccount[n].getAccNo();
     cout<<"\n"<<n+1<<":Enter name: ";
     cin.ignore();
     getline(cin,name);
     cout<<"Enter account type(1=check 2=saving 3=business):";
     cin>>type;
     bankAccount[n].setHolderAcc(name,type);
     cout<<"Account ADDED Succesfully"<<endl;
     cout<<"\n"<<name<<"   account#: "<<account<<endl;
}
//main menu which has option for new customer, exits customer or total print of customer.
int menu(){
    int choice;
    cout<<"Welcome to the Bank Account"<<endl;
    cout<<"1:New Customer 2: Exist Customer 3:print Customers Data 4:exit";
    cin>>choice;
    return choice;
}
//it prints all the customers 
void printCustomersData(BankAccount bankAccount[]){
    for(int i=0;bankAccount[i].getaccount()!=0;i++){
        bankAccount[i].print();
    }
}

//main function has loop which takes n customer added into array 
//and while contuon true which shows main  menu till exit .
int main()
{
   string name;
   int n,type;
   cout<<"Enter the number of account to create: ";
   cin>>n;
   BankAccount bankAccount[20];
   for(int i=0;i<n;i++){
     int account=bankAccount[i].getAccNo();
     cout<<"\n"<<i+1<<":Enter name: ";
     cin.ignore();
     getline(cin,name);
     cout<<"Enter account type(1=check 2=saving 3=business):";
     cin>>type;
     bankAccount[i].setHolderAcc(name,type);
     cout<<"\n"<<name<<"   account#: "<<account<<endl;
   }
   bool flag=true;
   while(flag){
    int choice=menu();
    switch(choice){
        case 1:
        addCustomer(bankAccount,n);
        n++;
        break;
        case 2:processCustomer(bankAccount);
        break;
        case 3:printCustomersData(bankAccount);
        break;
        case 4:flag=false;
    }  
   }
    return 0;
}


Related Solutions

In C++, define the class bankAccount to implement the basic properties of a bank account. An...
In C++, define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 components of type bankAccount to...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
Write the definition of a class, swimmingPool, to implement the properties of a swimming pool. Your...
Write the definition of a class, swimmingPool, to implement the properties of a swimming pool. Your class should have the instance variables to store the length (in feet), width (in feet), depth (in feet), the rate (in gallons per minute) at which the water is filling the pool, and the rate (in gallons per minute) at which the water is draining from the pool. Add appropriate constructors to initialize the instance variables. Also, add member functions to do the following:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is a sub class is derived from the Account class and implements the ITransaction interface. There are two class variables i.e. variables that are shared but all the objects of this class. A short description of the class members is given below: CheckingAccount Class Fields $- COST_PER_TRANSACTION = 0.05 : double $- INTEREST_RATE = 0.005 : double - hasOverdraft: bool Methods + «Constructor» CheckingAccount(balance =...
Programming Language: C# Person Class Fields - password : string Properties + «C# property, setter private»...
Programming Language: C# Person Class Fields - password : string Properties + «C# property, setter private» IsAuthenticated : bool + «C# property, setter absent» SIN : string + «C# property, setter absent» Name : string Methods + «Constructor» Person(name : string, sin : string) + Login(password : string) : void + Logout() : void + ToString() : string Transaction Class Properties + «C# property, setter absent » AccountNumber : string + «C# property, setter absent» Amount : double + «C#...
Here is a C++ class definition for an abstract data type LinkedList of string objects. Implement...
Here is a C++ class definition for an abstract data type LinkedList of string objects. Implement each member function in the class below. Some of the functions we may have already done in the lecture, that's fine, try to do those first without looking at your notes. You may add whatever private data members or private member functions you want to this class. #include #include typedef std::string ItemType; struct Node { ItemType value; Node *next; }; class LinkedList { private:...
Using basic C++( without using <Rectangle.h> ) Write the definition for a class called Rectangle that...
Using basic C++( without using <Rectangle.h> ) Write the definition for a class called Rectangle that has floating point data members length and width. The class has the following member functions: void setlength(float) to set the length data member void setwidth(float) to set the width data member float perimeter() to calculate and return the perimeter of the rectangle float area() to calculate and return the area of the rectangle void show() to display the length and width of the rectangle...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class with public and private members and multiple constructors.  Gain a better understanding of the building and using of classes and objects.  Practice problem solving using OOP. Overview You will implement a date and day of week calculator for the SELECTED calendar year. The calculator repeatedly reads in three numbers from the standard input that are interpreted as month, day of month, days...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT