CS 23
60 pts., final code due Mar. 19
A rational number is the ratio of two integers. Design a rational class with the following operations:
The constructor should take zero, one, or two arguments (initialize to 0, an integer, or a rational, respectively). Again, use default arguments.
The rational class should be implemented in the files rational.cc and rational.h, as we've been doing in class.
Write a small driver program to demonstrate and test the rational class. This program should be put in the file main.cc. In addition to testing the obvious (that rationals can be added, subtracted, displayed, etc.), the program should test the following conditions:
This is optional. If you elect this option, it will count for 30% of your homework grade. The due date is Mar. 12.
Turn in your design of the rational class. This consists of the file rational.h and a stub version of the file rational.cc Each of the stub functions should be documented with pre- and post-conditions.
Here's what I mean be a stub function:
// Prototype from .h file: char *strcpy(char *dest, char *src); // Stub function from .cc file: // Pre-Conditions: // Post-Conditions: char *strcpy(char *dest, char *src) { }In words, a stub function has no body.
Those who turn-in design reviews will be e-mailed my versions of the two design files. You will be on your honor to not share these files with those not electing this option.
E-mail me a script showing a compilation and sample run. Turn-in printed copies of the three source files in class.