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 from the user and display various statistics: sum, average, minimum, and maximum.
Outcomes
- Successfully populate a
std::vectorfrom a user (by reading fromstd::cin) - Correctly pass and return
std::vectorto other functions - Use C++ Standard Library algorithms to assist with computing statistics
- 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
taris the name of the command we are running- the
xindicates to eXtract - the
findicates there is a File we wish to operate on handout.taris the file we wish to extract
The handout will contain several files:
Statistician.h– header file for required methods (do not change)Statistician.cpp– source file for required methodsDriver.cpp– source file for driver applicationMakefile– makefile file to assist with compilation (do not change)
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
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 named 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
taris the command we are giving- the
cindicates to Create a new tar file - the
fspecifies the Filename we are operating on (creating) Driver.cppandStatistician.cppare files that will be added to the tarfile
Grading
- [20pt] Reading a vector from standard input with
populate - [10pt] Correctness of
minimum - [10pt] Correctness of
maximum - [10pt] Correctness of
sumOfValues - [10pt] Correctness of
average - [20pt] Exact format for input/output
- [20pt] Documentation / Formatting – NOT AUTOGRADED
- NOTE: if your program does not compile/run, the highest score you will earn will be a 20/100