Please distinguish between the h and cpp file create a fully
Please distinguish between the .h and .cpp file, create a fully working c++ program using the diagram provided.
Section 1: Homework Objectives
1. Given a class UML, learn to write a C++ class declaration.
2. Learn how to define/call constructor, accessor, mutator or toString( )
Section 2: Background
In this homework, according to the given UML class diagram, you’re required to design a
BankAccount class. You are also required to write a driver’s program to test it.
Section 3: Program description
3.1 Introduction
According to the following UML diagram, design a BankAccount class.
BankAccount
-id: string = \"?\"
-balance: double = 0.0
-address: string = \"?\"
+BankAccount()
+BankAccount(string, double, string)
+getID(): string
+getBalance(): double
+getAddress(): string
+setID(string): void
+deposit(double): bool
+withdraw(double): bool
+updateAddress(string):void
+toString(): string
+addInterest(): void
+equals(BankAccount): bool
Member variables and member functions\' description
Member
Variable
Data Type
Description
id
string
This represents a bank account\'s unique ID, such as \"123-456-
789\"
balance
double
This is the account balance.
address
string
This represents a bank account customer\'s mailing address, such as \"12345 Via Linda Rd. Phoenix, AZ 85048\"
Member Function
Function Description
BankAccount()
This is the default constructor and it should initialize all member varible by the initial value defined inside the UML. For example, id should be initialized to \"?\" etc.
BankAccount(string newID, double newBal, string newAddress)
This is the overloadded constructor. It takes three input parameters and initialize the three member variables accordingly with the three input parameters.
string getID()
This is the accessor for member variable id
double getBalance()
This is the accessor for member variable balance
string getAddress()
This is the accessor for member variable address
void setID(string newID)
This is the mutator for member variable id. It takes a new id as input and change the member variable id accordingly
bool deposit(double amount)
This is a mutator for member variable balance. It takes an amount as input parameter, if the amount of deposit is negative, the balance will not be changed and the function should return false; otherwise, the deposited amount (parameter value) will be added to the balance and the function returns true.
bool withdraw(double amount)
This is a mutator for member variable balance. It takes an amount as input parameter, if the balance is less than the withdraw amount (parameter value) or the withdraw amount is less than zero, the function should return false, otherwise subtract the balance by withdraw amount and return true.
void updateAddress(string newAddress)
This is a mutator for member variable address. In case the bank account\'s customer want to change his/her address, we will use this function.
string toString()
The toString function will display an bank account info. in the following format:
\ Account ID:\\t\\t id
2
\ Account Balance:\\t balance
\ Account Address:\\t address\ \
void addInterest()
If balance is between [0, 1000], interest rate is 1.5%; If balance is at least 1000 and up to (and including)
5000, interest rate is 2.5%;
The interest rate is 3.5% if balance is over 5000.
For all above cases, you need to compute the interests, then add it to balance.
bool equals(BankAccount anotherAct)
The function compares the id and address and returns true if this BankAccount object has the same id and address as the other account (the parameter variable which is another BankAccount object). Otherwise it returns false.
(Note: You should NOT use == to compare two strings since they\'re reference variables and will always return false. Instead you should use the
compare() function in string class to compare them, for example to check two string objects str1 and str2
are same strings or not, we wrote:
if (str1.compare(str2) == 0)
cout << \"Same\" << endl;
else
cout << \"Different\" << endl;
3.2 Programming Instructions
1. First, you will need to create two files to represent this class:
BankAccount.h : this is the header file which declares the class
BankAccount.cpp : is the class implementation file which should include all function\'s implementation
2. Second, you also need to create Assignment6.cpp file that contains a main function. Your main program will do the following: Declare and instantiate a BankAccount object. Get the name, balance, and the password from standard input and display the following menu to the user:
Choose an Action
------------------- D Deposit
W Withdraw
S Show Account Info. I Add the Interest
U Update Address
C Check the Account
? Display the Menu
Q Exit Program
Then the program should ask “Please enter a command: ”. A user will type in a character of their menu choice. Note: user might enter both upper case or lower case letters. You can use toupper( ) function in <cctype> directive to convert them all to upper case letters. Please find below for
each command\'s description
Command
Command Description
\'D\'
Ask a user to enter a deposit amount and call the deposit( ) function in BankAccount.cpp class. If the deposit( ) function return true (deposit amount is not negative), showing, for example, the following message on screen:
You deposit $ 650.70\
Your account\'s new balance is: 1051.20\ \
If the deposit( ) function return false (the deposit amount is negative), showing the following message on screen:
\ You input negative deposit amount. Deposit failed!\
\'W\'
Ask a user to enter a withdrawal amount, and call the withdraw( )
function in BankAccount,cpp class.If the withdraw( ) function return true, showing, for example, the following message on screen:
You withdraw $ 500.00\
Your account\'s new balance is: 400.50\ \
If the withdraw( ) function return false (no enough fund to withdraw), showing the following message on screen:
\ You don\'t have enough fund inside your account, withdraw failed\
\'S\'
This will call the toString( ) function and print the accout info. on screen.
\'I\'
This will call the addInterest() function and show the following message on screen:
\ Interests added\
\'U\'
Ask user to enter his/her new address, then call updateAddress( ) fucntion to change his/her address.
\'C\'
Ask a user to enter an id and address, and set these values to the second BankAccount object that you will need to create. Then call the equals( ) function with these two BankAccount objects (the first one you created and this second one) to check if they have the same id and the address. If they are same, then call toString() function to print out the first BankAccount object info. on screen. Otherwise print the following
message on screen:
\ Sorry we cannot access your account!\
\'?\'
Display the menu again. Please create the following displayMenu()
function in Assignment6.cpp and call it from the main function.
void displayMenu()
\'Q\'
Quit the program and exit.
3.3 Functions in Assignment6.cpp file
In Assignment6.cpp, besides the main( ) function, you\'re required to design at least the following functions inside! Feel free to design other functions whenever you feel necessary.
void getInitialBankInfo(string& ID, double& initialBalance, string& initialAddress );
void displayMenu();
See the following pseudocode for Assignment6.cpp for your reference (for your reference only!
feel free to create your own structure of codes)
Main Function
declare varibles id, address and initialBalance
Call getInitialBankInfo() function to get value for id,
address and initialBalance
Call contructor to create a BankAccount object, named for example, myAccount
Call displayMenu() Function
Do-While user does not enter \'Q\' Switch (based on user input)
Case \'D\': Ask user for deposit amount
Call deposit() on myAccount
break;
Case \'W\': Ask user for withdraw amount
Call withdraw() on myAccount
break;
Case \'S\': Call toString() on myAccount
break;
Case \'I\': Call addInterest() on myAccount
break;
Case \'U\': Ask user for new address
Call updateAddress() on myAccount break;
Case \'C\': Ask user for the second bank account\'s id and address
Create a second BankAccount object
Call equals() on myAccount
break;
Case \'?\': Call displayMenu() function break;
default: Show \"\ Unknown Command\ \" on screen
break;
End Switch
End Do-While
End of Main Function
| Member Variable | Data Type | Description | 
| id | string | This represents a bank account\'s unique ID, such as \"123-456- 789\" | 
| balance | double | This is the account balance. | 
| address | string | This represents a bank account customer\'s mailing address, such as \"12345 Via Linda Rd. Phoenix, AZ 85048\" | 
Solution
//BankAccount.h
 //header file of BankAccount
 #ifndef BANK_ACCOUNT_H
 #define BANK_ACCOUNT_H
 #include<iostream>
 #include<string>
 using namespace std;
 class BankAccount
 {
 private:
    string id;
    double balance;
    string address;
public:
    //method declartions of BankAccount class
    BankAccount();
    BankAccount(string, double, string);
   string getID();
    double getBalance();
    string getAddress();
   void setID(string);
    bool deposit(double);
    bool withdraw(double);
    void updateAddress(string);
   string toString();
    void addInterest();
    bool equals(BankAccount);
 };
 #endif BANK_ACCOUNT_H
--------------------------------------------------------------------------------
//BankAccount.cpp
 //header files
 #include<iostream>
 #include<sstream>
 //include BankAccount.h
 #include \"BankAccount.h\"
 using namespace std;
 //default constructor
 BankAccount::BankAccount()
 {
    id=\"?\";
    balance=0;
    address=\"?\";
 }
 //parameterized construcotr
 BankAccount::BankAccount(string id, double balance, string address)
 {
    this->id=id;
    this->balance=balance;
    this->address=address;
 }
string BankAccount::getID()
 {
    return id;
 }
 double BankAccount::getBalance()
 {
    return balance;
 }
 string BankAccount::getAddress()
 {
    return address;
 }
void BankAccount::setID(string id)
 {
    this->id=id;
 }
 bool BankAccount::deposit(double amt)
 {
    if(amt>0)
    {
        balance=balance+amt;
        return true;
    }
    else
        return false;
 }
 bool BankAccount::withdraw(double amt)
 {
    if(balance>amt)
    {
        balance=balance-amt;
        return true;
    }
    else
        return false;
 }
 void BankAccount::updateAddress(string address)
 {
    this->address=address;
 }
string BankAccount::toString()
 {
    stringstream ss;
    ss<<\"\ Account ID: \"<<id
        <<\"\ Balance :\"<<balance
        <<\"\ Address:\"<<address<<endl;
return ss.str();
}
 //add interest to balance
 void BankAccount::addInterest()
 {
   
    double rate=0;
   if(balance>0 && balance<1000)
        rate=0.15;
    else if(balance>=10000 && balance<=5000)
        rate=0.25;
    else if(balance>5000)
        rate=0.35;
double intamt=balance*rate;
balance=balance+intamt;
}
 //Returns true if two bank accounts are same
 bool BankAccount::equals(BankAccount ba)
 {
    return id==ba.getID() &&
        balance==ba.getBalance() &&
        address.compare(address)==0;
       
 }
--------------------------------------------------------------------------------
//BankAccount test program
 //main.c
 #include<iostream>
 #include \"BankAccount.h\"
 using namespace std;
 char menu();
 void getInitialBankInfo(string id, double &bal, string address);
 void displayMenu();
 int main()
 {
   string id;
    string address;
    double initialBalance;
   getInitialBankInfo(id, initialBalance,address);
   
    //creat a bank account object
    BankAccount bank(id, initialBalance,address);
    bool repeat=true;
    while(repeat)
    {
        char ch=menu();
        switch(ch)
        {
        case \'D\':
            double depositamt;
            cout<<\"Enter deposit amount : \";
            cin>>depositamt;
            if(bank.deposit(depositamt))
            {
                cout<<\"You deposit $ \"<<depositamt<<
                    \"\ Your account\'s new balance is: \"<<
                    bank.getBalance()<<\"\ \ \";
            }
            else
                cout<<\"\ You input negative deposit amount. Deposit failed!\ \";
            break;
        case \'W\':
            double withdrawamt;
            cout<<\"Enter withdraw amount : \";
            cin>>withdrawamt;
            if(bank.withdraw(withdrawamt))
            {
                cout<<\"You withdraw $ \"<<depositamt<<
                    \"\ Your account\'s new balance is: \"<<
                    bank.getBalance()<<\"\ \ \";
            }
            else
                cout<<\"\ You don\'t have enough fund inside your account, withdraw failed\ \";
            break;
        case \'S\':
            cout<<bank.toString()<<endl;
            break;
        case \'I\':
            cout<<\"\ Interests added\ \"<<endl;
            break;
        case \'U\':
            cout<<\"Enter new address : \";
            cin>>address;
            bank.updateAddress(address);
            break;
       case \'C\':
            {
            getInitialBankInfo(id, initialBalance,address);
            BankAccount otherBank(id,initialBalance,address);
           if(bank.equals(otherBank))
                cout<<\"Same accounts\ \ \";
            else
                cout<<\"Not same accounts\ \ \";
            }
            break;
       case \'?\':
            displayMenu();
            break;
       case \'Q\':
            cout<<\"Quitting program. \"<<endl;
            system(\"pause\");
            exit(0);
}
}
   system(\"pause\");
    return 0;
 }
 void getInitialBankInfo(string id, double &bal, string address)
 {
    cout<<\"Enter id : \";
    cin>>id;
    cout<<\"Enter balance : \";
    cin>>bal;
    cout<<\"Enter address : \";
    cin>>address;
}
 char menu()
 {
   char ch;
    cout<<\"Choose an Action\"<<endl;
    cout<<\"-------------------\"<<endl;
    cout<<\"D   Deposit\"<<endl;
    cout<<\"W   Withdraw\"<<endl;
    cout<<\"S   Show Account Info. I   Add the Interest\"<<endl;
    cout<<\"U   Update Address\"<<endl;
    cout<<\"C   Check the Account\"<<endl;
    cout<<\"?   Display the Menu\"<<endl;
    cout<<\"Q   Exit Program\"<<endl;
    cout<<\"Please enter a command: \"<<endl;
cin>>ch;
ch=toupper(ch);
return ch;
}
void displayMenu()
 {
    cout<<\"-------------------\"<<endl;
    cout<<\"D   Deposit\"<<endl;
    cout<<\"W   Withdraw\"<<endl;
    cout<<\"S   Show Account Info. I   Add the Interest\"<<endl;
    cout<<\"U   Update Address\"<<endl;
    cout<<\"C   Check the Account\"<<endl;
    cout<<\"?   Display the Menu\"<<endl;
    cout<<\"Q   Exit Program\"<<endl;
 }
--------------------------------------------------------------------------------
Sample output:
Enter id : 1111
 Enter balance : 1000
 Enter address : Chicago
 Choose an Action
 -------------------
 D   Deposit
 W   Withdraw
 S   Show Account Info. I   Add the Interest
 U   Update Address
 C   Check the Account
 ?   Display the Menu
 Q   Exit Program
 Please enter a command:
 d
 Enter deposit amount : 1000
 You deposit $ 1000
 Your account\'s new balance is: 2000
Choose an Action
 -------------------
 D   Deposit
 W   Withdraw
 S   Show Account Info. I   Add the Interest
 U   Update Address
 C   Check the Account
 ?   Display the Menu
 Q   Exit Program
 Please enter a command:
 w
 Enter withdraw amount : 100
 You withdraw $ 1000
 Your account\'s new balance is: 1900
Choose an Action
 -------------------
 D   Deposit
 W   Withdraw
 S   Show Account Info. I   Add the Interest
 U   Update Address
 C   Check the Account
 ?   Display the Menu
 Q   Exit Program
 Please enter a command:
 s
Account ID:
 Balance :1900
 Address:
Choose an Action
 -------------------
 D   Deposit
 W   Withdraw
 S   Show Account Info. I   Add the Interest
 U   Update Address
 C   Check the Account
 ?   Display the Menu
 Q   Exit Program
 Please enter a command:
 u
 Enter new address : newyork
 Choose an Action
 -------------------
 D   Deposit
 W   Withdraw
 S   Show Account Info. I   Add the Interest
 U   Update Address
 C   Check the Account
 ?   Display the Menu
 Q   Exit Program
 Please enter a command:
 c
 Enter id : 1111
 Enter balance : 2000
 Enter address : delhi
 Not same accounts
Choose an Action
 -------------------
 D   Deposit
 W   Withdraw
 S   Show Account Info. I   Add the Interest
 U   Update Address
 C   Check the Account
 ?   Display the Menu
 Q   Exit Program
 Please enter a command:
 I
Interests added
Choose an Action
 -------------------
 D   Deposit
 W   Withdraw
 S   Show Account Info. I   Add the Interest
 U   Update Address
 C   Check the Account
 ?   Display the Menu
 Q   Exit Program
 Please enter a command:
 s
Account ID:
 Balance :1900
 Address:newyork
Choose an Action
 -------------------
 D   Deposit
 W   Withdraw
 S   Show Account Info. I   Add the Interest
 U   Update Address
 C   Check the Account
 ?   Display the Menu
 Q   Exit Program
 Please enter a command:
 ?
 -------------------
 D   Deposit
 W   Withdraw
 S   Show Account Info. I   Add the Interest
 U   Update Address
 C   Check the Account
 ?   Display the Menu
 Q   Exit Program
 Choose an Action
 -------------------
 D   Deposit
 W   Withdraw
 S   Show Account Info. I   Add the Interest
 U   Update Address
 C   Check the Account
 ?   Display the Menu
 Q   Exit Program
 Please enter a command:
 d
 Enter deposit amount : 5000
 You deposit $ 5000
 Your account\'s new balance is: 6900
Choose an Action
 -------------------
 D   Deposit
 W   Withdraw
 S   Show Account Info. I   Add the Interest
 U   Update Address
 C   Check the Account
 ?   Display the Menu
 Q   Exit Program
 Please enter a command:













