(Latest Revision: Wed Nov 26 12:18 PST 2014 )
SIXTH CS 1500 SOLO PROGRAM: Array Arithmetic Program
OBJECTIVE:
The purpose of this programming assignment is to get practice using files,
arrays, and loops.
ASSIGNMENT SYNOPSIS:
Write a program that reads two sets of numbers from a file and
performs some arithmetic operations with them.
DETAILS:
To get a clear idea of what the program is supposed to do,
have a look at
the sample runs.
INPUT:
You must write the program with certain facts, assumptions, and
preconditions in mind:
- The program must prompt the user for the name of the input file and read the data from the file named by the user.
- The input file must contain two sets of 15 integers,
and all the integers must be between 1 and 999 (inclusive).
- The assignment directory contains two sample files that could be the
input files for the program. The names of the sample files
are
data01.txt
and
data02.txt
- Your program must correctly process the contents of the input file,
whatever particular numbers they are.
- After you turn your program in for grading, I will test it using some
input files that I have never shown to you.
If your program works incorrectly on any of my versions of
the input file, you will lose significant credit.
THE DESIGN OF THE PROGRAM:
The program must have at least two functions (in addition to
the main() function).
At least two of the additional functions must have
one or more parameters.
You are not allowed to use any global variables.
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 arrays appropriately. Therefore
- You must write the program so that it reads each list of numbers
into a separate array variable, using a loop to do the reading.
- You must not use large numbers of individual variables to avoid using
arrays.
- You must use loops (I recommend for-loops) to read in and write out
the various groups of 15 integers.
- You must not try to avoid coding loops by utilizing groups of 15
individual input statements or 15 individual output statements.
You should use this kind of declaration in your program:
char fileName[256] ;
to give your program the variable needed for accepting the filename from the user.
The array is nice and long - 256 slots - so it has more than
enough capacity for most filenames. 256 slots is enough for 255 characters
in a string, plus the null character ('\0') that is used to mark the end
of the string.
You can use a command like
ifstream fin(filename) ;
OR
these commands
ifstream fin ;
fin.open(fileName);
to declare an ifstream named fin, and attach it to
the file whose name is stored in the fileName string variable (array of char).
Note: Come to class to get more discussion of how to design the code.
FORM AND FORMATTING REQUIREMENTS:
At the beginning of your program file put a header comment like
this:
/* PROGRAM: Array Arithmetic */
/*
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 the two tests that are in
the sample runs.
Also perform a test where the input file does not exist.
(In this case the program should write a message saying there was
a failure to open the file, and then exit immediately.)
To make it easier for me to check the work in your script, order your
tests so that
- you first perform the tests in the sample runs, in the same
order they appear in
the sample runs file, and then
- lastly you perform the additional test.
When you do your testing, verify that all the output of the program is
correct.
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.)