Lab 3-Option 1

Due: Thu, Feb 15, 11:59pm

 

payrol

Write a C++ program which does the following (Below is an outline) (150 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 Celcius (nearest integers)
        4) Convert temperature from Fahrenheit to Celcius (exact values)
        5) Test a positive integer for being prime
        6) Quit

    Read Option

    Test Option

        If  1
            Ask the lengts 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 246 of the textbook
        If 3
            Ask for the temperature in Fahrenheit, as an integer
            Compute the temperature in celcius to nearest integer and print it out
        If 4
            Ask for the temperature in Fahrenheit (exact value)
            Compute the temperature in celcius (exact value) and print it out
        If  5
            Ask for an integer and determine whether it is prime or not.
        If 6
            Quit the entire program
       Otherwise
            Print "Invalid option"

    End Test

Until user quits

Specifications
1. Use a switch statement to implement the menu
2. Use functions for all subtasks (including printing the menu) . Write comments and pre-and post conditions with function declarations. Tell what each function is supposed to be doing. Separate declarations from definitions.
3. Use the following formula to find the area of the triangle with sides a,b and c (project 13, Chp 5)
    Area= sqrt(s*(s-a)*(s-b)*(s-c)) where s = (a+b+c)/2. So, first ask for the lengths of the sides from the user.
Not every 3 numbers can be sides of a triangle. They must satisfy the triangle inequality: The sum of any two sides must be greater than the third. You should check this condition and give an error message if it is not satisfied.
4. All decimal point number outputs must have 2 digits after the decimal point.
5. Overload the temperature conversion function to implement options 3 and 4. One for option 3 takes an integer argument and return an integer (which is the closest integer temperature). The other one will compute the exact value as a double. So both input and output types will be doubles.
6. You should only accept positive inputs for option 5. Give an error message if the input is negative or 0. 1 is not prime by definition.

Sample output

Turn in

Grading Table

Requirement

Grading Comments

Score

Code broken up in to functions, each of which performs a single objective.

 

15

 

Good clean, correct, easy to understand Input and output user interface

 

15

 

Complete source code with good formatting, variables names, and comments

 

10

 

Area of a triangle correct solutions

 

15

 

Hat size, jacket size, waist solutions

 

15

 

Fahrenheit to Celsius (Integer) correct solutions

 

10

 

Fahrenheit to Celsius (Exact) correct solutions

 

10

 

Prime Check correct solutions

 

10

 

Total

 

100