Introduction to Computer Science:
Quiz 9:  Vectors, Random Numbers, and SelectionSort
 Sewickley Academy, 2000-2001

See Course Home Page.
 
Date of Quiz: Thu Nov-16

Note:  This is a programming quiz.  You must use Visual C++.  You must begin with a new project, and you may not use any notes or any pre-written code.

Your task is to write the missing portions of the code below:  That is:
    loadVectorWithRandomElements(),
    printVector(), and
    selectionSort().

Good luck.

     // quiz9.cpp

     #include <stdio.h>
     #include <iostream.h>
     #include <stdlib.h>
     #include "apvector.h"

     typedef apvector<int> intVector;
     typedef intVector& intVectorByReference;

     const int MAX_ELEMENTS_TO_PRINT = 6;
     const int BIG_NUM = 99;

     void printVector(intVectorByReference v)
     {
      // YOU WRITE THIS, PART 1 of 3
      // This prints up to MAX_ELEMENTS_TO_PRINT
      // elements from vector v, placing
      // ellipsis (...) in the middle if elements
      // are skipped.
    }

     void selectionSort(intVectorByReference v)
     {
      // YOU WRITE THIS, PART 2 of 3
      // (be sure it sorts largest-to-smallest)
     }

     void loadVectorWithRandomElements(intVectorByReference v)
     {
      // YOU WRITE THIS, PART 3 of 3
      // This loads the vector v with random elements
      // in the range [0,BIG_NUM]
     }

     void main()
     {
      intVector v;
      int len;
      cout << "Enter the length of the vector: ";
      cin >> len;
      v.resize(len);
      loadVectorWithRandomElements(v);
      printVector(v);
      getchar();
      selectionSort(v);
      printVector(v);
      getchar();
     }

See Course Home Page.