{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

finalreport3

# finalreport3 - University of Cincinnati Department of...

This preview shows pages 1–4. Sign up to view the full content.

University of Cincinnati Department of Computer Science CS 121-002 Computer Science 1 Laboratory 3 Final Report Benjamin Jones 24 January 2008 1. Introduction The purpose of this laboratory is to learn how to utilize input/output statements, expressions, assignment statements, integer variables, constants, and IF statements in a practical example involving calculating the area of several geometric figures. More specifically, the program must calculate the area of a circle, square, or isosceles triangle, depending on what the user wants. The program will be reprogrammed several times using different standards. 2. The Program(s) // *********************************************************************** // File: lab3a.cpp // // Area of a user selected figure - User selects a geometric figure, the // user inputs some information based on // the figure chosen, and the program outputs // the area of the chosen figure. // // // Author: Benjamin Jones // Created: 24 January 2008 // Updated: Original // // Assignment: 2.16 // Compiler: MinGW32 G++ 3.4.2 (GNU) // // Inputs: Choice of geometric figure, "1" for circle, "2" for square, and "3" // for isosceles triangle with base equal to height. The use must also // input the diameter of the circle for a cricle, the length of the // square for a square, or the base of the triangle for the triangle. // Outputs: Display message, "<object> is of area=<area>" where object is either // "circle", "square", or "triangle" and area is the area in floating // point (expressed as variable type "double" // ********************************************************************* // // Design: // // 1. Get input from user // a) Read input // b) Determine whether the user selected triangle, circle, or square // 1. Get input from user depending on each figure // a) If circle get diameter

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
// 1. Read input // b) If square get length // 2. Read input // c) If triangle get height // 3. Read input // // 2. Calculate area of the selected geometric figure // a) If circle, calculate area of a circle // b) If square, calculate area of a square // c) If triangle, calculate area of a isosceles triangle where base // equals height // // 3. Display message "<object> area = <area> where <object> is a circle, // square, or triangle, and <area> is a floating point number, and // message is based upon object selection. // a) If circle, <object> = circle // b) If square, <object> = square // c) If triangle, <object> = triangle // // *********************************************************************** #include <iostream> using namespace std; const int OK = 0; const double PI = 3.14; int main() { int menuChoice = 0; double diameterOfCircle = 0.0; double lengthOfSquare = 0.0; double heightOfTriangle = 0.0; double areaOfObject = 0.0; // 1. Get input from user cout << "Please select the geometric figure you want to find the area for" << endl; cout << "****************************************************************" << endl; cout << "1) Circle" << endl; cout << "2) Square" << endl; cout << "3) Triangle" << endl; cout << "****************************************************************" << endl; cout << "=> "; // a) Read input cin >> menuChoice; cout << endl; // b) Determine whether the user selected triangle, circle, or square if (menuChoice == 1) { // a) If circle get diameter cout << "Please enter the diameter of the circle: ";
// 1. Read input cin >> diameterOfCircle; cout << endl; } else if (menuChoice == 2) { // b) If square get length cout << "Please enter the length of the square: "; // 2. Read input cin >> lengthOfSquare; cout << endl; } else if (menuChoice == 3) { // c) If triangle get height cout << "Remember, triangle is isosceles with base equal to height" << endl;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 13

finalreport3 - University of Cincinnati Department of...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online