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

bartleby

Videos

Textbook Question
Book Icon
Chapter 11, Problem 2PP

Define a class for rational numbers. A rational number is a number that can be represented as the quotient of two integers. For example, 1/2, 3/4, 64/2, and so forth are all rational numbers. (By 1/2, etc., we mean the everyday meaning of the fraction, not the integer division this expression would produce in a C++ program.) Represent rational numbers as two values of type int, one for the numerator and one for the denominator. Call the class Rational.

Include a constructor with two arguments that can be used to set the member variables of an object to any legitimate values. Also include a constructor that has only a single parameter of type int; call this single parameter wholeNumber and define the constructor so that the object will be initialized to the rational number wholeNumber/1. Also include a default constructor that initializes an object to 0 (that is, to 0/1).

Overload the input and output operators >> and <<. Numbers are to be input and output in the form 1/2, 15/32, 300/401, and so forth. Note that the numerator, the denominator, or both may contain a minus sign, so −1/2, 15/32, and −300/−401 are also possible inputs. Overload all of the following operators so that they correctly apply to the type Rational: ==, <, <=, >, >=, +, −, *, and /. Also write a test program to test your class.

(Hints: Two rational numbers a/b and c/d are equal if a*d equals c*b. If b and d are positive rational numbers, a/b is less than c/d provided a*d is less than c*b. You should include a function to normalize the values stored so that, after normalization, the denominator is positive and the numerator and denominator are as small as possible. For example, after normalization 4/−8 would be represented the same as −1/2. You should also write a test program to test your class.)

Blurred answer
Students have asked these similar questions
Write C++ code of class Complex that would represent a complex number. A complex number consists of a real part and an imaginary part and usually displayed in the form  + ἰ (a is real part while b is imaginary). This class should consists of void show( ) to display the complex number in the form a+ bi ( if imaginary part is positive) or a – bi ( if imaginary part is negative), void input( ) to assign values to the object of the Complex class. This Complex class should have two constructors i.e. default and parameterized. The object instantiated using default constructor should call input() to assign value to the real and imaginary part of the object. Also write code to overload + operator to add two complex numbers (objects). Comment your program properly and mention mutator and accessor as well. All functions should be inline except the constructors. Use this pointer wherever class data members are referred.
Define a new C++ class named “PayStub” that manages pay information: numberof hours (integer), hourly pay rate (double).The total payout amount will be calculated based on overtime. Any hour that ismore than 40 hours will be paid at a 1.5 pay rate.For example, with the hourly pay rate of $10.0 and if the number of hours is 40,the payout amount will be 400 and if the number of hours is 50 it will be (40 * 10)+ (10 * 15) = 550Please note that because the payout is a calculated value, it should not be part ofthe data members to make the object as small as possible.The class must provide at least the following two methods: • toString method that returns the string containing all the information aboutthe paystub including the total payout amount.For example, here is the output for different paystubs40 hours at $10.0 an hourHOURS(40) RATE($10.00) PAYOUT($400.00)50 hours at $10.0 an hourHOURS(50) RATE($10.00) PAYOUT($550.00)60 hours at $10.126 an hourHOURS(60) RATE($10.13)…
C++ Write a program that converts a number entered in Roman numerals to a positive integer. Your program should consist of a class, say, romanType. An object of type romanType should do the following: Store the number as a Roman numeral. Convert and store the number as a positive integer. Print the number as a Roman numeral or positive integer as requested by the user. The integer values of the Roman numerals are: M 1000D   500C   100L    50X    10V     5I     1 Test your program using the following Roman numerals: MCXIV, CCCLIX, and MDCLXVI.

Chapter 11 Solutions

Problem Solving with C++ (10th 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...Ch. 11 - Do Programming Project 19 from Chapter 8 except...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
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
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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