EBK PROBLEM SOLVING WITH C++
EBK PROBLEM SOLVING WITH C++
9th Edition
ISBN: 9780133834505
Author: 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
Consider the following class and answer questions after this class     #include <string>   using namespace std;   class Account   {       public:          Account(string accountName, int initialBalance)         {                name=accountName;                if (initialBalance > 0) {                balance = initialBalance;                }         }       void deposit(int depositAmount) {               if (depositAmount > 0) {               balance = balance + depositAmount;                }        }       int getBalance() const {              return balance;        }       void setName(string accountName) {             name = accountName;       }       string getName() const {            return name;       }   private:       string name;       int balance; };   a)     Rewrite the above class. Write prototype of all functions inside class and definition outside. b)    Write two friend functions to change the value of name and balance. c)     Write a print function and…
Given the following class definition: class employee{public:    employee();    employee(string, int, double);    employee(int, double);    employee(string);    void setData(string, int, double);    void print() const;    void updatePay(double);    int getNumOfServiceYears() const;    double getPay() const;private:    string name;    int numOfServiceYears;    double pay;}; Create a class parttime derived from the above class that includes private members payRate and hoursWorked of type double along with a constructor and the definition of a print function that prints out all information from the base and derived class. Provide a test program that would demonstrate the working parttime class. Note: You can assume all code is stored in a single file.
Assignment Question : #include <iostream> using namespace std; class Animal { protected:     int length, height;  public:     void set_values (int l, int h)       { length = l; height = h; }         virtual int cage_size (void) =0; };                                                                       A. Based on the above class definition, provide the derived classes below that will override the function cage_size from the base class Animal: i.Elephant, cage_size  = 1.5 x length x height ii.Giraffe, cage_size  = 2.5 x length x height   B. Write the complete main () function that will create the object Elephant and Giraffe. Insert their length and height to calculate their cage_size.   Note: A virtual function is a member function which is declared within a base class and is expected to be re-defined (overridden) by a derived class.

Chapter 11 Solutions

EBK PROBLEM SOLVING WITH C++

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
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
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