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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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