fork download
  1. //Andres Guzman CSC5 Chapter 4, P. 225, #21
  2. //
  3. /**************************************************************
  4. *
  5. * SELECT CALCULATION OPTION
  6. * ____________________________________________________________
  7. * This program will allow the user to select an option to calculate.
  8. *
  9. * Computation is based on the formula:
  10. * area1 = pi * pow(radius,2)
  11. * area2 = length * width
  12. * area3 = length * height
  13. * ____________________________________________________________
  14. * INPUT
  15. * radius = Input the radius for an object
  16. * length = Input the desired length of an object
  17. * width = Input desired width of an object
  18. * height = Input desired height for an object
  19. * OUTPUT
  20. * area1 = The area of a circle
  21. * area2 = The area of a rectangle
  22. * area3 = The area of a triangle
  23. *
  24. **************************************************************/
  25. #include <iostream>
  26. #include <cmath>
  27. using namespace std;
  28.  
  29. int main()
  30. {
  31. //
  32. //Initlaizing Variabales
  33. int choice; //Holds the input for the choices
  34. double area1, area2, area3; //Holds room for different areas of calculation
  35. double pi = 3.14159; //Holds a fraction of pi
  36. double radius, length, width, height; //Holds the different input measurements
  37. const int CIR_AREA = 1; //Option 1 for the circle
  38. const int REC_AREA = 2; //Option 2 for the rectangle
  39. const int TRI_AREA = 3; //Option 3 for the triangle
  40. const int QUIT = 4; //Option to end program
  41. //
  42. //Output Options
  43. cout << "\t\Geometry Calculator\n\n"
  44. << "1. Calculate the Area of a Circle\n"
  45. << "2. Calculate the Area of a Rectangle\n"
  46. << "3. Calculate the Area of a Triangle\n"
  47. << "4. Quit\n"
  48. << "Enter your choice (1-4): ";
  49. cin >> choice;
  50. //
  51. //Initialize option selection
  52. switch(choice)
  53. {
  54. case 1 : cout << "\nWhat is the radius of the circle? ";
  55. cin >> radius;
  56. area1 = pi * pow(radius,2); //Calculates area of circle
  57. cout << "\nArea: " << area1;
  58. break;
  59. case 2 : cout << "\nWhat is the length of the rectangle? ";
  60. cin >> length;
  61. cout << "\nWhat is the width of the rectangle? ";
  62. cin >> width;
  63. area2 = length * width; //calculates the area of a rectangle
  64. cout << "\nArea: " << area2;
  65. break;
  66. case 3 : cout << "\nWhat is length of the Triangle? ";
  67. cin >> length;
  68. cout << "\nWhat is the height of the Triangle? ";
  69. cin >> height;
  70. area3 = length * height * .5; //calculates the area of a triangle
  71. cout << "\nArea: " << area3;
  72. break;
  73. case 4 : cout << "\nTerminating Program.";
  74. break;
  75. default : cout << "\nInvalid input. Please input 1, 2, 3, or 4.";
  76. break;
  77. }
  78. return 0;
  79. }
Success #stdin #stdout 0s 5316KB
stdin
1 7
stdout
	Geometry Calculator

1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit
Enter your choice (1-4): 
What is the radius of the circle? 
Area: 153.938