Assignment 1 C++
Assignment 1 C++
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: