CMSC 160 -- Lab 7

Lab 7

Getting Started

Log into the computer science server and use wget and tar to download your starter code.
  1. Use wget to download the file at http://cs.longwood.edu/courses/cmsc160/f17/files/lab7.tgz
  2. Uncompress the lab7.tgz file by using tar -xvzf lab7.tgz
  3. Use ls to see that there is a new directory called lab7
  4. Use cd lab7 to change directory to the lab7 directory

File redirection

The command line provides a feature, called redirection, to allow your program to read (or write) output from other files and programs. The command ./lab7 < test1.txt would read input from the file test1.txt instead of the keyboard! Likewise, the command ./lab7 > result1.txt would write all output to the file result1.txt. We will utilize file redirection to help with our test cases.

The Problem

In this lab we will:
  1. write test cases using files
  2. use if statements
  3. use functions
  4. use loops
  5. use vectors
In this lab we will use vectors to generate some statistics. You will read in integers (cin) and store the words in a vector. You are to write the following functions:
  1. smallest
    input: a vector of ints
    output: the smallest value in the input
    
  2. largest
    input: a vector of ints
    output: the largest value in the input
    
  3. average
    input: a vector of ints
    output: the average of the ints in the vector (what is the return type?)
    
  4. isSorted
    input: a vector of ints
    output: returns true (a boolean value)  if the vector is in ascending or descending order
    
  5. nonNegativeValues
    input: a vector of ints
    output: a vector containing all the integers in the input which are not negative
    

Remember, you will be graded on style, syntax, functionality, test cases, and correctness.

Handin

When you are done you may hand in your lab by using make handin.

The lab is due at 11:59pm Oct. 10th 2017.