SlideShare a Scribd company logo
1 of 2
Download to read offline
BLG332E
Object Oriented Programming
Practice Session 3
Exercise 4
In this exercise, you create a simple version of the Account class. A test program,
TestBanking.cpp, has been written that creates a single account.
Task 1: Change your working directory to chap03/exercise4
Task 2: Create a class Account that implements the UML diagram given above.
a) Declare one private attribute: balance; tis attribute holds the current (or “running”) balance of
the bank account.
b) Declare a public constructor that takes one parameter (init_balance) that populates the
balance attribute.
c) Declare a public method getBalance that retrieves the current balance.
d) Declare a public method deposit that adds the amount parameter to the current balance.
e) Declare a public method withdraw that removes the amount parameter from the current
balance.
Task 3: Read the TestBanking.cpp code.
Task 4: Compile Account.cpp and TestBanking.cpp.
Task 5: Run the program. You should see the following output:
Create an account with 500.0 balance
Withdraw 150.0
Deposit 22.50
Withdraw 47.62
The account has a balance of 324.88
Exercise 5
In this exercise you will expand the Banking project by adding a Customer class. A customer will
contain one Account object.
Task 1: Change your working directory to chap03/exercise5
Task 2: Copy Account class from the previous exercise lab
cp ../exercise4/Account.* .
Task 2: Create a class Customer class that implements the above UML diagram
a) Declare three private attributes: firstName, lastName, and account.
b) Declare a public constructor that takes two parameters (f and l) that populate the object
attributes.
c) Declare two public accessors for the object attributes; the methods getFirstName and
getlastName return the appropriate attribute.
d) Declare a public method setAccount to assign the account attribute.
e) Declare a public method getAccount to retrieve the account attribute.
f)
Task 3: Read the TestBanking.cpp code.
Task 4: Compile Account.cpp, Customer.cpp, and TestBanking.cpp.
Task 5: Run the program. The output generated should be:
Creating the Customer Jane Smith
Creating her account with a 500.0 balance.
Withdraw 150.0
Deposit 22.50
Withdraw 47.62
Customer [Smith, Jane] has a balance of 324.88
Exercise 6
In this exercise, you will modify the withdraw method to return a boolean value to specify whether the
transaction was successful.
Task 1: Change your working directory to chap03/exercise6
Task 2: You can copy the Account.* and Customer.* files you created in Exercise 5.
Task 3: Modify the Account class to place conditions on the withdraw and deposit methods.
a) Modify the deposit method to return true.
b) Modify the withdraw method to check that the amount being withdrawn is not greater
than the current balance. If amt is less than balance, then subtract the amount from the
balance and return true; else leave the balance alone and return false.
Task 4: Read the TestBanking.cpp code.
Task 5: Compile Account.cpp, Customer.cpp, and TestBanking.cpp.
Task 6: Run the program. The output generated should be:
Creating the Customer Jane Smith
Creating her account with a 500.0 balance.
Withdraw 150.0:true
Deposit 22.50: true
Withdraw 47.62: false
Withdraw 400.0: false
Customer [Smith, Jane] has a balance of 324.88

More Related Content

Viewers also liked (8)

Biografia
BiografiaBiografia
Biografia
 
Greek & latin root words
Greek & latin root wordsGreek & latin root words
Greek & latin root words
 
Totvs certificado totvs devstudio
Totvs certificado totvs devstudioTotvs certificado totvs devstudio
Totvs certificado totvs devstudio
 
ERISA: A Timeline for Compliance
ERISA: A Timeline for ComplianceERISA: A Timeline for Compliance
ERISA: A Timeline for Compliance
 
Higiene alimentaria
Higiene alimentariaHigiene alimentaria
Higiene alimentaria
 
Bonsaii franchisetermsandconditions
Bonsaii franchisetermsandconditionsBonsaii franchisetermsandconditions
Bonsaii franchisetermsandconditions
 
27 al 31 de enero de 2014
27 al 31 de enero de 201427 al 31 de enero de 2014
27 al 31 de enero de 2014
 
Hoja de vida jimmy torres
Hoja de vida jimmy torresHoja de vida jimmy torres
Hoja de vida jimmy torres
 

Similar to 10

Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7
ashhadiqbal
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
ccis224477
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
ccis224477
 
Cis247 i lab 4 composition and class interfaces
Cis247 i lab 4 composition and class interfacesCis247 i lab 4 composition and class interfaces
Cis247 i lab 4 composition and class interfaces
sdjdskjd9097
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
cis247
 
Assignment Instructions 2_7aExplain the interrelationships bet.docx
Assignment Instructions 2_7aExplain the interrelationships bet.docxAssignment Instructions 2_7aExplain the interrelationships bet.docx
Assignment Instructions 2_7aExplain the interrelationships bet.docx
ssuser562afc1
 
Please distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdfPlease distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdf
neerajsachdeva33
 
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Account.h  Definition of Account class. #ifndef ACCOUNT_H #d.pdfAccount.h  Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
anujmkt
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org
AbbyWhyte974
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org
MartineMccracken314
 
Cis247 i lab 5 inheritance
Cis247 i lab 5 inheritanceCis247 i lab 5 inheritance
Cis247 i lab 5 inheritance
sdjdskjd9097
 
Cis247 a ilab 5 inheritance
Cis247 a ilab 5 inheritanceCis247 a ilab 5 inheritance
Cis247 a ilab 5 inheritance
ccis224477
 

Similar to 10 (20)

Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7
 
Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7
 
CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces  CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces
 
Comp 220 lab 3
Comp 220 lab 3Comp 220 lab 3
Comp 220 lab 3
 
T4
T4T4
T4
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
 
