Download Category:

Rational CPP.zip - (400.33 KB)
Rational CPP/Debug/
Rational CPP/Debug/cl.command.1.tlog
Rational CPP/Debug/CL.read.1.tlog
Rational CPP/Debug/CL.write.1.tlog
Rational CPP/Debug/link.1624.read.1.tlog
Rational CPP/Debug/link.1624.write.1.tlog
Rational CPP/Debug/link.1624-cvtres.read.1.tlog
Rational CPP/Debug/link.1624-cvtres.write.1.tlog
Rational CPP/Debug/link.command.1.tlog
Rational CPP/Debug/link.read.1.tlog
Rational CPP/Debug/link.write.1.tlog
Rational CPP/Debug/link-cvtres.read.1.tlog
Rational CPP/Debug/link-cvtres.write.1.tlog
Rational CPP/Debug/mt.command.1.tlog
Rational CPP/Debug/mt.read.1.tlog
Rational CPP/Debug/mt.write.1.tlog
Rational CPP/Debug/Produce CPP.exe
Rational CPP/Debug/Produce CPP.exe.embed.manifest
Rational CPP/Debug/Produce CPP.exe.embed.manifest.res
Rational CPP/Debug/Produce CPP.exe.intermediate.manifest
Rational CPP/Debug/Produce CPP.ilk
Rational CPP/Debug/Produce CPP.lastbuildstate
Rational CPP/Debug/Produce CPP.log
Rational CPP/Debug/Produce CPP.pdb
Rational CPP/Debug/Produce CPP.write.1.tlog
Rational CPP/Debug/Produce CPP_manifest.rc
Rational CPP/Debug/rational.obj
Rational CPP/Debug/rc.command.1.tlog
Rational CPP/Debug/rc.read.1.tlog
Rational CPP/Debug/rc.write.1.tlog
Rational CPP/Debug/vc100.idb
Rational CPP/Debug/vc100.pdb
Rational CPP/Produce CPP.sln
Rational CPP/Produce CPP.suo
Rational CPP/Produce CPP.vcxproj
Rational CPP/Produce CPP.vcxproj.filters
Rational CPP/Produce CPP.vcxproj.user
Rational CPP/Question.txt
Rational CPP/rational.cpp
Rational CPP/Screenshot_1.png

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

(By 1/2 and so on we mean that everyday

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 de?ne

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

Write a Review

Get a fresh solution of this question. Ask it now to our experts.

Ask Your Question

We have verified professionals who are ready to answer your question.


Save Time and Money

We choose experts who can quickly answer your question and that suit your budget.


Get Your Answer

Your satisfaction is 100% guaranteed. You can keep on asking questions until you get the answer you need.