Operator overloading

Assignment Help Basic Computer Science
Reference no: EM13324953

C++ programming
Operator Overloading
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 and so on we mean that e v e r y d a y fractions, 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. Include a default constructor that initializes an object to 0 (that is, 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 the following operators so that t h e y correctly apply to the type Rational: ==, <, <=, >, >=, +, -, *, and /. The main() should test your class and the functions.
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.
Filename: rational.cpp

Reference no: EM13324953

Questions Cloud

Identify one example of fallacious reasoning : Identify one example of fallacious reasoning. Tell us the context in which the fallacy occurred. Tell us about the fallacy. What were the words or the reasoning involved?
What is the magnitude of the net electric field : Two particles are fixed to an x axis: particle 1 of charge -4.18 × 10-7 C is at the origin and particle 2 of charge +4.18 × 10-7 C is at x2 = 13.9 cm. what is the magnitude of the net electric field
How each of the intrinsic html objects interacts : You are to write two versions of this assignment. One using HTML and VBScript and one using HTML and Javascript.
Estimate the charge magnitude : Two tiny spheres have the same mass and carry charges of the same magnitude. The mass of each sphere is 5.04 10-6 kg. Determine the charge magnitude
Operator overloading : Operator Overloading
At what time does the second car catch up with the first one : A "rocket car" is launched along a long straight track at t = 0 s. It moves with constant acceleration a1 = 1.2m/s2. At what time does the second car catch up with the first one
Explain what is the solubility of m(oh)2 in pure water : What is the solubility of M(OH)2 in pure water. B. What is the solubility of M(OH)2 in a .202 M solution of M(NO3)2? Ksp=5.45E-18
Cross-examination by partys attorney during deposition : Do you think cross-examination by a party's attorney during a deposition is common? Why or why not? There are several reasons any particular case will go to trial. Some of these may also affect the pretrial conference. Which ones and why?
Develop a two-page brief on email or phishing scams : Develop a two-page brief on email or phishing scams reported within the past six months. Indicate who they were directed to, who might be behind these attacks and why. Also address any similarities/differences between similar previous attacks.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  What properties can be added in referential integrity

What properties can be added in referential integrity

  1/(2n) is less than or equal to [ 1 * 3 * 5 *...* (2n - 1)]

Prove that 1/(2n) is less than or equal to [ 1 * 3 * 5 *...* (2n - 1)] / (2 * 4 *...* 2n) whenever n is a positive integer.

  Show how an assembly might replace this pseudo-instruction

show how an assembly might replace this pseudo-instruction with the true instructions to achieve the same effect. You solution must observe MIPS register use conventions.

  How many total bits are required for a direct-mapped cache

How many total bits are required for a direct-mapped cache with 16 KB of data and 4-word blocks, assuming a 32-bit address.

  Steps to follow to verify local police department-s findings

Your computer investigation firm has been hired to verify the local police department's findings on a current case. What do you need to ask the police investigator for, and what procedures should you follow?

  What is the simplest form of the boolean function

What is the simplest form of the Boolean function y′ . (x + y)?

  What is the programming model of a hcs12 microcontroller

What is the programming model of a HCS12 microcontroller

  Which processes were loaded normally is running in safe

Next, boot the system into safe Mode and use Task Manager to list running processes. Which processes that were loaded normally are not loaded when the system is running in safe Mode?

  Explain response time for jobs in observed system

Explain the response time for jobs in observed system? As function of N, number of terminals, give high-load bounds for throughput and response time; also provide low-load bounds.

  System designer to make sure implementation went smoothly

In new system implementation, what would you do as lead system designer to make sure implementation went smoothly?

  Write the communication in the neuron work

Write down the communication within the neuron work? Write down the communication between the neuron work?

  Create a jsp that returns the name of the browser

I need to create a JSP that returns the name of the browser that is being used to display the page

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd