Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 12, Problem 1PP
Program Plan Intro

Percentage Calculation

Program Plan:

ADT interface filename: “Percent.h”

  • Include required header files.
  • Define a class “Percent”.
    • Declare function for overload operator “==” and “<”.
    • Declare default constructor for “Percent” class.
    • Declare a constructor for “Percent” class with one integer parameter.
    • Declare function for input overload operator and output overload operator.
    • Declare function for binary overload operators “+”, “-” and “*”.
    • Declare a member variable “value”.

ADT implementation filename: “Percent.cpp”

  • Include required header files.
  • Define default constructor for “Percent” class.
    • Here assign the value of “value” to “0”.
  • Define constructor for “Percent” class with one integer parameter “percentValue”.
    • In this constructor, assign “value” to “percentValue”.
  • Define a function for overload operator “<”.
    • This function is used to check whether the first percent is less than second percent or not.
  • Define a function for overload operator “==”.
    • This function is used to check whether the two percent’s are equal or not.
  • Define a function for input operator “>>”.
  • Define a function for input operator “<<”.
  • Define a function for binary overload operator “+” to compute the sum of two percentages.
    • In this function, create an object “sum”.
    • Then compute the addition of two percent’s.
    • Finally returns the result of addition.
  • Define a function for binary overload operator “-” to compute the subtraction of two percentages.
    • In this function, create an object “s”.
    • Then compute the subtraction of two percent’s.
    • Finally returns the result of subtraction.
  • Define a function for binary overload operator “*” to compute the multiplication of one percent and an integer value.
    • In this function, create an object “m”.
    • Then compute the multiplication of one percent and an integer value.
    • Finally returns the result of multiplication.

Application filename: “main.cpp”

  • Include required header files.
  • Define main function.
    • Create two objects “percent1” and “percent2” from “Percent” class.
    • Create an object “percent3” with one integer parameter “10”.
    • Declare an integer variable “intValue”.
    • Read the percentage 1 and percentage 2 from user.
    • Check the two percentages using “==” operator.
    • Check the two percentages using “<” operator.
    • Create an object “sumPercent” from “Percent” class.
    • Then compute and display sum of two percentages.
    • Create an object “subPercent” from “Percent” class.
    • Then compute and display difference of two percentages.
    • Display percentage 3 from assigned value.
    • Read an integer from user to multiply with a percentage 3.
    • Finally compute and display the multiplication of “percent3” and a user entered integer value.

Blurred answer
Students have asked these similar questions
Topical Information Use C++. This lab should provide you with practice in file handling, stream formatting, and some string manipulation. Classes might come in handy, too. Program Information Write a program that reads a list of enrollments from a file and prints a class roster for the teacher. Make the class roster line up as neatly as you can and still fit on the screen. You can choose the actual values to use for your data. Make sure to do enough sets of data to well test your program! (Empty data set, normal data set, data with large values, data with short values, etc.) Also, your program can't know ahead of time how many people are enrolled in the class... Don't forget to read the file's name from the user and protect your program against any errors that may occur during the opening of the file. Try to use functions to break up the program into more manageable pieces. As an example, you might have the data file contain: # name # student number # address1 # address2 # phone number…
Answer the given question with a proper explanation and step-by-step solution.
This discussion assignment examines variable scope. For this assignment, we will be examining the Beverage2 class (an updated version of the Beverage class from discussion 1), its subclass Espresso, and the TestBeverage2 class. This time, assume that all source files are in the same package. Note that some lines may wrap, but are still considered on one line. Examine the code below. Recall that variables have four kinds of scope: static, instance, local, and block. For each variable listed below, identify its scope (static, instance, local, or block) and describe the scope using complete sentences. An example description is provided, after the code listing, for the ounces variable in the Beverage2 class. Please describe the scope for the following variables: The num variable in the Beverage2 class The price variable in the Beverage2 class The shots variable in the Espresso class The b variable in the TestBeverage2 class The j variable in the TestBeverage2 class   public abstract…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education