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, 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 a program and input three decimal in main and pass them to the defualt constructor of the class. show the result of the multiplication of three numbers. in c++.
Please answer in Java 1. A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design the class Point that can store and process a point in the x-y plane.-We should then perform operations on a point, such as showing the point, setting the coordinates of the point, printing the coordinates of the point, returning the x-coordinate, and returning the y-coordinate. -Write a test program to test various operations on a point.  The class Point should contain the following methods and data members: 1. protected members x and y2. default constructors3. constructors with parameters4. setPoint(x)5. getX()6. getY()7. toString()8. equals(x)9. makeCopy(x)10. getCopy()11. printPoint()  The output should show the following: -Initialize myPoint = [5.00,4.00]-Initialize yourPoint = [0.00, 0.00]-Print both of these objects-Set yourPoint to [5.00, 45.00] and print it-Determine if the 2 points are equal or not-Change the myPoint coordinates to [6.00, 9.00]-Print this new myPoint…
I need help in coding these two classes(dorm and room) in JAVA from the following information-> *A dormitory has a name and has several rooms. When a dormitory is built, the name and the number of rooms should be provided. In some cases, the maximum capacity of the rooms is also provided. If there is no maximum capacity set, each room can accommodate at most 6 guests. *The rooms are then automatically created and added to the dormitory, numbered from 1, 2, 3, and so on, representing the room number. Once the room number is assigned to the created room, this information cannot be edited anymore. *The dormitory can accept guests into a given room number. Each guest has a name and nationality. If the capacity is full or an invalid room number is provided, the guest will not be added and this method returns false. Otherwise, this method returns true. *The dormitory also has a method to return the guests in a given room number. If an invalid room number is provided, the method will…

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

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