SlideShare a Scribd company logo
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

Amor en llamas
Amor en llamasAmor en llamas
Amor en llamas
Chloé Juliet
 
Totvs certificado programacao advpl
Totvs certificado programacao advplTotvs certificado programacao advpl
Totvs certificado programacao advpl
Diego Danna
 
1424959218142Certificate
1424959218142Certificate1424959218142Certificate
1424959218142Certificate
NDUBUISI OBELEAGU
 
Railway
RailwayRailway
Railway
chaman451
 
Exemplos
ExemplosExemplos
Induksi salam
Induksi salamInduksi salam
Induksi salam
ffarrah
 
EDUCA A TUS HIJOS CON UN POCO DE HAMBRE Y UN POCO DE FRIO
EDUCA A TUS HIJOS CON UN POCO DE HAMBRE Y UN POCO DE FRIO EDUCA A TUS HIJOS CON UN POCO DE HAMBRE Y UN POCO DE FRIO
EDUCA A TUS HIJOS CON UN POCO DE HAMBRE Y UN POCO DE FRIO
jarissalamejordelmundo
 
Prezentimii3
Prezentimii3Prezentimii3
Prezentimii3
EliotDylazeka
 
Estaciones fijas
Estaciones fijasEstaciones fijas
Estaciones fijas
kaerinik
 

Viewers also liked (9)

Amor en llamas
Amor en llamasAmor en llamas
Amor en llamas
 
Totvs certificado programacao advpl
Totvs certificado programacao advplTotvs certificado programacao advpl
Totvs certificado programacao advpl
 
1424959218142Certificate
1424959218142Certificate1424959218142Certificate
1424959218142Certificate
 
Railway
RailwayRailway
Railway
 
Exemplos
ExemplosExemplos
Exemplos
 
Induksi salam
Induksi salamInduksi salam
Induksi salam
 
EDUCA A TUS HIJOS CON UN POCO DE HAMBRE Y UN POCO DE FRIO
EDUCA A TUS HIJOS CON UN POCO DE HAMBRE Y UN POCO DE FRIO EDUCA A TUS HIJOS CON UN POCO DE HAMBRE Y UN POCO DE FRIO
EDUCA A TUS HIJOS CON UN POCO DE HAMBRE Y UN POCO DE FRIO
 
Prezentimii3
Prezentimii3Prezentimii3
Prezentimii3
 
Estaciones fijas
Estaciones fijasEstaciones fijas
Estaciones fijas
 

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
 
Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7
solutionjug4
 
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
HomeWork-Fox
 
Comp 220 lab 3
Comp 220 lab 3Comp 220 lab 3
Comp 220 lab 3
HomeWork-Fox
 
T4
T4T4
T4
lksoo
 
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
 
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
IBM Rational software
 
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
pradesigali1
 
Cis247 i lab 5 inheritance
Cis247 i lab 5 inheritanceCis247 i lab 5 inheritance
Cis247 i lab 5 inheritance
sdjdskjd9097
 
11 job costing
11 job costing11 job costing
Java: Class Design Examples
Java: Class Design ExamplesJava: Class Design Examples
Java: Class Design Examples
Tareq Hasan
 
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

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

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

Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 

Recently uploaded (20)

Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 

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