CS 215 - Fundamentals of Programming II
Spring 2008 - Project 1
20 points


Out: January 23, 2008
Due: January 30, 2008


Reminder: Programming Projects (as opposed to Homework problems) are to be your own work. See syllabus for definitions of acceptable assistance from others.


The instructor's format for class specifications is defined in the on-line handouts An Analysis and Design Style Guideline and An Analysis and Design Style Guideline for Classes. (They are used by the instructor in CS 210.) Links to these handouts also is provided on the CS 215 home page.


Problem Statement

A rational number is a number that can be expressed as an integer or the quotient of an integer divided by a nonzero integer. Expressed as a/b, a is called the numerator and b is called the denominator. Results of the binary arithmetic operations on rational numbers represented by a/b and c/d are as follows:


Operator

Result

a/b + c/d

(ad + bc) / bd

a/bc/d

(ad - bc) / bd

a/b * c/d

ac / bd

a/b / c/d

ad / bc, where c not equal to 0


In addition, a/b = c/d when ad = bc. From this relationship, the equality and relational operations can be defined.


Consider the following specification for a Rational class that models a rational number. The analysis of each operation is given formally, but the design of each operation is given informally in English.


Specification for Rational Class

Attributes:


Objects

Type

Name

numerator of the Rational

int

numerator

denominator of the Rational

int

denominator


The class invariant is as follows (i.e., all valid objects must meet these conditions):



Operations


Objects

Type

Kind

Movement

Name

output stream

ostream

variable

received, passed back, returned

out

a Rational

Rational

variable

received

aRational

Assignment

Write the implementation for this Rational class. Note that the function names for this class must be as specified above. The Rational class definition and friend operator function prototypes should be put in header file rational.h with suitable compilation guards. The implementations of the Rational class and friend operator functions should be put in source file rational.cpp.


Write a main program that adequately tests your Rational class in file rationaldriver.cpp. This program should demonstrate that your Rational class meets all of the specifications given above. Part of your grade will depend on how well you test your class. In addition, the submission system will run a specific driver program to test your Rational class.


The file except.h with the RangeError exception class definition is available on csserver in directory /home/hwang/cs215/lecture07 and on the course website under January 25. You can copy the file by changing directories to where you want to put it and typing:


cp /home/hwang/cs215/lecture07/except.h .


(The last '.' indicates the current directory.) You should not modify this file.


You must submit a makefile named Makefile.project1 for your project. Submissions without working makefiles will be assessed up to a 3-point penalty as indicated in the syllabus. It should conform to the examples given in the handout Very Basic make and demonstrated in class.


REMINDER: Your project must compile for it to be graded. Submissions that do not compile will be returned for resubmission and assessed a late penalty. Submissions that do not substantially work also will be returned for resubmission and assessed a late penalty.


Follow the guidelines in the C++ Programming Style Guideline handout. As stated in the syllabus, part of the grade on a programming project depends on how well you adhere to the guidelines. The grader will look at your code listing and grade it according to the guidelines.


What to submit

Electronically submit a tarfile containing (only) Makefile.project1, rational.h, rational.cpp, and rationaldriver.cpp as explained in the handout Submission Instructions for CS 215. Also hand in hard-copy printouts of these files as explained in the handout. Do not submit except.h, object files, or executable files.

01/22/08 5 of 5