Lab 3

Due: Sept 29, 11:55pm


  • Turn in the code (a cpp file or link), and the run outputs as requested below.
  • Remember to format the code as described and the book and text, and to include comments including complete commetns at the beginning of the program.


Feature %
Program correctness and completeness with respect to defination 70%
Code Format (Indenting, variable names) 10%
Code Comments 10%
Turning in complete run of every function at least twice with difference values. 10%


Write a C++ program which does the following (Below is an outline) (60 pts)

    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) Calculate a windchill factor according to the formula in Programming Project 14 (page 300-1) of the textbook (though I am not convinced that it is the best formula available).
        7) 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
            Ask for a temperature and wind speed to calculate windchill index
        If 7 
            Quit the entire program
            Print "Invalid option"

    End Test

Until user quits


  1. Use a switch statement to implement the menu for extra credit.
  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.
  7. There is no universially accepted formula for the windchill factor. You may compare your answers againts some web pages that do calculate that value but keep in mind that i) the units are different ii) the formulas are probably different. Here are couple of sites that caculate windchill effect:

Wind Chill

This topic: KenyonCpp > WebHome > Lab3
Topic revision: r3 - 2015-09-29 - JimSkon
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback