CSCI 362: Statistician Redux

An Enhanced Statistician

Overview

You are tasked with implementing an enhanced number analysis program. You will be expected to populate a vector with numbers read in from the user and display a view statistics: sum, average, minimum, and maximum

Outcomes

  1. Successfully populate a std::vector from a user (by reading from std::cin)
  2. Correctly pass and return std::vector to other functions
  3. Use C++ Standard Library algorithms to assist with computing statistics
  4. Adhere to strict formatting requirements

File Structure

Downloading the handout file will give you a handout.tar file. You can extract the contents of the tar file by providing the following command:

tar xf handout.tar

The handout will contain several files:

Required Functions

Statistician.cpp

// Finds the largest value in the passed vector
// Assumes nums is not empty
float
maximum (const std::vector<float>& nums);


// Finds the smallest value in the passed vector
// Assumes nums is not empty
float
minimum (const std::vector<float>& nums);


// Finds the sum of values from the passed vector
// Should return zero if the vector is empty
float
sumOfValues (const std::vector<float>& nums);


// Finds the average of all values from the passed vector
// assumes nums is not empty
float
average (const std::vector<float>& nums);


// Creates and returns a new vector. Reads in count number
// of values from the user by prompting for each one
// should return an empty vector if count <= 0
std::vector<float>
populate (int count);

Driver.cpp

// Entry point to the program
// The program should perform the following tasks:
// 1. Prompt the user to enter the count of numbers
// 2. populate and return a vector with values read from the user
// 3. Report the sum, average, min, and max
int
main(int argc, char* argv[]);

Sample Input/Output

Enter number of values ==> 5
Enter value ==> 1.5
Enter value ==> 5.5
Enter value ==> 2.5
Enter value ==> 3.5
Enter value ==> 4.5

The statistics of all 5 values are:
  Sum: 17.5
  Avg: 3.5
  Min: 1.5
  Max: 5.5

Compiling and Running your program

As a reminder, you can use make to compile your program:

[username@machine statredux]$ make
g++ -g -Wall   -c -o Driver.o Driver.cpp
g++ -g -Wall   -c -o Statistician.o Statistician.cpp
g++ Driver.o Statistician.o   -o Driver

Once you see those commands run, a program – Driver should now exist in your directory. Typing ls will list the contents of the directory.

[username@machine statredux]$ ls
Driver  Driver.cpp  Driver.o  Makefile  Statistician.cpp  Statistician.h  Statistician.o

Running the Driver can be done by prepending ./ before the name of the program in the current directory:

[username@machine statredux]$ ./Driver
Enter number of values ==> 
...

Handin

To automatically generate a handin tarfile, you can invoke:

make handin

and submit the generated handin.tar to autolab

If you wish to make handin.tar from scratch you can alternatively invoke:

tar cf handin.tar Driver.cpp Statistician.cpp

Grading