Lab 3. Putting functions inside classes

This time I am giving you a partial program which is a C++ version of the last one. Your task is to complete the program by writing the bodies for the three member functions of the class Picnic so that the program behaves just like the last one. i.e. it prints the number of hot dogs per child and the number of left-overs. The only changes are to split the tasks between the three functions 'input', 'calculate' and 'output', and to add a test to prevent division by zero.

Follow these steps to complete the assignment.

  1. Get the source code exactly as in your first and second assignments.
  2. Use the editor to add bodies for the Picnic member functions 'input', 'calculate' and 'output' to print out the corresponding result.
  3. Insert in 'calculate' a test for the number of children being zero, and in that case, make the program print a message instead of doing the operation. 'output' also needs a test to stop it from displaying its message.
  4. Compile and run the program several times to test its results.
  5. Run the program twice more with the these inputs:
    First run: number of hot dogs: 23, number of children: 7
    Second run: number of hot dogs: 23
    , number of children: 0
  6. Redirect the output to a file in each case, and insert the outputs into a copy of the source code file. You can also redirect the input by typing the numbers into a file and using:

    % a.out < in > out
  7. where 'in' is the name of this input file, and 'out' is the name of the output file.
  8. Insert the contents of the 'out' file into the source code file, print it on th elineprinter and hand it to me (RTH).
  9. Use the assignment submitter to submit the source code for lab3.

Points to note: