/**************************************************************** CS177/477 C++ Programming, Fall 1999 Lab 3. Putting functions inside classes This time I am giving you a partial program which is a C++ version of the last one. You 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. Edit the source code from this message exactly as in your first assignemnt. 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 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 where in is the name of this input file, and out is the name of the output file. 5. Print the file with the source code and output and hand it to me (RTH). 6. Mail the same file to our grader (login junpu). Points to note: o 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. o Don't forget to put your name in the file comment block. o the three functions are all 'void' functions--they do not return any value. o You may need extra variables to hold the results of the arithmetic operations. You should declare these also in the private data section of the class, along with the variables that hold the input values. o Use the if-else form in the test for zero. The 'then' branch will be your error message, the 'else' branch will be the arithmetic operation(s). *******************************************************************/ ///////////////////////////////////////////////////////////////////// // CS177/477, Fall 1999 // // Using class member functions for separate tasks. // // This program reorganizes the code for the hot dog problem // // Roger Hartley // ///////////////////////////////////////////////////////////////////// #include using namespace std; // declare a class to encapsulate the variables for the problem and // functions the operate on them class Picnic { private: /* declare variables here */ public: void input() { /* put your code in here*/ } void calculate() { /* put your code in here */ } void output() { /* put your code in here */ } }; int main() { Picnic picnicObject; // create a picinc picnicObject.input(); // input the values for hot dogs and children picnicObject.calculate(); // calculate hot dogs per child and left overs picnicObject.output(); // display the results return 0; }