Rational
class in C++, but this time using the standard arithmetic and equality operators.. As before, I will be supplying a test
program (rational_test.cpp
) as well as an exception class (rational_exception.h
).
rational.h
and rational.cpp
as two separate exercises in CodeLab. As I will be supplying the other,
the function signatures in the .h
and .cpp
files must match (which is the whole reason I;m doing it this way — to force you to use the
correct signatures). All the function definitions (bodies) should go into the .cpp
, i.e., none should be coded inline in the class declaration
in the .h
.
+=
operator first, since it's a member and has access to the
class representation, and then leverage that functionality to implement the corresponding non-member binary operator (in this case +
).
<<
operator. You can either continue to use your print
function or move its functionality
into the operator.
rational.h
rational.cpp
h
/ .cpp
file; it may also be the case that I made a mistake in the signature). In the event of such (interface) errors, the compiler
will complain about the two functions signatures not matching. In order for you to figure out your error, you should know which signature is your
and which is mine, and where the compiler will be doing the complaining. In 4.1.1, the compiler will encounter the .h
file first (because the
#include
is encountered at the top of the .cpp
file), and thus the error will be manifested when it reaches my signature
(in the .cpp
which won't match. Conversely, in 4.1.2 — where I am providing the .h
file, the error will again appear
in the .cpp
signature, which is yours this time.