Problem Solving with C++ (9th Edition)
Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 11.2, Problem 18STE

Following is the definition for a class called Percent. Objects of type Percent represent percentages such as 10% or 99%. Give the definitions of the overloaded operators >> and << so that they can be used for input and output with objects of the class Percent. Assume that input always consists of an integer followed by the character ‘%’, such as 25%. All percentages are whole numbers and are stored in the int member variable named value. You do not need to define the other overloaded operators and do not need to define the constructor. You only have to define the overloaded operators >> and <<.

#include <iostream>

using namespace std;

class Percent

{

public:

friend bool operator ==(const Percent& first, const Percent& second);

friend bool operator <(const Percent& first, const Percent& second);

Percent();

Percent(int percentValue);

friend istream& operator >>(istream& ins, Percent& theObject);

//Overloads the >> operator to input values of type

//Percent.

//Precondition: If ins is a file input stream, then ins

//has already been connected to a file.

friend ostream& operator <<(ostream& outs, const Percent& aPercent);

//Overloads the << operator for output values of type

//Percent.

//Precondition: If outs is a file output stream, then

//outs has already been connected to a file.

private:

int value;

};

Blurred answer
Students have asked these similar questions
C++   Write a class named Car with member variables: yearModel, Make, Speed as private.Use a Constructor that accepts year model and make as arguments. It should also assign 0 to thespeed use accelerate and brake functions that add and subtract 5 from speed each time it is called.Demonstrate the class in a program that creates a Car object, and then calls the acceleratefunction 5 times. After each call to the accelerate function, get the current speed of the car anddisplay it. Then, call the brake function five times. After each call to the brake function, get thecurrent speed of the car and display it
Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data of the class—the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it’s declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form. Provide public member functions that perform each of the following tasks: Adding two Rational numbers. The result should be stored in reduced Subtracting two Rational numbers. The result should be stored in reduced Multiplying two Rational numbers. The result should be stored in reduced Dividing two Rational numbers. The result should be stored in reduced Printing Rational numbers in the form a/b, where a is the numerator and b is the denominator. Printing Rational numbers in floating-pointformat
in c++ Write a class named Mobile that holds data about a mobile in a retail store. The class should have the following member variables: Name/brand. A string that holds name of the brand of phone. unitsOnHand. An int that holds the number of units currently in inventory. price. A double that holds the retail price. Write a constructor that accepts arguments for each member variable, appropriate functions that store values in these member variables, and accessor functions that return the values in these member variables.  Once you have written the class, Write another class Store (link list) having Mobile as a node then provide function to insert new mobile in list and to Delete a mobile and to display all mobiles. Write a main program that shows all the functionality. Note: you have to implement all scenarios (insert and delete at start, end, in between).

Chapter 11 Solutions

Problem Solving with C++ (9th Edition)

Ch. 11.1 - Given the following definitions: const int x = 17;...Ch. 11.2 - What is the difference between a (binary) operator...Ch. 11.2 - Prob. 13STECh. 11.2 - Suppose you wish to overload the operator = so...Ch. 11.2 - Prob. 15STECh. 11.2 - Give the definition for the constructor discussed...Ch. 11.2 - Here is a definition of a class called Pairs....Ch. 11.2 - Following is the definition for a class called...Ch. 11.3 - Give a type definition for a structure called...Ch. 11.3 - Write a program that reads in five amounts of...Ch. 11.3 - Change the class TemperatureList given in Display...Ch. 11.3 - Prob. 22STECh. 11.3 - If a class is named MyClass and it has a...Ch. 11.4 - Prob. 24STECh. 11.4 - The following is the first line of the copy...Ch. 11.4 - Answer these questions about destructors. a. What...Ch. 11.4 - a. Explain carefully why no overloaded assignment...Ch. 11 - Modify the definition of the class Money shown in...Ch. 11 - Self-Test Exercise 17 asked you to overload the...Ch. 11 - Self-Test Exercise 18 asked you to overload the...Ch. 11 - Prob. 1PPCh. 11 - Define a class for rational numbers. A rational...Ch. 11 - Define a class for complex numbers. A complex...Ch. 11 - Enhance the definition of the class StringVar...Ch. 11 - Define a class called List that can hold a list of...Ch. 11 - Define a class called StringSet that will be used...Ch. 11 - This programming project requires you to complete...Ch. 11 - Redo Programming Project 6 from Chapter 9 (or do...Ch. 11 - Solution to Programming Project 11.12 To combat...Ch. 11 - Repeat Programming Project 11 from Chapter 10 but...
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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
What is Abstract Data Types(ADT) in Data Structures ? | with Example; Author: Simple Snippets;https://www.youtube.com/watch?v=n0e27Cpc88E;License: Standard YouTube License, CC-BY