Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

Assignment 1 C++

The document defines functions to calculate the areas of different shapes - circles, rectangles, and triangles. The main function displays a menu allowing the user to choose which shape to calculate, then calls the corresponding area function. Each area function prompts the user for the required measurements, performs the area calculation formula, and displays the result.

Uploaded by

Syazwan Abdullah
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Assignment 1 C++

The document defines functions to calculate the areas of different shapes - circles, rectangles, and triangles. The main function displays a menu allowing the user to choose which shape to calculate, then calls the corresponding area function. Each area function prompts the user for the required measurements, performs the area calculation formula, and displays the result.

Uploaded by

Syazwan Abdullah
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ANSWER: #include <iostream> #include <cmath> #define PI 3.

14159 using namespace std; void void void void circleArea (); rectangleArea (); triangleArea (); displayArea ();

int main() { int choice; cout << " \t GEOMETRY CALCULATION \n cout << " CHOOSE YOUR SELECTION " << cout << " 1. Calculate The Area of a cout << " 2. Calculate The Area of a cout << " 3. Calculate The Area of a cout << " 4. Quit " << endl; cout << " \n Enter Your Choice ( 1 cin >> choice; if ( choice == 1 ) circleArea (); else if ( choice == 2 ) rectangleArea (); else if ( choice == 3 ) triangleArea (); else if ( choice == 4 ) cout << " Bye! " << endl; else

" << endl; endl; Circle " << endl; Rectangle " << endl; Triangle " << endl; 4 ) = ";

cout << " \n You May Only Enter 1, 2, 3 or 4 " << endl; return 0; } void circleArea ( ) { float radius; cout << " \n Enter Circle's Radius = " ; cin >> radius; if ( radius > 0 ) cout << " \n The Area is = " << PI*pow(radius,2) << endl; else cout << " \n Only enter positive values for radius " << endl; } void rectangleArea () { int length, width;

cout << " \n Enter Rectangle's Length = " ; cin >> length; cout << " Enter rectangle's Width = " ; cin >> width; if ( (length>0) && (width>0) ) cout << " \n The Area is = " << length*width << endl; else cout << " \n Only enter positive values for length and width " << endl; } void triangleArea () { float base, height; cout << " \n Enter The Length of the Base = " ; cin >> base; cout << " Enter The Triangle's Height = " ; cin >> height; if ( (base>0) && (height>0) ) cout << " \n The Area is = " << base*height*1/2 << endl; else cout << " \n Only enter positive values for base and height " << endl; } void displayArea () { circleArea (); rectangleArea (); triangleArea (); return; }

EXAMPLE OF OUTPUT:

You might also like