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
In java Develop a function that takes two integers and returns the sum of the values from the first to the second (the two inputs may be in any order). Call the function at least twice with different arguments  Develop a void function PrintLineOfChar that accepts a single character and an integer. The function prints a single line of the character repeated the integer number of times. Call the function at least twice with different arguments.
C++ programAnd please include .h and .cpp
C++

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