Topical Information

This lab will help you practice with strings as arguments to functions.

Program Idea

You've heard that a lot of your functions (especially input functions) will be pretty similar except for the messages with which you'll prompt or that you'll print in response to errors. Since these messages are simply string data, you think maybe you should just make them string arguments to the functions.

Thought Provoking Questions (I)

  1. How do you pass a string to a function? Should it be a value argument or a reference argument? (Hint: How big is a string? Is it something that's always small? Or is it something potentially large that we might not want to make a copy of?)
  2. Since you are passing these strings to be printed/displayed -- not modified -- should they be changed within the function? How can you ensure that this won't happen -- even by accident?
  3. Could the caller pass literal strings ("like this one") to your function as the actual argument? Or do they have to declare a string variable/constant and pass that in? (Does your answer depend on the previous question?)

Watch...

.

.

.

out...

.

.

.

below!!!!!

Program Information

Write functions for inputting a user's answers to:

(Note: that's four functions -- not one.)

Let the caller specify the prompts for all functions. Allow the caller to specify the error message for at least the bounded decimal functions.

None of the functions should return a value to the caller until the user has entered an appropriate value! (This is a large part of their utility/re-usability.)

Place these in a library and write a simple test program (aka driver) to show that each works as desired.

Thought Provoking Questions (II)

  1. What type of value does your yes/no function return? Is it a char, a string, or could/should you be more compact?
  2. Could you overload the bounded-entry functions for other types besides the decimal type you chose? Would it be necessary? Why/Why not?
  3. Is overloading useful -- just amongst these four functions? (Hint: How could the compiler tell if the programmer using your library were calling the ≤-bounding function or the ≥-bounding function? ...or would it really even matter..?)

    (You kinda recall something like this:

        enum WhichEnd { Left = 1, Right, Both };
    

    from the notes/examples...hmm...)

  4. Could you provide default values for the prompts and/or error messages? Should you?

This assignment is (Level 4).

Options


Total Level Possible

If you did all above options, this lab could be worth as much as (Level 13).