CS210 Lab: Software Engineering Principles Postlab
Postlab Exercise:
This postlab exercise asks you to modify the code for the fraction class.
Click here to download this project
We have decided to change the specifications.
We would like to be able to store a fraction in its proper or improper form.
In it's proper form, it should be reduced.
When a number is converted to proper form, the whole number should be stored.
We should also allow the conversion from improper to proper and from
proper to improper.
However, we will assume that the input remains in numerator/denominator format.
To summarize, we will have data members:
We will have member functions:
- Initialize--
takes two integer values and stores them in
num and denom
- NumeratorIs--
returns the value of num
- DenominatorIs--
returns the value of denom
- Reduced--
checks whether the numerator and denominator
have a common factor and, if they do, divides
both by the common factor. Stores the result
in num and denom.
- IsZero--
tests whether the fraction is zero.
A fraction is zero if the numerator is zero
and the denominator is 1.
- IsNotProper--
tests if the numerator is greater than or
equal to the denominator.
- ConvertToProper--
reduces the fraction, and stores the whole-number
part and leaves the remaining part in the fraction.
- ConvertToImproper--
converts the whole number back into a fraction.
Whole will be 0 and fraction will be the reduced
improper form.
To Do:
- Implement this as code.
- Develop a test plan for the modified ConvertToProper and
the new ConvertToImproper member functions
For Answers, click
here
Back to Software Engineering Principles Lab click
here
Copyright: Department of Computer Science, University of Regina.