Lab #3 FAQ

(Frequently Asked Questions)

Updated: Thursday, July 23, 1998 8:13:27 PM

Here are some popular Questions and Answers for Lab #3.

****************************************
Q: The public member function:
int countChars(void) const;
is supposed to return the number of characters in the String. Do we include spaces and punctuation or just the letters a-z and A-Z?

A: This function should count all characters in the String. This includes letters, numbers, spaces, puncuation, etc. For example, if the String contained the text (without the quotes):

"This sentence has 5 words."
then the function should return the value 26.


****************************************
Q: If a cleint tries to initialize a String to a NULL string or an empty string, am I supposed to print an error message?

A: No. You should just initialize your String data to NULL if you get a NULL pointer. If you get an empty string, "", then you should just deal with it. An empty string is a valid string.

****************************************
Q: What if the client tries to initialize the String with a string that is so large that there is not enough memory in the heap for it? Should I print an error message?

A:It is unlikely that this will happen. However, you do need to make sure that you are asserting that the 'new' operator successfully allocated the memory. Use the assert() function we've seen in class. Look at this page for a quick reminder.

****************************************
Q: In the isEqual(...) function, if one or both strings in the objects are NULL, do we print an error message?

A: No. Just be sure to handle them intelligently (meaning don't crash the program!) For this assignment, assume that a NULL string or empty string is less than a non-NULL or non-empty string.

****************************************
Q:Who is responsible for printing error messages, our String class or the client code?

A: Since the client has no way of detecting any errors, you need to display error messages. In this assignment, the only time that you should display an error message is if a memory allocation fails (the new operator returns NULL). This should be caught by the assert() function that you must use in any function that allocates memory dynamically. Look at this page for a quick reminder.

****************************************
Q: In the isGreater(...) function, do we return TRUE if the object's private data string is greater, or if the otherString's data is greater?

A: Return TRUE if the object's data (the private data) is greater. Think of the function call as replacing the infix operator for greater than:

  s1.isGreater(s2)  // Is s1 > s2 ?

****************************************
Q: I'm not quite sure what some of the public member functions of the String class are supposed to do. How can I start implementing them if I'm unsure?

A: You can't. One of the goals of this assignment is to get you to think about what you are supposed to be implementing. In the previous lab assignments, I gave you explicit descriptions that described what the functions were supposed to do. In this assignment, I've purposely left out some things so that you will have to "think" like a software developer. Many times, the clients don't provide all of the information that you need to complete the task. It is your responsibility to ask the client for clarification. In this case, I am your client. So, if you are unsure, you need to ask me for more information. If you just make an assumption about what the function is supposed to do, you risk being wrong and upsetting your client (me) and not getting paid (a good grade).


Back to Outline