CSE 109 Programming Assignment #1 Due: 10:45 PM Thursday 16 February 2012 [Late collections 10:45 PM 18 February, 19 February] This assignment is an exercise in writing a class and in using pointers. Finish writing the class Word that we started writing in lecture. In /proj/csc109/p1 you will find the file p1.cc, which is based on what I developed in lecture. The program in p1.cc requires the implementation of the following methods (member functions), among others, in class Word. (Note that I indicate methods with (), but this is not meant to suggest how the method should be parameterized.) I have already implemented some of these. 1. The default constructor. 2. The copy constructor. It should make a deep copy of the object passed to it. 3. The destructor, ~Word() 4. Constructors that take a single character or a string of characters as arguments. 5. The [] operator gives access to the character at the given index (starting from 0) provided the index is "in range." Otherwise the program should crash. 6. The []const operator, which behaves like [] in 5. 7. << displays the characters in the Word. 8. = the assignment operator, which copies the right hand side to the left hand side 9. Comparison operators <,<=,>,>=,==,!= 10. str(), which returns a pointer to a string containing the characters in Word (we called this getStr() in class, but I changed it). 12. length() returns the number of letters in the Word 13. >> read input from an istream into a Word, stopping when an end of line or end of file is encountered. 14. iterReset(), which resets the iterator to the beginning of the string that is stored 15. iterNext(), which returns the "next" character in the string. The program crashes if there is no next chatacter. 16. iterPeei(), which returns the character that would be returned if iterNext() were called. Note: iterNext() moves the iterator, while iterPeek() does not. 17. iterAtEnd() which returns true if and only if there are one or more characters for the iterator to return 18. check(), our usual friend. NOTE: Although we declared the methods (indexOf(), subStr(), and trimmed()), you need not implement them. I do note, that the iterator enables you to write reasonably efficient methods for trimmed() and subStr(). Start this assignment by creating the subdirectory p1 in your subdirectory cse109.121 and copying the files /proj/csc109/p1/prog1.output, and /proj/csc109/p1/p1.cc into your p1 directory. DO NOT, I REPEAT EMPHATICALLY DO NOT, CHANGE THE CODE OF main() in p1.cc AT ALL. I REPEAT, DO NOT CHANGE THE PROGRAM CODE IN main() AT ALL IT IS IMPORTANT THAT YOU COMPILE ALL YOUR .cc FILES WITH THE -Werror \ -Wall OPTIONS (E.G. g++ -Werror -Wall p2.cc). When you are ready to submit your work, create the file "DONE" by executing the command "touch DONE". Notes: 1. The file p2.cc should have good documentation. It should have identifying information at the top, e.g., your name, the course, the assignment number. The class declaration should be documented with comments at the top which explain the class and its purpose. The role of each data member should be explained. Each member method should be explained (e.g., by stating pre- and post-conditions and by stating the overall algorithm). Hard to understand sections of code should be explained. This means that most of the documentation goes in the .h file. 2. The point of the iterator is to give the user efficient, interrupted access to the letters of a Word. When grading your work, I will pay attention to whether your implementation is efficient. (Hint: Do not use []) 3. I did not implement or use check() in lecture, but you should implement it and add calls to it in the appropriate places. 4. The file p1.output contains the output when I ran my solution to p1 and entered "I hope you find this program easy" when responding to the prompt "Enter a line of text- ." IN THE SYLLABUS READ THE STATEMENT ABOUT UNFAIR COLLABORATION AND AVOID UNFAIR COLLABORATION