Lab 2. Modify an existing program
Here, below, is source code for a program
that calculates a number of seats
given a number of rooms and the number of seats per room. Follow
these steps to complete the assignment. These steps are essentially
the same as the last lab assignment, except for step 2.
- Copy the source code
(shift-click on the link) exactly as in your first
assignment.
- Use the editor to change the purpose
of the program to calculate how many
hot dogs a child can get given a total number of hot dogs, and a
number of children. These two numbers should be read from the keyboard
and the results of the calculation printed on the screen. The
program should print both the number of hots dogs per child, and the
number of hots dogs left over. For example: 64
hot dogs divided among 15 children gives 4 each with 4 left over. You
can use both integer division (the / operator) and the modulus,
or remainder operator % to do this. See page 77 of the textbook for
examples.
- Compile and run the program several
times with different numbers to
test its results.
- Run the program once more with the
example input (64 and 15) but with
redirected output to a file, and insert the output into a copy
of the source code file.
- Print the file with the source code
and output on the lineprinter and hand it to me (RTH).
- Use the assignment
submitter to copy your source code into my directory. Don't try to copy
it directly - it won't work because you do not have Linux permissions set to
alter my directory.
Points to note:
- Use different file names from those
used in Lab 1, so that you can preserve
your work from last week.
- You may get compilation errors and/or
warnings. Pay attention to these messages
because you program may not run correctly, or at all, because of
these errors.
- Don't forget to put your name, date
and assignment name (lab2) in the file header comment.
- Change the file header comment to
reflect the new use of the program.
- Change the user prompts (the text
strings printed by the program before
asking for input) to suit the new purpose.
- Notice that any line that starts with
double slash (//) is a comment line--useful for the reader but ignored by
the compiler.
- The calculation is obviously different
for the new use.
- Make sure your output is easily read
and understood.