Lab 3 - FunctionsDue: Feb 20, 11:55pm |
Write a C++ program which does the following (Below is an outline) (100 pts)
repeat Print Menu 1) Compute area of a triangle (according to the formula below) 2) Compute your clothing size (according to Project 9, in chapter 4 of the textbook) 3) Convert temperature from Fahrenheit to Celsius (nearest integers) 4) Convert temperature from Fahrenheit to Celsius (exact values) 5) Test a positive integer for being prime 6) Calculate a windchill factor according to the formula from the text, given below. 7) Quit Read Option Test Option If 1 Ask the lengths of the sides of the triangle If the lengths are acceptable, find and print the area of the triangle (according to the formula below, also see Project 13, Chp 5) If 2 Ask user's height,weight, and age Find and compute hat size, jacket size, waist according to formulas in Project 9, page 243 of the textbook If 3 Ask for the temperature in Fahrenheit, as an integer Compute the temperature in celsius to nearest integer and print it out If 4 Ask for the temperature in Fahrenheit (exact value) Compute the temperature in celsius (exact value) and print it out If 5 Ask for an integer and determine whether it is prime or not. If 6 Ask for a temperature and wind speed to calculate windchill index If 7 Quit the entire program Otherwise Print "Invalid option" End Test Until user quits
This computations are done in Celsius and m/sec.
W = 13.12 + 0.6215 * t - 11.37 * v^{0.16} + 0.3965* t * v^{0.16}
where
The idea is the break this project up into functional that are cohesive - e.g. each function has a singular purpose, and could (conceivably) be used again somewhere else. I came up with 2 types of functions, the user interface functions (UI) that "talk" to the user, and the support functions that provide (mostly mathematical) functional support for the UI functions.
// User Interface Functions // Each option of the switch will simply call on of these. void printMenu(); void triangleUI(); void clothsUI(); void FtoCIntUI(); void FtoCDoubleUI(); void windchillUI(); void CheckPrimeUI(); //Support Functions double triangleArea(double a, double b, double c); double hatSize(double w, double h); double jacketSizeUnder30(double w, double h); double jacketSizeOver30(double w, double h, int age); double waistSizeOver28(double w, int age); double waistSizeUnder28(double w); double celsius(double f); int celsius(int f); bool prime(int number); double windChill(double temp, double wind_speed);
Recall that an overload function is one that uses the same name, but has differnent types. The C++ compiler calls the one that matches. You will need to implement each of the versions of celsius
below. Which one gets called depends on the type in the call.
double celsius(double f); int celsius(int f);
Turn in a run with all these inputs
Requirement | Grading Comments | Points | Score |
---|---|---|---|
Code broken up in to functions, each of which performs a single objective. | 20 | ||
Good clean, correct, easy to understand Input and output user interface | 10 | ||
Complete source code with good formatting, variables names, and comments | 10 | ||
Area of a triangle correct solutions | 10 | ||
Hat size, jacket size, waist solutions | 10 | ||
Fahrenheit to Celsius (Integer) correct solutions | 10 | ||
Fahrenheit to Celsius (Exact) correct solutions | 10 | ||
Prime Check correct solutions | 10 | ||
Wind Chill solutions | 10 |
Area of a triangle | 15, 20, 30 |
2.3, 7.75, 23.2 | |
8, 0, 5 | |
Hat size, jacket size, waist | Height = 58, Weight = 167.5, Age = 32 |
Height = 42, Weight = 101.5, Age = 22 | |
Height = 77, Weight = 255, Age = 55 | |
Fahrenheit to Celsius (Integer) | 32 |
-17 | |
89 | |
Fahrenheit to Celsius (Exact) | 32 |
-17 | |
89 | |
Prime Check | 2311 |
12557 | |
13219 | |
1 | |
Wind Chill | 22 C Degrees, 34 m/sec |
-6 C Degrees, 64 m/sec | |
0 C Degrees, 12 m/sec |