Call-by-Value, Multiple Files
Lab Assignment
5

The assignment contains two parts. See the class slides for Chapter 12 for the second problem.


Body Mass Index.
The program, Lab5_bmi, should calculate the person's Body Mass Index (BMI) and BMI category.

The BMI formula is as follows:

BMI = Weight in Pounds * 703 / ((Height in inches) * (Height in inches ))

The BMI categories are calculated on the basis of the person's BMI index as follows:

Underweight: less than 18.5
Normal weight: 18.5-24.9
Overweight: 25-29.9
Obese: 30 or greater

The BMI should be calculated by a function bmi that accepts two parameters: "height in inches" and "weight in pounds" and returns the BMI. Note that the BMI has a fractional part.

The main function should prompt the user for his/her weight and height, compute the category then output both the BMI and the category. The user should input his/her height in feet and inches. The main function should compute the total number of inches (one foot has 12 inches) and pass it to the bmi function.

Make sure to use the bmi function declaration and put the function definition below the main function definition.

Figures. Create an executable file titled Lab5_figures. This project will contain multiple files. Write a program that repeatedly asks the user to select either a square or triangle, then inputs the figure size and then prints the appropriate shape in stars. The program should quit if the user inputs an invalid option. See an example dialog below:

1. square
2. triangle
select figure: 2
select size: 4
*
**
***
****
1. square
2. triangle

select figure: 1

select size: 4

****
* *.

* *

****

Note that for the square with a size of n, the first row has n asterisks; the next n-2 rows have 2 asterisks one at the start of the row and one under the nth asterisk on the first line; and the last row has n asterisks. The figure is not really a square because the vertical spacing is different from the vertical spacing.That is OK.

For the triangle with a size of n, the first line has 1 asterisk, the 2nd two asterisks, and the nth, n asterisks forming a right triangle.


Place the asterisk-printing code in two separate functions: triangle and square. Each function should accept a single integer parameter - the size of the figure and return no value (be a void-function). Create three separate files figures.cpp, figures.h, and figuresInput.cpp. Place the triangle and square function definitions in figures.cpp and their declarations in figures.h. Make sure that the header file is protected against multiple inclusion. Place the main function in figuresInput.cpp.

Create a simple makefile, Makefile, that will handle all the compilations and linking. You can do this after you debug the program if you wish so you don't have to deal with the new concepts of multiple files and makefiles at the same time. However,once you are used to makefiles, you will save a lot of time by using them, even with short programs. Name the make file as in the slides for Chapter 12. Include a clean option.

Make sure your programs adhere to proper programming style. Submit your programs and makefile to the subversion repository. Do not forget to verify your submission on the web.