Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. void displayHeader();
  5. void displayMenu();
  6. void calculateCircle(double x);
  7. void calculateTriangle(double h,double s1, double s2, double s3);
  8. void calculateSquare (double s);
  9. void calculateRectangle(double w ,double l);
  10. void displayResult(double x, double y, string shape);
  11.  
  12.  
  13. int main()
  14. {
  15. int answer;
  16.  
  17. displayHeader();
  18. displayMenu();
  19.  
  20. cin >> answer;
  21.  
  22. switch (answer)
  23. {
  24. case 1: // circle
  25.  
  26. double radius;
  27. cout << "Enter radius of circle " << endl;
  28. cin >> radius;
  29. calculateCircle(radius);
  30. break;
  31.  
  32. case 2: // triangle
  33. double tHeight;
  34. double s1;
  35. double s2;
  36. double s3;
  37. cout << "Enter height of triangle " << endl;
  38. cin >> tHeight;
  39. cout << "Enter side1 of triangle " << endl;
  40. cin >> s1;
  41. cout << "Enter side2 of triangle " << endl;
  42. cin >> s2;
  43. cout << "Enter side3 of triangle " << endl;
  44. cin >> s3;
  45. calculateTriangle(tHeight,s1, s2,s3);
  46. break;
  47. case 3: // square
  48. double side;
  49. cout << "Enter side of square " << endl;
  50. cin >> side;
  51. calculateSquare(side);
  52. break;
  53. case 4: // rectangle
  54. double rHeight;
  55. double width;
  56. cout << "Enter width of rectangle " << endl;
  57. cin >> width;
  58. cout << "Enter height of rectangle " << endl;
  59. cin >> rHeight;
  60. calculateRectangle(width, rHeight);
  61. break;
  62. case 5:
  63. cout << "BYEEEEEEEee" << endl;
  64. break;
  65. default:
  66. cout << "Bad choice! Please try again later.\n";
  67. }
  68.  
  69.  
  70. return 0;
  71. }
  72.  
  73. void displayHeader() {
  74. //cout << "******************************************************************" << endl;//
  75. cout << "Welcome to the Circumference and Surface Area Calculator!" << endl;
  76. cout << "******************************************************************" << endl;
  77. }
  78. void displayMenu() {
  79. cout << "Here are some shapes you could use to calculate the circumference and surface area" << endl;
  80. cout << "1 - Circle\n";
  81. cout << "2 - Triangle\n";
  82. cout << "3 - Square\n";
  83. cout << "4 - Rectangle\n";
  84. cout << "Quit\n";
  85. }
  86. void calculateCircle(double r)
  87. {
  88. double circumference = 2 * 3.14 * r;
  89. double surfaceArea = 3.14 * (r * r);
  90. displayResult(circumference, surfaceArea, "circle");
  91. }
  92. void calculateTriangle(double h,double s1, double s2, double s3){
  93. double circumference = s1 + s2 + s3;
  94. double surfaceArea = (h * s1) / 2;
  95. displayResult(circumference, surfaceArea, "triangle");
  96. }
  97. void calculateSquare(double s){
  98. double circumference = s * 4;
  99. double surfaceArea = s *s;
  100. displayResult(circumference, surfaceArea, "square");
  101. }
  102.  
  103. void calculateRectangle(double w ,double l){
  104. double circumference = 2 * (w + l);
  105. double surfaceArea = w * l;
  106. displayResult(circumference, surfaceArea,"rectangle");
  107. }
  108. void displayResult(double c, double s, string shape){
  109. cout << "The circumference of the " << shape << " is " << c << endl;
  110. cout << "The surface area of the " << shape << " is " << s << endl;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement