CSCI 160 Lab exercise 3, F21N01/N02

In lab exercise 3 we'll be working on pass-by-reference parameters, recursion, and loops.

As with previous labs, there are several key syntax elements you'll need to be familiar with. The core syntax elements can be found here.

The process for obtaining, working on, and submitting labex3 is the same as for past labs (except of course it's labex3 rather than labex0/1/2).

Refer back to the lab1 part 1 instructions if you forget the specifics of different steps.


labex3.cpp objectives

In this lab exercise we'll continue our work with functions and if/else statements, but this time we'll be using pass-by-reference parameters in one function, and we'll be using recursion and loops to carry out repetition (e.g. getting the user to repeatedly enter values until they supply valid information).

You may use either the iostream library or the cstdio library for input/output.

The applied objective for this exercise is to create and submit a complete and correct C++ program, adhering the the course code standards, with the following behaviour and restrictions:

  1. The general intent of the program is to Details are provided below regarding the required error checking and handling, and the required structure of the program.

  2. The program will have a selectShape function that prompts the user to enter 'T' for triangle or 'R' for rectangle. The function must use a recursive approach (no loops) to getting the user to try again, returning the eventual valid response. selectShape does not take any parameters, it returns a char.

  3. The getDimensions function takes two pass-by-reference parameters, height and width. Both parameters are of type double, and the function has a void return type.

    The function must use a loop (no recursion) to repeatedly prompt the user to enter the shape dimensions, continuing until a pair of valid values are provided. (The valid values must get stored in the parameters.)

  4. The displayArea routine takes three parameters: the shape type (a char), the height (a double), and the width (a double). It has a return type of void.

    The function must compute the area of the shape (width*height for the rectangle, width*height/2 for the triangle).

    After the area has been computed, the function must display the shape type, dimensions, and computed area.

  5. The main routine's sequence of events will simply be to:


Deadlines and late penalties

Submission deadlines and late penalties for all lab exercises are provided on the main labs page.

Reminders

Don't forget to do your "make submit" when finished, and don't forget about the tools/tips from week 2 of labex1 (ssh'ing to the pups, getting your lab feedback, and use of X2Go).

Don't forget to follow the code standards, be sure to check your feedback from labex2 to see if there were concerns with your previous work with respect to the code standards.

Suggested (iterative) development process

As with previous labs, I strongly recommend coding and testing small parts of the program at a time. Get basic versions of each function working first (without error checking, loops, or recursion) then when those appear to be working start adding the error checking (still without the loop or recursion), then when that appears to be working add the repetition.