SlideShare a Scribd company logo
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:tt 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 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
#include
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
#include
//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: "<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
#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 $ "<>withdrawamt;
if(bank.withdraw(withdrawamt))
{
cout<<"You withdraw $ "<>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. "<>id;
cout<<"Enter balance : ";
cin>>bal;
cout<<"Enter address : ";
cin>>address;
}
char menu()
{
char ch;
cout<<"Choose an Action"<>ch;
ch=toupper(ch);
return ch;
}
void displayMenu()
{
cout<<"-------------------"<

More Related Content

Similar to Please distinguish between the .h and .cpp file, create a fully work.pdf

Write a banking program that simulates the operation of your local ba.docx
 Write a banking program that simulates the operation of your local ba.docx Write a banking program that simulates the operation of your local ba.docx
Write a banking program that simulates the operation of your local ba.docx
ajoy21
 
I need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdfI need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdf
rajeshjangid1865
 
Cbse computer science (c++) class 12 board project bank managment system
Cbse computer science (c++)  class 12 board project  bank managment systemCbse computer science (c++)  class 12 board project  bank managment system
Cbse computer science (c++) class 12 board project bank managment system
pranoy_seenu
 
I am having trouble writing the individual files for part 1, which i.pdf
I am having trouble writing the individual files for part 1, which i.pdfI am having trouble writing the individual files for part 1, which i.pdf
I am having trouble writing the individual files for part 1, which i.pdf
mallik3000
 
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdfBank Program in JavaBelow is my code(havent finished, but it be .pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
izabellejaeden956
 
Hi,I have updated the code as per your requirement. Highlighted th.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdfHi,I have updated the code as per your requirement. Highlighted th.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdf
annaindustries
 
You are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdfYou are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdf
deepakangel
 
Ch03
Ch03Ch03
Ch03
ojac wdaj
 
The java class Account that simultes the Account class.pdf
   The java class Account that simultes  the Account class.pdf   The java class Account that simultes  the Account class.pdf
The java class Account that simultes the Account class.pdf
akshay1213
 

Similar to Please distinguish between the .h and .cpp file, create a fully work.pdf (10)

Write a banking program that simulates the operation of your local ba.docx
 Write a banking program that simulates the operation of your local ba.docx Write a banking program that simulates the operation of your local ba.docx
Write a banking program that simulates the operation of your local ba.docx
 
I need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdfI need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdf
 
Cbse computer science (c++) class 12 board project bank managment system
Cbse computer science (c++)  class 12 board project  bank managment systemCbse computer science (c++)  class 12 board project  bank managment system
Cbse computer science (c++) class 12 board project bank managment system
 
I am having trouble writing the individual files for part 1, which i.pdf
I am having trouble writing the individual files for part 1, which i.pdfI am having trouble writing the individual files for part 1, which i.pdf
I am having trouble writing the individual files for part 1, which i.pdf
 
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdfBank Program in JavaBelow is my code(havent finished, but it be .pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
 
Hi,I have updated the code as per your requirement. Highlighted th.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdfHi,I have updated the code as per your requirement. Highlighted th.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdf
 
You are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdfYou are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdf
 
Ch03
Ch03Ch03
Ch03
 
Ch03
Ch03Ch03
Ch03
 
The java class Account that simultes the Account class.pdf
   The java class Account that simultes  the Account class.pdf   The java class Account that simultes  the Account class.pdf
The java class Account that simultes the Account class.pdf
 

More from neerajsachdeva33

Can you please explain those risk management from Kaiser Permanente.pdf
Can you please explain those risk management from Kaiser Permanente.pdfCan you please explain those risk management from Kaiser Permanente.pdf
Can you please explain those risk management from Kaiser Permanente.pdf
neerajsachdeva33
 
A survey of 2630 musicians showed that 372 of them are left-handed. .pdf
A survey of 2630 musicians showed that 372 of them are left-handed. .pdfA survey of 2630 musicians showed that 372 of them are left-handed. .pdf
A survey of 2630 musicians showed that 372 of them are left-handed. .pdf
neerajsachdeva33
 
What is other disorder of arteries beside atherosclerosis What.pdf
What is other disorder of arteries beside atherosclerosis What.pdfWhat is other disorder of arteries beside atherosclerosis What.pdf
What is other disorder of arteries beside atherosclerosis What.pdf
neerajsachdeva33
 
Why is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdf
Why is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdfWhy is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdf
Why is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdf
neerajsachdeva33
 
What type of relationship typically exists between the resident and t.pdf
What type of relationship typically exists between the resident and t.pdfWhat type of relationship typically exists between the resident and t.pdf
What type of relationship typically exists between the resident and t.pdf
neerajsachdeva33
 
What is the model for floral induction by day-lengthSolutionB.pdf
What is the model for floral induction by day-lengthSolutionB.pdfWhat is the model for floral induction by day-lengthSolutionB.pdf
What is the model for floral induction by day-lengthSolutionB.pdf
neerajsachdeva33
 
What is the difference between a semi-permeable and selectively perm.pdf
What is the difference between a semi-permeable and selectively perm.pdfWhat is the difference between a semi-permeable and selectively perm.pdf
What is the difference between a semi-permeable and selectively perm.pdf
neerajsachdeva33
 
what did Linnaeus contribute to taxonomySolutionThe classifica.pdf
what did Linnaeus contribute to taxonomySolutionThe classifica.pdfwhat did Linnaeus contribute to taxonomySolutionThe classifica.pdf
what did Linnaeus contribute to taxonomySolutionThe classifica.pdf
neerajsachdeva33
 
We are interested in whether the proportions of female suicide victim.pdf
We are interested in whether the proportions of female suicide victim.pdfWe are interested in whether the proportions of female suicide victim.pdf
We are interested in whether the proportions of female suicide victim.pdf
neerajsachdeva33
 
True or false Fruits attract animals that act as pollinators T.pdf
True or false Fruits attract animals that act as pollinators T.pdfTrue or false Fruits attract animals that act as pollinators T.pdf
True or false Fruits attract animals that act as pollinators T.pdf
neerajsachdeva33
 
the observed locations of integrated retroviral proviruses within ho.pdf
the observed locations of integrated retroviral proviruses within ho.pdfthe observed locations of integrated retroviral proviruses within ho.pdf
the observed locations of integrated retroviral proviruses within ho.pdf
neerajsachdeva33
 
The general name for something that binds to a protein is Select one.pdf
The general name for something that binds to a protein is  Select one.pdfThe general name for something that binds to a protein is  Select one.pdf
The general name for something that binds to a protein is Select one.pdf
neerajsachdeva33
 
serial communication, parallel communication, SPI and ADCs. Write .pdf
serial communication, parallel communication, SPI and ADCs. Write .pdfserial communication, parallel communication, SPI and ADCs. Write .pdf
serial communication, parallel communication, SPI and ADCs. Write .pdf
neerajsachdeva33
 
The first part of the assignment involves creating very basic GUI co.pdf
The first part of the assignment involves creating very basic GUI co.pdfThe first part of the assignment involves creating very basic GUI co.pdf
The first part of the assignment involves creating very basic GUI co.pdf
neerajsachdeva33
 
Suppose that a heap stores 210 elements. What is its height (show w.pdf
Suppose that a heap stores 210 elements. What is its height (show w.pdfSuppose that a heap stores 210 elements. What is its height (show w.pdf
Suppose that a heap stores 210 elements. What is its height (show w.pdf
neerajsachdeva33
 
Oxfam used its existing opt-in e-mail list only for this campaign; i.pdf
Oxfam used its existing opt-in e-mail list only for this campaign; i.pdfOxfam used its existing opt-in e-mail list only for this campaign; i.pdf
Oxfam used its existing opt-in e-mail list only for this campaign; i.pdf
neerajsachdeva33
 
JUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdf
JUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdfJUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdf
JUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdf
neerajsachdeva33
 
In the paramyxoviruses, cleavage of the F0 protein into two subunits .pdf
In the paramyxoviruses, cleavage of the F0 protein into two subunits .pdfIn the paramyxoviruses, cleavage of the F0 protein into two subunits .pdf
In the paramyxoviruses, cleavage of the F0 protein into two subunits .pdf
neerajsachdeva33
 
Information about dengue fever is provided on the following pages. A.pdf
Information about dengue fever is provided on the following pages. A.pdfInformation about dengue fever is provided on the following pages. A.pdf
Information about dengue fever is provided on the following pages. A.pdf
neerajsachdeva33
 
A toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdf
A toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdfA toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdf
A toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdf
neerajsachdeva33
 

More from neerajsachdeva33 (20)

Can you please explain those risk management from Kaiser Permanente.pdf
Can you please explain those risk management from Kaiser Permanente.pdfCan you please explain those risk management from Kaiser Permanente.pdf
Can you please explain those risk management from Kaiser Permanente.pdf
 
A survey of 2630 musicians showed that 372 of them are left-handed. .pdf
A survey of 2630 musicians showed that 372 of them are left-handed. .pdfA survey of 2630 musicians showed that 372 of them are left-handed. .pdf
A survey of 2630 musicians showed that 372 of them are left-handed. .pdf
 
What is other disorder of arteries beside atherosclerosis What.pdf
What is other disorder of arteries beside atherosclerosis What.pdfWhat is other disorder of arteries beside atherosclerosis What.pdf
What is other disorder of arteries beside atherosclerosis What.pdf
 
Why is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdf
Why is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdfWhy is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdf
Why is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdf
 
What type of relationship typically exists between the resident and t.pdf
What type of relationship typically exists between the resident and t.pdfWhat type of relationship typically exists between the resident and t.pdf
What type of relationship typically exists between the resident and t.pdf
 
What is the model for floral induction by day-lengthSolutionB.pdf
What is the model for floral induction by day-lengthSolutionB.pdfWhat is the model for floral induction by day-lengthSolutionB.pdf
What is the model for floral induction by day-lengthSolutionB.pdf
 
What is the difference between a semi-permeable and selectively perm.pdf
What is the difference between a semi-permeable and selectively perm.pdfWhat is the difference between a semi-permeable and selectively perm.pdf
What is the difference between a semi-permeable and selectively perm.pdf
 
what did Linnaeus contribute to taxonomySolutionThe classifica.pdf
what did Linnaeus contribute to taxonomySolutionThe classifica.pdfwhat did Linnaeus contribute to taxonomySolutionThe classifica.pdf
what did Linnaeus contribute to taxonomySolutionThe classifica.pdf
 
We are interested in whether the proportions of female suicide victim.pdf
We are interested in whether the proportions of female suicide victim.pdfWe are interested in whether the proportions of female suicide victim.pdf
We are interested in whether the proportions of female suicide victim.pdf
 
True or false Fruits attract animals that act as pollinators T.pdf
True or false Fruits attract animals that act as pollinators T.pdfTrue or false Fruits attract animals that act as pollinators T.pdf
True or false Fruits attract animals that act as pollinators T.pdf
 
the observed locations of integrated retroviral proviruses within ho.pdf
the observed locations of integrated retroviral proviruses within ho.pdfthe observed locations of integrated retroviral proviruses within ho.pdf
the observed locations of integrated retroviral proviruses within ho.pdf
 
The general name for something that binds to a protein is Select one.pdf
The general name for something that binds to a protein is  Select one.pdfThe general name for something that binds to a protein is  Select one.pdf
The general name for something that binds to a protein is Select one.pdf
 
serial communication, parallel communication, SPI and ADCs. Write .pdf
serial communication, parallel communication, SPI and ADCs. Write .pdfserial communication, parallel communication, SPI and ADCs. Write .pdf
serial communication, parallel communication, SPI and ADCs. Write .pdf
 
The first part of the assignment involves creating very basic GUI co.pdf
The first part of the assignment involves creating very basic GUI co.pdfThe first part of the assignment involves creating very basic GUI co.pdf
The first part of the assignment involves creating very basic GUI co.pdf
 
Suppose that a heap stores 210 elements. What is its height (show w.pdf
Suppose that a heap stores 210 elements. What is its height (show w.pdfSuppose that a heap stores 210 elements. What is its height (show w.pdf
Suppose that a heap stores 210 elements. What is its height (show w.pdf
 
Oxfam used its existing opt-in e-mail list only for this campaign; i.pdf
Oxfam used its existing opt-in e-mail list only for this campaign; i.pdfOxfam used its existing opt-in e-mail list only for this campaign; i.pdf
Oxfam used its existing opt-in e-mail list only for this campaign; i.pdf
 
JUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdf
JUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdfJUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdf
JUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdf
 
In the paramyxoviruses, cleavage of the F0 protein into two subunits .pdf
In the paramyxoviruses, cleavage of the F0 protein into two subunits .pdfIn the paramyxoviruses, cleavage of the F0 protein into two subunits .pdf
In the paramyxoviruses, cleavage of the F0 protein into two subunits .pdf
 
Information about dengue fever is provided on the following pages. A.pdf
Information about dengue fever is provided on the following pages. A.pdfInformation about dengue fever is provided on the following pages. A.pdf
Information about dengue fever is provided on the following pages. A.pdf
 
A toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdf
A toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdfA toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdf
A toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdf
 

Recently uploaded

Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 

Recently uploaded (20)

Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 

Please distinguish between the .h and .cpp file, create a fully work.pdf

  • 1. 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
  • 2. 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.
  • 3. 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:tt 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:
  • 4. 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 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:
  • 5. 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
  • 6. 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
  • 7. //BankAccount.h //header file of BankAccount #ifndef BANK_ACCOUNT_H #define BANK_ACCOUNT_H #include #include 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 #include //include BankAccount.h #include "BankAccount.h"
  • 8. 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;
  • 9. 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: "<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() &&
  • 10. address.compare(address)==0; } -------------------------------------------------------------------------------- //BankAccount test program //main.c #include #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 $ "<>withdrawamt; if(bank.withdraw(withdrawamt)) {
  • 11. cout<<"You withdraw $ "<>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. "<>id; cout<<"Enter balance : "; cin>>bal; cout<<"Enter address : "; cin>>address; } char menu() { char ch; cout<<"Choose an Action"<>ch; ch=toupper(ch); return ch; } void displayMenu() { cout<<"-------------------"<