Presentation is loading. Please wait.

Presentation is loading. Please wait.

Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009.

Similar presentations


Presentation on theme: "Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009."— Presentation transcript:

1 Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009

2 Part I: Hand-Written Exercises 1. (a) What is the difference between an operator and a function? (b) What is the difference between a friend function for a class and a member function for the class?

3 2. What (if anything) is wrong with the following code? char stringVar[] = “Hello”; strcat(StringVar, “ and Good-bye.”); cout is in the program file.

4 3. How many characters are in each of the following character and string constants? a.‘\n’ b.‘n’ c.“Mary” d.“M” e.“Mary\n”

5 Part II: Programming Exercises 4.Define a class named MyInteger that stores an integer and has functions to get and set the integer’s value. Then, overload the [] operator so that the index returns the digit in position i, where i=0 is the lease-significant digit. If no such digit exists then -1 should be returned. For example, if x is of type MyInteger and is set to 418, then x [0] should return 8, x [1] should return 1, x [2] should return 4, and x [3] should return -1.

6 5.Write a program that will read in a line of text and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma, or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespaces, commas, and periods. When outputting the number of letters that occur in a line, be sure to count upper and lowercase versions of a letter as the same letter. Output the letters in alphabetical order and list only those letters that occur in the input line. For example, the input line “I say Hi.” should output similar to the following: 3 words 1 a 1 h 2 i 1 s 1 y

7 Homework Submission Due: 3 weeks (May 8, 2009) Hand-written exercises –Please write your names and answers on A4 papers. Programs –Forum: http://140.124.183.11/oop/ –Submission site: http://140.124.183.11/hw/


Download ppt "Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009."

Similar presentations


Ads by Google