312-174
Lab 0
Spring 2000
Preliminary Steps: copy the Lab0 folder from the barrj/CS174/Software/Lab 0 folder to the desktop.
#include "fraction.h"
//-----------------------------------------------------------------------
// Function: fractArray
// Purpose: Constructor.
// PreCondition: None.
// PostCondition: Every element of the internal array contains a
// Fraction object with value 0. Index is 0.
// Return as value of function: None.
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// Function: operator+
// Purpose: Add two arrays.
// PreCondition: Receive a fractArray object, F1.
// PostCondition: Create a new fractArray object. Each element i of
// this object contains the value of the internal array[i]
// + F1.array[i].
// Return as value of function: The new fractArray.
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// Function: insert
// Purpose: Insert a new fraction into the internal array.
// PreCondition: Receive a Fraction object f.
// PostCondition: Set the next available element of the internal array
// to contain f. Index is incremented. If the internal
// array if full, then nothing is changed.
// Return as value of function: None.
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// Function: get
// Purpose: Get the fraction stored at a given element.
// PreCondition: Recieve an index i, where 0<= i < 20.
// PostCondition: return the fraction stored at index i of the internal
// array,
// Return as value of function: a Fraction.
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// Function: biggest
// Purpose: Determine the biggest element in the array.
// PreCondition: None.
// PostCondition: Return the largest Fraction stored in the
// internal array.
// Return as value of function: a Fraction object.
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// Function: printArr
// Purpose: Print the fractions stored in an array.
// PreCondition: None.
// PostCondition: Fractions stored printed on the monitor.
// Return as value of function: None.
//-----------------------------------------------------------------------
Fraction fractArray::printArr()
{
cout << "\n The elements of this array are: " << endl;
for (int i = 0; i < 20; i++)
cout << i << ": " << fractArr[i];
}
Modify the file lab0.cpp to interactively create a list of 5 fractions and test your new class and its methods.
Additional requirements:
Hints:
Return to Student Pages
Return to John Barr's Home Page
Last Modified: 12 January 2000
THIS PAGE MAINTAINED BY:
John Barr, Ithaca College