(Latest Revision: Fri Nov 22 22:07 PST 2013 )
SIXTH CS 1500 SOLO PROGRAM: Statistics Calculating Program
OBJECTIVE:
The purpose of this programming assignment is to get practice using files,
arrays, and loops.
ASSIGNMENT SYNOPSIS:
Write a program that reads some numbers from a file and
calculates some statistics.
DETAILS:
For many of the details of the directions regarding this assignment, see
the program shell.
The program shell contains a finished main function. Your assignment is to
carefully read the comments that describe what the other functions in the
program are supposed to do, and then to write the code for those functions. I
expect you to write the functions one at a time and test the program using
appropriate stub code after writing each function. There is a file containing
an extended terminal session
that shows how the finished program is supposed to behave in various test
situations.
INPUT:
You must write the program with certain facts, assumptions, and
preconditions in mind:
- The program is configured to get all its input from a file named
numbers.txt.
- There is no way for you, the programmer, to know exactly what will be in
the file numbers.txt when the program executes.
- You may assume only
- that numbers.txt contains only a series of one or more
integers, interspersed with white space (which could be blank
spaces and/or tabs and/or newlines); and
- that the first number in numbers.txt is the count of how many
numbers are in the rest of the file.
For example, the file might contain:
4 10 40 35 29
The initial 4 in the file means that there are four more numbers in the file.
In this case, the four additional numbers are 10, 40, 35, and 29.
- The assignment directory contains some sample files that could be the
content of numbers.txt. The names of the sample files
are numbers000.txt, numbers005.txt,
numbers043.txt, numbers050.txt, numbers100.txt,
and numbers101.txt.
- Your program must correctly process the contents of numbers.txt,
whatever they turn out to be.
- After you turn your program in for grading, I will test it using some
versions of the numbers.txt file that I have never shown to you.
If your program works incorrectly on any of my versions of
numbers.txt, you will lose substantial credit.
- You may want to make more versions of numbers.txt for your
testing. You may use
this program
for that purpose.
THE DESIGN OF THE PROGRAM:
For this assignment I am requiring you to use the shell program I am giving
you. You are required to add code implementing the functions, to make the
program work correctly, and then to turn the program in like that - a program
derived from my shell by inserting code to implement all the functions - no
more and no less.
In particular, you are not allowed to change anything in the program other
than to add code for the functions. You have to leave the main function the
way it is. You may not add any new functions or take out any functions. You
may not add parameters to functions or take any away, or change a value
parameter to a reference parameter, or vice-versa. You may not add global
constants or variables, or take away any of the global constants.
I expect you to employ good principles of top-down design when you develop the
program.
I want you to have the experience of writing a program that reads from a file
and uses an array. Therefore it is extremely important that you do not make
any modifications in an attempt to avoid using a file or an array.
Because I am going to test all the programs by compiling and running them on
different versions of the input file, I need everyone in the class to use
exactly the same name for the input file. Therefore,
please name your input file numbers.txt and make sure
that your getData function reads the input from that file.
If you don't change the header of getData, and you use the command:
ifstream fin(fname) ;
in your getData function, that will declare an ifstream named fin, and it
will open the numbers.txt file.
Note: Depending on the computing environment in which you develop the program,
you may not understand how to give a file the name numbers.txt. If you
ask about it, I think I or Julie Gorman can help you figure it out.
Note: Come to class to get more discussion of how to design the code for the
functions.
FORM AND FORMATTING REQUIREMENTS:
At the beginning of your program file put a header comment like
this:
/* PROGRAM: Stats Calculator */
/*
Name: Gordon Goodguy
User Name: goodge
Course: CS 1500, Computer Programming I
Instructor: John Sarraille
Date: January 01, 1970
*/
Of course, in place of "Gordon Goodguy," you must put your own full name. In
place of "goodge" put your user (login) name. In place of the Unix epoch,
"January 01, 1970," put the date that you finished the program.
Note that the comment delimiters /* and */ are important. They need to be
placed correctly or you will get compiler errors.
TESTING:
When you make your test script, include all the tests that are in
the extended terminal session.
Also perform two more tests - where the number of integers in the file is one,
and where the number of integers in the file is two.
To make it easier for me to check your work on the script, order your
tests so that as you perform them, the number of items in the test files
gets larger and larger. Also, put the 'unable to open file' test last.
(That's the way I ordered my tests in
the extended terminal session.)
The extended terminal session
also illustrates a way to work with multiple versions of the input file, while
still having just one name for the input file. Different versions of the
input file have names like numbers000.txt, numbers005.txt,
numbers043.txt, numbers050.txt, numbers100.txt,
and numbers101.txt. When we want to use one of the files for
input, say numbers050.txt, we do this unix command first:
cp numbers050.txt numbers.txt
The cp command is the unix command that makes a copy of a file. So
after that command executes, numbers.txt is a copy of
numbers050.txt. So if
we run the program right away after that, the program reads from numbers.txt,
which is the same as numbers050.txt. By doing a cp command before
each program run, we can test many different input files, although the program
always uses numbers.txt as the name of its input file.
When you do your testing, verify that all the output of the program is
correct. You can use
this web site
to check calculations of averages and population standard deviations.
WHAT TO TURN IN:
You will be sending me two e-mail messages. Please follow these rules:
- Always send me e-mail as plain text in the main message body.
Never send me attachments.
- Always use the exact subject line I specify for each
message. (I often get hundreds of e-mail messages in a week. The
subject line allows me to find and sort messages.) You will lose a
significant number of points on the assignment if you use the wrong
subject line.
- Be very careful when you send the e-mail. You may use the
instructions in your
Hello World! lab exercise
for guidance. Of course, you will need to make the obvious changes to
those directions -- you have to use the correct subject line and
filename.
- Always send yourself a copy of each e-mail message you send to me,
check immediately to see if you receive the message intact, and
check within a few minutes to see if you have received e-mail notifying
you about an undeliverable message. You are
responsible for sending e-mail correctly.
Here is the list of things you have to turn in:
- At the start of class on the
due date
place the following item on the "counter" in front of me:
- a hardcopy (printed listing) of your program (the C++
source code). Make sure all the code is properly
formatted and that it all shows on the paper.
- Before midnight on the the due
date send me the following by e-mail:
- A copy of the source code (C++ code) with subject line:
CS1500Solo6Source
- a (filtered) script, with subject line
CS1500Solo6Script
showing the results of doing all the tests described above in the
section entitled "TESTING"
Note that there are no spaces in the subject lines given. It is important
that you do not insert any spaces. My e-mail address is:
john@ishi.csustan.edu
WHEN IS THIS ASSIGNMENT DUE?
Look for the due date in
the class schedule.
(It's at the top level of the class directory.)