Project 3 Discussion


1. It is suggested that you write your code in the following order:


2. Negative numbers are allowed.

3. You must catch the error where an object's "value" member has the potential to be

You must catch this error in all appropriate places (hint: this includes the constructor and setPrecision). Use the following algorithm:

IF (number out of range) Try to reduce the number to fit into an int IF (reduced number fits into an int) Tell the user that precision has been reduced Continue with the reduced number ELSE Tell the user that the number is unreliable Continue with the unreliable number

4. Constructor

Examples:

Fixed f(1.2345, 4) --> value = 12345, precision = 4
Fixed f(1.2345, 2) --> value = 123, precision = 2
Fixed f(1.2345, 0) --> value = 1, precision = 0
Fixed f(1.2345, 6) --> value = 1234500, precision = 6

You must do error checking on precision. Use the following algorithm:

IF (precision < 0) Set precision = 2

5. Overloading of <<

Examples

value = 12345, precision = 3 cout << f; --> 12.345 value = 12345, precision = 6 cout << f; --> 0.012345

To avoid imprecise results, DO NOT use your overloaded float cast operator. (Hint: think of how to display the integer and fractional portions of the Fixed number separately.)

6. setPrecision

Examples

value = 12345, precision = 2 f.setPrecision(4) --> value = 1234500, precision = 4 value = 12345, precision = 2 f.setPrecision(1) --> value = 1234, precision = 1

You must do error checking on the precision argument. Use the following algorithm:

IF (new_p < 0) Send message to user Leave precision and value alone

7. Assignment

Must be able to do:

Fixed a, b, c; a = b = c;

Must be able to do:

Fixed a, b; float f; a = b = f;

Assume 2 for the precision of the float.

Assume no overflow for the float.

8. Cast from Fixed to float

There is no return type in the prototype

operator float() const; // float is the implicit return type

However, you must have a return statement in the function that returns a float.

Example:

Fixed a(1.23, 2); // value = 123, precision = 2 float f; f = float(a); // f = 1.23

Note that the value and precision of "a" will NOT change.

9. Arithmetic (+, -, *, /)

Precision of the answer will have the precision of the operand with the greater precision.

10. Trig and Power

Correction: "exp" function should be called "pow"

"pow" raises a Fixed to an int power.

--------
Last modified:    Saturday, 11-Mar-2000 14:20:02 EST