CIS 254 Intro to Object Oriented Program Design

Project 4.1

Write an interactive program that computes the area of a square (area = side2) or triangle (area = 1/2 * base * height) after prompting the user to type the first character of the figure name (t or s). Make sure that your output matches the sample output exactly. Note that a square does not have a base and a height. It has only a side. Your variable names should reflect this.

Use double variables so that the user can enter a decimal if desired. Round your answer to the nearest tenth.

Hint: in order to round the numbers to the nearest tenth, #include <iomanip> at the top of your program and use something like

cout << fixed << setprecision(1) << "The area is......

This will cause your output to be rounded to 1 digit after the decimal.

In this program it will be best to NOT use any named constants.

Sample screen output 1:

    Enter the type of figure (s or t): t    
    Enter the base: 7
    Enter the height: 3
    The area is 10.5

Sample screen output 2:

    Enter the type of figure (s or t): s    
    Enter the length of a side: 9
    The area is 81.0