OBJECTIVE:
Search a file of numbers of type int and write the largest and smallest
to the screen. The file contains int values delimited by white space or
newline characters.
THE ASSIGNMENT:
Your assignment is to write a program
that searches a file of numbers of type int and write the largest and
smallest to the screen.
To do this you will need to:
1. Declare an array of characters to hold the file name input by
the user:
char fileName [13];
2. Check that the file can be opened and exit it not.
3. Process the file, one integer at a time (while(not EOF)),
keeping track of the smallest and largest values seen so far. Output
the smallest and largest values once all of the integers in the file
have been processed.
INPUT AND OUTPUT:
The program must prompt the user to input a file name.
The program must open and read a file containing int values delimited
by white space or newline characters. The program will output the
smallest and largest values in the file.
Here are sample contents of a data file, called
data1:
333333
-1
4444444
-22
55555555
-1
-333
999999
-4444
How it should look when you run the program:
mmartin@cs.csustan.edu:(~/cs1500/solo6)
g++ solo6.cpp
mmartin@cs.csustan.edu:(~/cs1500/solo6)
a.out
Enter a file
name. This Program limits file names to a maximum of 12
characters.
data1
Smallest in
file = -4444
Largest in
file = 55555555
WHAT TO
TURN IN:
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 upload the following to the Homework Submission
System:
- A copy of the source code (C++ code) (be sure your name is
in the comment section at the beginning of the program), named sprog6.cpp
- and a (filtered) script showing a test run of the program,
named sprog6.script
DUE DATES:
For the due dates, see
the class schedule.