tar.gz
archive of your asg1/ directory, including:
README
file containing
Makefile
.h
headers and .cpp
source)
make clean
before tar
)
handin
notes
Array
class presented in class,
make the class templated to allow instantiaion of
Array<int>
and
Array<float>
objects
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 randseed(); // seed random number generator
void randfill(); // fill up member arr with random ints
Use the C stdlib rand()
routine to generate
(pseudo-) random numbers when filling the array in member
function randfill()
, e.g., sample usage:
#include <cstdlib>
srand((unsigned int)1337); // seed generator, do this only once!
// for each new value, get pseudo-random 0 < number < 1
for(int i=0; i<arr.size(); i++)
arr[i] = (float)rand()/(float)RAND_MAX;
main()
routine works unaltered:
int main()
{
int seeknum;
Array<int> Arr(10);
Arr.randseed();
Arr.randfill();
std::cout << "Arr:\n" << Arr << std::endl;
std::cout << "min: " << Arr.min() << std::endl;
std::cout << "max: " << Arr.max() << std::endl;
std::cout << std::endl;
std::cout << "Enter number to find: ";
std::cin >> seeknum;
std::cout << seeknum << " is at position " << Arr.find(seeknum) << std::endl;
}
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