array_t
class presented in class,
make the class templated to allow instantiaion of
array_t<int>
and
array_t<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_t<int> iarr(10);
iarr.randseed();
iarr.randfill();
std::cout << "iarr:\n" << iarr << std::endl;
std::cout << "min: " << iarr.min() << std::endl;
std::cout << "max: " << iarr.max() << std::endl;
std::cout << std::endl;
std::cout << "Enter number to find: ";
std::cin >> seeknum;
std::cout << seeknum << " is at position " << iarr.find(seeknum) << std::endl;
}
seed = 1337 iarr: [0] = 1 [1] = 86 [2] = 24 [3] = 21 [4] = 30 [5] = 74 [6] = 89 [7] = 64 [8] = 21 [9] = 68 min: 1 max: 89 Enter number to find: 64 64 is at position 7
tar.gz
archive of your lab02/ directory, including:
README
file containing
Makefile
.h
headers and .cpp
source)
make clean
before tar
)
sendlab
notes