Help for the Rational Arithmetic assignment Here are some ideas that may help you approach this assignment. For detailed directions, see the instructions in the course packet and the checklist on the website.
void RATshow(Rational r)
{
printf("RATshow\n");
}
The other three functions will be a little more complicated,
because they return a value. It may take a couple of tries to get
the syntax right so that it compiles. Remember that since this
file is an 'implementation', there is no main(), so you will have
to compile it by typing 'gcc RAT.c RATtest.c' (where RATtest.c is
the client program). Don't forget to type #include "RAT.h" at the
top of your program. Otherwise, 'Rational' will be an undefined
type.
When you run this program, you should get a printout that starts
with:
RATinit RATinit RATadd RATshow + RATshow = RATshow
You can trace through the code in RATtest.c to see that you
print the name corresponding to each function called in this
client.
The purpose in doing this step is two-fold. First, it should help
you better understand how the client and implementation relate.
Second, you will now be able to work on the functions in your
implementation one at a time. As you've probably learned by now,
it's best to work on your programs in small steps. You can now do
that, because you have a working implementation.
RATadd 1/2 + 1/3 = 1/3 RATadd 8/9 + 1/9 = 1/9 RATadd 8/9 + 1/9 = 1/9 RATadd 1/200000000 + 1/300000000 = 1/300000000 RATmul 4/17 * 17/4 = 17/4 RATmul 3037141/3247033 * 3037547/3246599 = 3037547/3246599