Advertisement
Porr011

Lesson 10 Activity 3

Mar 3rd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. #include <math.h>
  5. using namespace std;
  6.  
  7. void displayMenu(); // function for menu
  8.  
  9. int area(int); // argument for circle
  10. int area(int,int); // argument for square
  11. float area(float); // argument for rectangle
  12. float area(float,float,float); // argument for triangle
  13.  
  14. // *******************************
  15. //* Main
  16. //* Ask for the dimensions of the shape
  17. //*
  18. //*******************************/
  19. int main()
  20. {
  21.     int choice; // menu choice
  22.    
  23.     int s,l,w; // intergers for sides of square and length and width of a rectangle
  24.     float r,A,B,C; // floats for radius and the 3 sides for triangle
  25.    
  26.     displayMenu();
  27.     cin >> choice; //getting the choices from menu and getting all varibles from user
  28.     if (choice == 1)
  29.     {
  30.     cout<<"Enter the radius of the circle:";
  31.     cin>>r;
  32.     }
  33.     else if (choice ==2)
  34.     {
  35.     cout<<"Enter the sides of a the square:";
  36.     cin>>s;
  37.     }
  38.     else if (choice ==3)
  39.     {
  40.     cout<<"Enter the length and width of the rectangle:";
  41.     cin>>l>>w;
  42.     }
  43.     else if (choice ==4)
  44.     {
  45.     cout << "Length of sides must be positive and sum of any two sides" << endl;
  46.     cout << "must be smaller than third side." << endl;
  47.     cout<<"Enter all 3 sides of the triangle:";
  48.     cin>>A>>B>>C;
  49.     }
  50.     // couts for all the areas
  51.     cout<<"\nArea of circle is "<<area(r);
  52.     cout<<"\nArea of square is "<<area(s);
  53.     cout<<"\nArea of rectangle is "<<area(l,w);
  54.     cout<<"\nArea of triangle is "<<area(A,B,C);
  55.     return 0;
  56. }
  57.  
  58. // finding areas for shapes
  59. float area(float r)
  60. {
  61.     return(3.14*r*r); // area for circle
  62. }
  63. int area(int s)
  64. {
  65.     return(s*s); // area for square
  66. }
  67. int area(int l,int w)
  68. {
  69.     return(l*w); // area for rectangle
  70. }
  71. float area(float A,float B, float C)
  72. {
  73. float s = (A+B+C)/2; // area for triangle
  74.     return sqrt(s*(s-A)*(s-B)*(s-C));
  75. }
  76.  
  77. //********************
  78. //* Menu function
  79. //* Ask the user witch shape to find area of
  80. //******************
  81. void displayMenu()
  82. {
  83.     cout << "Please choose a shape you want to find the area" << endl;
  84.     cout << "1. Circle" << endl;
  85.     cout << "2. Square" << endl;
  86.     cout << "3. Rectangle" << endl;
  87.     cout << "4. Triangle" << endl;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement