3050, Spring 2006
Programming Assignment 1
Due Friday, March 3, 2006
Program: Longest Line
The goal of this assignment is to become more familiar with writing C++
programs, while applying some of the file processing operations we have
seen in class.
You will write a C++ program that read an input file(s) in text
(ASCII), finds the longest line in the file, prints the length and
contents of the longest line to the screen and writes it to a text
Your program should be well documented and written in good style. To
document the program, write comments explaining what is done in the
following lines and add comments at the end of certain lines explaining
what has been done on that line. For each function or method add a full
explanation before it, explaining the purpose and what the parameters
represent. For each class created, add an explanation before it. Good
style includes good documentation, choice of clear variable names, and
good program organization and design.
Lines in the file will be determined by newline ('\n') characters.
Command line arguments:
The input file (or files) for your program will be given on the command
line. The main mechanism to do this involves the use of the following
arguments in the main program:
argc, char* argv)
(You may want to look up information on these parameters in your
favorite C++ book or on the web.)
Structure of you program:
Your submission will consist of four files:
- main program (file: lab1main.cpp)
- Line class (files: Line.cpp and Line.h)
- script (see "Making a script" below) - including compile line and
Testing your program:
Before submitting your program you should test it on a variety of
files, including but not limited to:
The results of these tests should be reflected in your script.
- Nonexistent file
- Empty file
- A .cpp file
- A regular text file
- More than one file, if you have provided for this in your program
Submitting your program:
Your files will be uploaded though our automated submission system:
Go to this web site and login using your cs login name and password.
Select CS3050 and Lab1, follow the instructions to upload your
programs. (Note that the testing/compiling module may not be functional
at this time, so I will not be providing a compile line for you.)
Should you have any difficulties with the submission system, please
alert me as soon as possible. If the submission system fails, email
your files to me as attachments (firstname.lastname@example.org).
Making a script (by Dr.
Making a Record of a Program Run: Now that you are
sure the program is working correctly, let's
test. This one will be "for the record." Enter "script p1.script"
and wait until the computer writes a prompt on the screen again. (There
be a slight delay. The prompt you get now may be different than
Here's an explanation of what you just did: The "script"
turns on a program that makes a record of whatever appears on the
command you entered was "script p1.script" so the record the
program makes will be a file called p1.script.
Enter "a.out" and see your "Hello World!" message
the screen again. Now enter "exit" to turn off the scripting
program. From the time you entered "script p1.script" to the
you entered "exit", all things that were written on the screen
also recorded in the file called p1.script.
Enter clear to clear the screen. Now enter "cat p1.script".
This causes the computer to type the contents of the script file you
It should look something like this:
Note that the script file (named p1.script) starts and ends with
that tell when the script was started, and when it was completed. In
it reproduces what you typed.
Script started on Sat Aug 21 19:05:11 2004
script done on Sat Aug 21 19:17:37 2004
Now enter "jove p1.script" so you can look at the file with
editor. You see your script. You also see "weird" characters in the
like ^M at the end of each line, and maybe some other things. These
characters are an undesirable side-effect of the way the scripting
interacts with special characters that handle the terminal display. The
characters are sometimes visible, and sometimes not, depending on just
try to display your script file. The characters were not visible when
displayed p1.script with "cat," but they were visible when you
JOVE. Do a C-x C-c command to exit JOVE.
When you turn in a real programming
assignment, you will be sending me the
source code, plus a script similar to the one you just made. The script
be a record that will show me that you did the right kind of testing of
I require you to run your script through a filter before you send it to
It's a way to get rid of most of the weird characters, so the script
more readable. It is easy to do, no matter how big the script is.
Here's how: Enter "cat p1.script | col -b
temp". This command pipes the script file to the input
command "col -b > temp", which filters out some of the
characters and writes the output to a file named temp. Now the temp
the filtered version of the script. Enter "mv
temp p1.script" to replace the script file with the new
filtered version. Now enter "jove p1.script" again. See how
file has been cleaned up? Good. Exit JOVE again by doing a C-x C-c