Cis247 i lab 4 composition and class interfaces
Cis247 i lab 4 composition and class interfacesCis247 i lab 4 composition and class interfaces
Cis247 i lab 4 composition and class interfaces
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
 
Assignment Instructions 2_7aExplain the interrelationships bet.docx
Assignment Instructions 2_7aExplain the interrelationships bet.docxAssignment Instructions 2_7aExplain the interrelationships bet.docx
Assignment Instructions 2_7aExplain the interrelationships bet.docx
 
Please distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdfPlease distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdf
 
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Account.h  Definition of Account class. #ifndef ACCOUNT_H #d.pdfAccount.h  Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org
 
Lab 2: Importing requirements artifacts from a CSV file
Lab 2: Importing requirements artifacts from a CSV file Lab 2: Importing requirements artifacts from a CSV file
Lab 2: Importing requirements artifacts from a CSV file
 
Comp 220 i lab 3 bank account lab report and source code
Comp 220 i lab 3 bank account lab report and source codeComp 220 i lab 3 bank account lab report and source code
Comp 220 i lab 3 bank account lab report and source code
 
Cis247 i lab 5 inheritance
Cis247 i lab 5 inheritanceCis247 i lab 5 inheritance
Cis247 i lab 5 inheritance
 
11 job costing
11 job costing11 job costing
11 job costing
 
Java: Class Design Examples
Java: Class Design ExamplesJava: Class Design Examples
Java: Class Design Examples
 
Cis247 a ilab 5 inheritance
Cis247 a ilab 5 inheritanceCis247 a ilab 5 inheritance
Cis247 a ilab 5 inheritance
 

More from liankei (20)

Lo 19
Lo 19Lo 19
Lo 19
 
Lo 18
Lo 18Lo 18
Lo 18
 
Lo 13
Lo 13Lo 13
Lo 13
 
Lo 12
Lo 12Lo 12
Lo 12
 
Lo 11
Lo 11Lo 11
Lo 11
 
Lo 06
Lo 06Lo 06
Lo 06
 
Lo 05
Lo 05Lo 05
Lo 05
 
Lo 04
Lo 04Lo 04
Lo 04
 
Lo 01
Lo 01Lo 01
Lo 01
 
Lo 16
Lo 16Lo 16
Lo 16
 
Lo 15
Lo 15Lo 15
Lo 15
 
Lo 09
Lo 09Lo 09
Lo 09
 
Lo 08
Lo 08Lo 08
Lo 08
 
Lo 03
Lo 03Lo 03
Lo 03
 
Lo 20
Lo 20Lo 20
Lo 20
 
Lo19
Lo19Lo19
Lo19
 
Lo20
Lo20Lo20
Lo20
 
Lo17
Lo17Lo17
Lo17
 
Lo18
Lo18Lo18
Lo18
 
Lo15
Lo15Lo15
Lo15
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

10

  • 1. BLG332E Object Oriented Programming Practice Session 3 Exercise 4 In this exercise, you create a simple version of the Account class. A test program, TestBanking.cpp, has been written that creates a single account. Task 1: Change your working directory to chap03/exercise4 Task 2: Create a class Account that implements the UML diagram given above. a) Declare one private attribute: balance; tis attribute holds the current (or “running”) balance of the bank account. b) Declare a public constructor that takes one parameter (init_balance) that populates the balance attribute. c) Declare a public method getBalance that retrieves the current balance. d) Declare a public method deposit that adds the amount parameter to the current balance. e) Declare a public method withdraw that removes the amount parameter from the current balance. Task 3: Read the TestBanking.cpp code. Task 4: Compile Account.cpp and TestBanking.cpp. Task 5: Run the program. You should see the following output: Create an account with 500.0 balance Withdraw 150.0 Deposit 22.50 Withdraw 47.62 The account has a balance of 324.88 Exercise 5 In this exercise you will expand the Banking project by adding a Customer class. A customer will contain one Account object. Task 1: Change your working directory to chap03/exercise5 Task 2: Copy Account class from the previous exercise lab cp ../exercise4/Account.* .
  • 2. Task 2: Create a class Customer class that implements the above UML diagram a) Declare three private attributes: firstName, lastName, and account. b) Declare a public constructor that takes two parameters (f and l) that populate the object attributes. c) Declare two public accessors for the object attributes; the methods getFirstName and getlastName return the appropriate attribute. d) Declare a public method setAccount to assign the account attribute. e) Declare a public method getAccount to retrieve the account attribute. f) Task 3: Read the TestBanking.cpp code. Task 4: Compile Account.cpp, Customer.cpp, and TestBanking.cpp. Task 5: Run the program. The output generated should be: Creating the Customer Jane Smith Creating her account with a 500.0 balance. Withdraw 150.0 Deposit 22.50 Withdraw 47.62 Customer [Smith, Jane] has a balance of 324.88 Exercise 6 In this exercise, you will modify the withdraw method to return a boolean value to specify whether the transaction was successful. Task 1: Change your working directory to chap03/exercise6 Task 2: You can copy the Account.* and Customer.* files you created in Exercise 5. Task 3: Modify the Account class to place conditions on the withdraw and deposit methods. a) Modify the deposit method to return true. b) Modify the withdraw method to check that the amount being withdrawn is not greater than the current balance. If amt is less than balance, then subtract the amount from the balance and return true; else leave the balance alone and return false. Task 4: Read the TestBanking.cpp code. Task 5: Compile Account.cpp, Customer.cpp, and TestBanking.cpp. Task 6: Run the program. The output generated should be: Creating the Customer Jane Smith Creating her account with a 500.0 balance. Withdraw 150.0:true Deposit 22.50: true Withdraw 47.62: false Withdraw 400.0: false Customer [Smith, Jane] has a balance of 324.88