class to represent rational numbers

Hi, I am having trouble understanding what a set of instructions on my homework means. The part is Casting: Rational numbers should be able to be implicitly cast to floats and double, and implicitly cast from integers. Would anyone be able to explain a little what this could mean? Is it simply casting ints to floats or doubles to make comparison easier?

the full instructions are below if that will help.





Write a class to represent rational numbers. Unlike floating point numbers, rational numbers do not suffer from finite precision. The numbers should be stored in their simplest form. The following operations are required:

Casting: Rational numbers should be able to be implicitly cast to floats and double, and implicitly cast from integers.

Comparison: All of the comparison operators <, > , == , <= , >= . != should be implemented

Arithmetic: All of the arithmetic operators, +, +=, *, *=, /, /= -, -= should be implemented

I/O: Stream insertion and extraction << and >> should be implemented



You must also provide a main program that demonstrates the full capability of your rational number class.
Take a look at this -> http://learnzillion.com/lessonsets/240-convert-rational-numbers-to-decimals

And this -> http://courses.cms.caltech.edu/cs11/material/cpp/donnie/cpp-ops.html

EDIT- it's not a trivial task so hopefully you are motivated to solve the problem. Those specs could be much better though. The Prof obviously doesn't spend any time on them.
Last edited on
Topic archived. No new replies allowed.