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
(GREATEST COMMON DIVISOR) The greatest common divisor of integers x and y is the largest integer that evenly divides into both x and y. Write and test a recursive function gcd that returns the greatest common divisor of x and y. The gcd of x and y is defined recursively as follows: If y is equal to 0, then gcd (x, y) is x; otherwise, gcd (x, y) is gcd (y, x % y), where % is the remainder operator.
(Perfect Numbers) An integer is said to be a perfect number if the sum of its divisors, including 1 (but not the number itself), is equal to the number. For example, 6 is a perfect number, because   6=1+2+3. Write a functionisPerfect that determines whether parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. Print the divisors of each perfect number to confirm that the number is indeed perfect. Challenge the power of your computer by testing numbers much larger than 1000.
[In c#] Write a class with name Arrays . This class has an array which should be initialized by user.Write a method Sum that should sum even numbers in array and return sum. write a function with name numFind in this class with working logic as to find the mid number of an array. After finding this number calculate its factorial.Write function that should display sum and factorial.Don’t use divide operator

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