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
Design and draw a high-level "as-is" process diagram that illustrates a current process related to a product or service offered through the SSDCI.gov database.
Compare last-mile connections for connecting homes and businesses to the Internet
Explain wireless networking standards

Chapter 5 Solutions

C++ How to Program (10th Edition)

Knowledge Booster
Background pattern image
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