Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
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.
Expert Solution & Answer
Trending nowThis is a popular solution!
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…
Chapter 12 Solutions
Problem Solving with C++ (10th Edition)
Ch. 12.1 - Suppose that you are defining an ADT class and...Ch. 12.1 - Which of the following files has a name that ends...Ch. 12.1 - Prob. 3STECh. 12.1 - Suppose you define a class in separate files and...Ch. 12.1 - Suppose you want to change the implementation of...Ch. 12.1 - What is the difference between an ADT you define...Ch. 12.2 - Consider the program shown in Display 12.5. Could...Ch. 12.2 - In Self-Test Exercise 7, we saw that you could not...Ch. 12.2 - Prob. 9STECh. 12.2 - Prob. 10STE
Ch. 12.2 - Consider the following function declarations from...Ch. 12.2 - Would the program in Display 12.8 behave any...Ch. 12.2 - Prob. 13STECh. 12.2 - In Display 12.7 there are two groupings for the...Ch. 12 - Add the following member function to the ADT class...Ch. 12 - Prob. 3PCh. 12 - Redo Practice Programs 2 from Chapter 11, but this...Ch. 12 - This Practice Program explores how the unnamed...Ch. 12 - Prob. 1PPCh. 12 - Redo (or do for the first time) Programming...Ch. 12 - Prob. 3PP
Knowledge Booster
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
- c++ student instruction1. SimpleVector Generic Template2. SearchableVector Generic Template3. SimpleVectorInterface Generic Template4. Soccer Class implemented with MyString 5. Implementation of operators.6. Use three files in your implementation.Description of the problem:1. Use the Soccer class described in Gaddis chapter 11 number 6 page 6522. Implement the operators in your code, and make the code modifications discussed in class, to create a one-dimensional array composed of instances of type Soccer and show your results in solving the following problems:to. (Gaddis) Programming Challenger 9. SearchableVectorModification page 1023 Chapter 16b. (Gaddis) Programming Challenger 10. SortableVector ClassTemplate Modification page 1023 Chap16. order with himSelection Sort algorithm p. 474 Chap. 8=============================================================== Soccer Scores class infoWrite a program that stores the following data about a soccer player in a structure: Player’s Name…arrow_forwardYou are tasked to implement an abstract data type class which takes in a given input file called input.txt, and processes, identifies and sorts all unique word instances found in the file. Sample Input Hi hello hi good bye goodbye Bye bye good say Sample Output Bye Hi bye hello hi say The input.txt file is found along with the zip folder where this instructions file also came along with. Note: you are not allowed to use pythonic lists, and its methods and functions, and string methods. However the use of the file handling methods (read readlines and readline) are allowed for this project.arrow_forwardNeed help with implementing of this program in C# by using Interface. Task: RenameFile Create an interface IUndoable to represent actions that can be reversed. Create a class that renames a file, and make it undoable.arrow_forward
- Hey there I am struggling with creating a second class module in PYTHON - that would import an already existing class I have finished from another module file called LANDINGSPOT, the class I am struggling with follows the exact order below* - class PLANE first-class which is done (Landingspot CLASS with objects ID, city, country ) and am trying to create another class module PLANE. (flightNumber, Start, goingTo). Each class would be eventually reading from text files with some spaces and commas separating randomly that’s where they would be getting data but that's for another module, which would need to import PLANE class. 'As suggested by its name, this class represents a 'Plane' from one landingSpot to another landingSpot in the program. Each Plane object must have a flightNumber (the unique 6-character code containing 3 letters followed by 3 digits), Start place, and a goingTo. Both the Start and goingTo must be LandingSpot objects within the…arrow_forwardAssume 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 class Beverage2 { private static int num; private int ounces; private double price; protected Beverage2(int ounces, double price) { this.ounces = ounces; this.price = price;…arrow_forwardIn this assignment, you will write a program that readsa list of people from a file, create a HashSet of the people, and print the people in the HashSet.The input filename ispassed in as a command line argument.•The program must implement a main class, and a Person class.•A template for the Person class is provided.A Person has a name and an address, both Strings.•If the input file name is not provided, your program should an error message and exit, e.g., Usage: java FuAssignment10/FuMain inputfile•If the specified input file does not exist or cannot be opened, your program should an error message and exit, e.g.,File abc.txt does not existor cannot be opened!•The input file lists one person per line. Each line contains aname and an address, separated by a comma, “,”.For example, the following are in a sample file students.txt:James Bond, 111 Main StTayer Smoke, 2334 Murry LnDavid Jones, 302 Toast AveAbby Wasch, 84 Sunny PlJames Bond, 111 Main St•Yourprogram should read each line,…arrow_forward
- For this task, you are to complete a program which manages a movie collection. Instructions The movie collection program found below is currently missing two important pieces of functionality---it doesn't add movies to the collection, nor is it able to print the longest movies in the collection. Provided for you is the Movie class which contains the title and duration for a particular movie, and the MovieCollection class which is responsible for maintaining a collection of movies. Your task is to implement missing functionality by a) completing the interactive loop, and b) defining a print_longest_movies method on the MovieCollection class. a) Completing the interactive loop To complete the interactive loop, you must instantiate a Movie object using the information provided by the user and add it to the MovieCollection object using the provided add_movie method. b) Defining print_longest_movies This method is to take no arguments and print the title and duration…arrow_forwardPlease write Python code. Movie Recommendations via Item-Item Collaborative Filtering. You are provided with real data (Movie-Lens dataset) of user ratings for different movies. There is a readme file that describes the data format. In this project, you will implement the item-item collaborative filtering algorithm that we discussed in the class. The high-level steps are as follows: a) Construct the profile of each item (i.e., movie). At the minimum, you should use the ratings given by each user for a given item (i.e., movie). Optionally, you can use other information (e.g., genre information for each movie and tag information given by the user for each movie) creatively. If you use this additional information, you should explain your methodology in the submitted report. b) Compute similarity score for all item-item (i.e., movie-movie) pairs. You will employ the centered cosine similarity metric that we discussed in class. c) Compute the neighborhood set N for each item (i.e. movie).…arrow_forwardusing c++: Write a class date (d, m, y), class file (name, size, creation_date) and class directory (name, directory_creation_date, array[files])Write the constuctors, destructors, set, get methods for each classCreate a directory object and fill it with its required data Find the size of the created directory object.arrow_forward
- in python. Please include docstring, so I can understand each step to this program. Thanks. you will import the json module. Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet, saving data to a JSON file, loading data from a JSON file, and getting a set of all pet species. It will only be loading JSON files that it has previously created, so the internal organization of the data is up to you. The init method takes no parameters and initializes all the data members, which must all be private. The add_pet method takes as parameters the name of the pet, the species of the pet, and the name of the pet's owner. If a pet has the same name as a pet that has already been added, then the function should raise a DuplicateNameError (you'll need to define this exception class). The delete_pet method takes as a parameter the name of the pet and deletes that pet. The get_owner method takes as a parameter the name of the pet and…arrow_forwardThe goal for Lab07 is to use the provided Student class and create an array of Student objects that is stored in a School object. This program uses a Student class that is provided(picture attached!). The class is placed in its own separate file and should not be altered. This project started with Lab06a and uses the same Student class. Part one of Lab07 is similar to the Lab06b. The difference is that Lab06b used static 1D arrays and Lab07 uses dynamic ArrayList arrays. The output is the same. OUTPUT Tom 21 1.685 Ann 34 3.875 Bob 18 2.5 Jan 45 4.0 Joe 27 2.975 Sue 19 3.225 Jay 30 3.65 Meg 38 2.0 Art 40 3.999 Deb 35 2.125 Ann 34 3.875 Art 40 3.999 Bob 18 2.5 Deb 35 2.125 Jan 45 4.0 Jay 30 3.65 Joe 27 2.975 Meg 38 2.0 Sue 19 3.225 Tom 21 1.685 Bob 18 2.5 Sue 19 3.225 Tom 21 1.685 Joe 27 2.975 Jay 30 3.65 Ann 34 3.875 Deb 35 2.125 Meg 38 2.0 Art 40 3.999 Jan 45 4.0 Tom 21 1.685 Meg 38 2.0 Deb 35 2.125 Bob 18 2.5 Joe…arrow_forwardThe goal for Lab07 is to use the provided Student class and create an array of Student objects that is stored in a School object. This program uses a Student class that is provided(picture attached!). The class is placed in its own separate file and should not be altered. This project started with Lab06a and uses the same Student class. Part one of Lab07 is similar to the Lab06b. The difference is that Lab06b used static 1D arrays and Lab07 uses dynamic ArrayList arrays. The output is the same. In part two, adds the linearSearch and the binarySearch methods. Each search method is tested with an existing search record and one that does not exist. Tom 21 1.685 Ann 34 3.875 Bob 18 2.5 Jan 45 4.0 Joe 27 2.975 Sue 19 3.225 Jay 30 3.65 Meg 38 2.0 Art 40 3.999 Deb 35 2.125 7 -1 Ann 34 3.875 Art 40 3.999 Bob 18 2.5 Deb 35 2.125 Jan 45 4.0 Jay 30 3.65 Joe 27 2.975 Meg 38 2.0 Sue 19 3.225 Tom 21 1.685 7 -1arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education