CPSC 212-002 Computer Science IV
(Data Structures and Algorithms)

Fall 2009
15:30-16:45TTH Daniel 415
Assignment 1

Objectives:
To learn templated class structure, access to (usage of) member functions

Due date:
09/03/09

What to hand in:
A tar.gz archive of your asg1/ directory, including:
  1. A README file containing
    1. Course id--section no
    2. Name
    3. Assignment description
    4. Brief solution description (e.g., program design, description of algorithm, etc., however appropriate).
    5. Lessons learned, identified interesting features of your program
    6. Any special usage instructions
  2. Makefile
  3. source code (.h headers and .cpp source)
  4. object code (do a make clean before tar)
How to hand in:
See handin notes

Description:
  1. Using the Array class presented in class, make the class templated to allow instantiaion of Array<int> and Array<float> objects
  2. Provide the member functions
    	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;
    
    		

  3. Your code should be such that the following 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;
    }
    		
  4. Sample output:
    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