Absolute C++
Absolute C++
6th Edition
ISBN: 9780133970784
Author: Walter Savitch, Kenrick Mock
Publisher: Addison-Wesley
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 8, 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. ( C + +

By 1/2 and so on we mean the everyday fraction, not the integer division this expression would produce in a 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/l. 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, IS/ 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 the following operators so that they correctly apply to the type Rational: = = , < , < = , > , > = , + , , * , and /. Write a test program to test your class. Hints: Two rational numbers a/b and c/d are equal if a equals c *b. If b and d are positive rational numbers, a/b is less than c/d provided is less than c 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.

Blurred answer
Students have asked these similar questions
C++
Code in C++ Language As a cashier, you would always hate those times when customers choose to take back their order since you'd always summon your manager and yell, "Ma'am pa-void!" No matter how you hate it, you always have to do it since you have no other choice.   Given (1) an array of prices of the items, (2) another array of the items the customer wishes to take back, and (3) the customer's payment, print the change of the customer. Input: The first number indicates the number of items "n" brought to the cashier. The next "n" numbers are the prices of the items. The next number indicates the number of items "m" that the customer wants to take back and not proceed. It is assured that 0 <= m <= n. The next "m" numbers are the items to be void that ranges from item 1 to item "n". The final number is the customer's payment. It is also assured that the given payment >= final price of items. INPUT: 5 103.65 650.95 10.25 1067.30 65.18 2 1 5 2000.00 Output:  The change…
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.

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