The general presentation of your document counts! (This includes qualities such as neatness, formatting, and legibility.)
int min() const; // return min value in list
int max() const; // return max value in list
int find(int val) const; // return index of argument val
void randfill(); // fill up member arr with random ints
Use the Unix-supplied routine rand()
to generate
(pseudo-) random numbers when filling the array in member
function randfill()
. (Note: there is no need to
re-seed the random number generator, that's already been done
for you.)
main()
routine works unaltered:
int main()
{
int seeknum;
IntArray Arr(10);
// using "static" object
Arr.randseed();
Arr.randfill();
cout << "printing Arr\n" << Arr << "\n";
cout << "min: " << Arr.min() << endl;
cout << "max: " << Arr.max() << endl;
cout << endl;
cout << "Enter number to find: ";
cin >> seeknum;
cout << seeknum << " is at position " << Arr.find(seeknum) << endl;
}
seed = 809191 printing Arr [0] = 12802 [1] = 5781 [2] = 10707 [3] = 20155 [4] = 32739 [5] = 19420 [6] = 1169 [7] = 6289 [8] = 17350 [9] = 4702 min: 1169 max: 32739 Enter number to find: 5781 5781 is at position 1
main()
so that a "dynamic" object
is used, i.e., where the size of the object's array is
determined by the user. The top few lines of
main()
should now look like this:
int main()
{
int num = 0;
int seeknum;
IntArray *Arrp;
// using "dynamic" object
cout << "Enter list size: ";
cin >> num;
.
.
.
Note the difference in the use of object, Arr
,
above, and the pointer to object, *Arrp
, here.
Hint: How is Arrp
allocated and
initialized?
ostream& operator<<
so that it
works for the pointer to object, Arrp
, as well
as for the object itself, Arr
, avove. (The code
for the latter is already provided.)
+
operator.
+
operator should be implemented so that
the following code works:
Arr3 = Arr1 + Arr2;
cout << "printing Arr3\n" << Arr3 << endl;
Hint: What should happen when the objects' array sizes
differ?