Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <math.h>
- using namespace std;
- void displayMenu(); // function for menu
- int area(int); // argument for circle
- int area(int,int); // argument for square
- float area(float); // argument for rectangle
- float area(float,float,float); // argument for triangle
- // *******************************
- //* Main
- //* Ask for the dimensions of the shape
- //*
- //*******************************/
- int main()
- {
- int choice; // menu choice
- int s,l,w; // intergers for sides of square and length and width of a rectangle
- float r,A,B,C; // floats for radius and the 3 sides for triangle
- displayMenu();
- cin >> choice; //getting the choices from menu and getting all varibles from user
- if (choice == 1)
- {
- cout<<"Enter the radius of the circle:";
- cin>>r;
- }
- else if (choice ==2)
- {
- cout<<"Enter the sides of a the square:";
- cin>>s;
- }
- else if (choice ==3)
- {
- cout<<"Enter the length and width of the rectangle:";
- cin>>l>>w;
- }
- else if (choice ==4)
- {
- cout << "Length of sides must be positive and sum of any two sides" << endl;
- cout << "must be smaller than third side." << endl;
- cout<<"Enter all 3 sides of the triangle:";
- cin>>A>>B>>C;
- }
- // couts for all the areas
- cout<<"\nArea of circle is "<<area(r);
- cout<<"\nArea of square is "<<area(s);
- cout<<"\nArea of rectangle is "<<area(l,w);
- cout<<"\nArea of triangle is "<<area(A,B,C);
- return 0;
- }
- // finding areas for shapes
- float area(float r)
- {
- return(3.14*r*r); // area for circle
- }
- int area(int s)
- {
- return(s*s); // area for square
- }
- int area(int l,int w)
- {
- return(l*w); // area for rectangle
- }
- float area(float A,float B, float C)
- {
- float s = (A+B+C)/2; // area for triangle
- return sqrt(s*(s-A)*(s-B)*(s-C));
- }
- //********************
- //* Menu function
- //* Ask the user witch shape to find area of
- //******************
- void displayMenu()
- {
- cout << "Please choose a shape you want to find the area" << endl;
- cout << "1. Circle" << endl;
- cout << "2. Square" << endl;
- cout << "3. Rectangle" << endl;
- cout << "4. Triangle" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement