C++ How to Program (10th Edition)
C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
Question
Book Icon
Chapter 5, Problem 5.32E
Program Plan Intro

Program Plan:

1. Include Header files.
2. Declare class DollarAmount.

  • Start declaring public member functions.
  • Declare “DollarAmount(int64_t value)” constructor which puts pennies in variable “amount”.
  • Declare “DollarAmount(int64_t value1, int64_t value2)” constructor which takes two arguments to take value in dollars and cents. These are then converted to pennies and transferred to variable “amount”.
  • Define function add to add amount to variable “amount”.
  • Define function to subtract an amount from variable “amount”.
  • Define member function "divide" to divide "amount" with an argument "d" passed in the function using rounding technique used in addInterest member function.
  • Define function addInterest to calculate interest on variable “amount”.
  • Use conditional operator to pass value to constructor of class, calculating value using Banker’s rounding.
  • Define function "toString()" to return a string representation of a DollarAmount object for display purpose.
  • Declare private members:
  • amount to store dollar amount in pennies.

3. End of class.
4. Start the main function
  • Declare two objects of class DollarAmount "d1" and "d2" by passing amount in pennies, which will invoke single argument constructor;
  • Display result of adding amount of d2 to d1 using "add" function modifying object d1.
  • Display result of subtracting amount of d2 from d1 using "subtract" function modifying object d1.
  • Display result of subtracting amount of d1 from d2 using "subtract" function modifying object d2.
  • Ask for the interest rate and divisor in "rate" and "divisor".
  • Create object "balance" of class DollarAmount with initial balance 100000.
  • Display initial balance of "balance" object.
  • Display headers of the table as "Interest Year Amount on deposit"
  • Use for loop to run for 10 years
  • Call function addInterest using "balance" object, with "rate" and "divisor"
  • Display values of Interest Year and balance amount
  • End of for loop
  • End of main function

Blurred answer
Students have asked these similar questions
What did you find most interesting or surprising about the scientist Lavoiser?
1. Complete the routing table for R2 as per the table shown below when implementing RIP routing Protocol? (14 marks) 195.2.4.0 130.10.0.0 195.2.4.1 m1 130.10.0.2 mo R2 R3 130.10.0.1 195.2.5.1 195.2.5.0 195.2.5.2 195.2.6.1 195.2.6.0 m2 130.11.0.0 130.11.0.2 205.5.5.0 205.5.5.1 R4 130.11.0.1 205.5.6.1 205.5.6.0
Analyze the charts and introduce each charts by describing each. Identify the patterns in the given data. And determine how are the data points are related.   Refer to the raw data (table):

Chapter 5 Solutions

C++ How to Program (10th Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:9780357392676
Author:FREUND, Steven
Publisher:CENGAGE L