/**************************************************************** CS177 C++ Programming, Spring 1998 Lab 4. Multiple objects and function parameters. At the bottom of this message is skeleton source code for a program that counts the number of characters and lines typed by the user at the keyboard. Complete the skeleton so that it reports the number of characters *excluding* newline characters, *and* the number of lines. For example, here is sample input and output: % a.out This is some input ^D Number of lines = 2 Number of characters = 17 % *** YOU MAY NOT BE ABLE TO FINISH THIS ASSIGNMENT IN THE LAB SESSION, PLEASE COMPLETE IT IN YOUR OWN TIME. THE DUE DATE IS MONDAY, 16TH., IN CLASS *** Follow these steps to complete the assignment. 1. Edit the source code frm this message exactly as in your first assignemnt. 2. Use the editor to add methods to the Counter class to: a) initialize the counter variable b) increment the counter c) print the value of the counter d) print a warning and terminate the program when either when the number of characters exceeds 50, or the number of lines exceeds 5. 3. Compile and run the program several times to test its results. 4. Run the program once more with the the sample input given above. Redirect the output to a file, and insert the output into a copy of the source code 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 hhuang). 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 Termination of keyboard input is signalled by typing a single ctrl-D on a separate input line. You can also make the program read from a file by using input indirection: % a.out < input.file There is no need to put a ctrl-D in the file since UNIX will effectively put one in for you. o The skeleton uses the member functions get and eof for the object cin. You should not need to alter this. o You need two counter objects, one to count lines and one to cout characters. o Constructor functions have no return type. o Terminate the program with a call to exit, thus: exit(1); o You may want to customize the output function (which prints the value of the counter) by passing it a string. You can use the standard string class to do this: void print(string str) { cout << str << ... } You must include the header file to use sthe string class: #include (Note there is no .h on it) *******************************************************************/ ///////////////////////////////////////////////////////////////////// // CS177/457, Spring 1998 // // Using multiple objects and function parameters // // Roger Hartley // ///////////////////////////////////////////////////////////////////// #include // uncomment the line below if you want to use the string class //#include class Counter { public: // put a default constructor function here // put a function that increments the counter here // put a function to print the value of the counter here // put a function here to test whether the counter has exceeded // some value passed as an argument private: int count; // the counter variable }; int main() { const int MAX_LINES = 5; // the threshold for lines const int MAX_CHARS = 50; // the threshold for characters // create two counter objects here, one for lines and one for // characters char c; // a variable to hold the characters read one at a time // from the keybaord cin.get(c); // read one character from the keyboard while (!cin.eof()) { // continue as long as there are more characters // here you should test for newline, and process accordingly, // here you should test for too many lines and characters, and exit // if too many cin.get(c); // get another character from the keyboard } // report on the number of characters and lines }