CSCI 159 Lab 3 exercises

Lab3 will consist of two parts:

Hopefully most people complete all of the basic exercise and get a start on the main exercise within their scheduled lab section on Sept 29/Oct 1.

Here is the collection of new C++ syntax elements we'll be using for lab3.


Follow our usual setup process

  1. Log in, open a browser, go to the lab3 page, open a terminal window:
    (see lab 2 if you need a refresher on any of the steps)

  2. get lab 3:
    make -f make159 csci159/lab3

  3. Go into your lab3 directory and begin the edit/compile/test/submit routine: As with previous labs, you'll see that the two .cpp files are nearly empty to start with.


Part 1: the basics of this lab's new C++ features (basic.cpp)

For the first part of today's lab exercise we're adding code to a basic.cpp to experiment with the use of if/else if/else statements in C++ in several ways: As always, be sure you're following the course code standards as you write your code, and don't forget to 'make submit'.


Part 2: design and implementation exercise (lab3.cpp)

Now we want to take our new error checking and recursion capabilities and put them to good use in our stair-counting programs from the previous lab.

For this lab you must use a good modular (function based) design, and must use functions and recursions for the input error checking/repeat-until-valid aspects (no loops!). If your lab2 solution already had a suitable design then feel free to use it as the starting point (and you'll probably find the second half of lab 3 to be relatively quick and painless), otherwise you are welcome to come up with a new design and/or use the lab2.cpp sample solution as a guide.

Since user input error checking, if/else if/else, and recursion are the things we are specifically trying to practice in this lab, the new behaviour and restrictions for our program are as follows:

The output below shows what a snippet of the program behaviour might look like while trying to get a particular value from the user, here showing the user input in bold italics just for clarity.
Please enter the number of times Shaggy answered a call: foo
Sorry, the number of calls must be an integer value, please try again.

Please enter the number of times Shaggy answered a call: -3
Sorry, the number of calls must be non-negative, please try again.

Please enter the number of times Shaggy answered a call: huh?
Sorry, the number of calls must be an integer value, please try again.

Please enter the number of times Shaggy answered a call: 17

(at this point the program moves along normally)