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
- Successfully populate a
std::vector
from a user (by reading fromstd::cin
) - Correctly pass and return
std::vector
to 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
tar
is the name of the command we are running- the
x
indicates to eXtract - the
f
indicates there is a File we wish to operate on handout.tar
is 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
(const std::vector<float>& nums);
maximum
// Finds the smallest value in the passed vector
// Assumes nums is not empty
float
(const std::vector<float>& nums);
minimum
// Finds the sum of values from the passed vector
// Should return zero if the vector is empty
float
(const std::vector<float>& nums);
sumOfValues
// Finds the average of all values from the passed vector
// assumes nums is not empty
float
(const std::vector<float>& nums);
average
// 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>
(int count); populate
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
(int argc, char* argv[]); main
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
tar
is the command we are giving- the
c
indicates to Create a new tar file - the
f
specifies the Filename we are operating on (creating) Driver.cpp
andStatistician.cpp
are 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