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 Oct. 6/8.

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 HowManyFit program from the previous lab.

For this lab you must use a good modular (function based) design, and must use recursive functions for the repetition aspects.

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 container size from the user, here showing the user input in bold italics just for clarity. (The example below assumes they entered carton as the name of the container type.)
Please enter the size of a(n) carton in litres (e.g. 4.6): foo
Sorry, that was not a valid number, please try again.

Please enter the size of a(n) carton in litres (e.g. 4.6): -3
Sorry, the size must be a positive number, please try again.

Please enter the size of a(n) carton in litres (e.g. 4.6): huh?
Sorry, that was not a valid number, please try again.

Please enter the size of a(n) carton in litres (e.g. 4.6): 17.41

(at this point the program moves along normally)