Advertisement
Guest User

Untitled

a guest
May 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6.  
  7. class Shape
  8. {
  9. public:
  10. virtual double Area()=0;
  11. };
  12.  
  13. class Diamond : public Shape{
  14. private:
  15. double side1 , side2;
  16. public:
  17. Diamond(double side1,double side2){
  18. this->side1 = side1;
  19. this->side2 = side2;
  20. }
  21. double getSide1()
  22. {
  23. return side1;
  24. }
  25. double getSide2()
  26. {
  27. return side2;
  28. }
  29. double Area()
  30. {
  31. return (side1 * side2) / 2;
  32. }
  33. };
  34.  
  35. class Oval : public Shape
  36. {
  37. private:
  38. double Axis1;
  39. double Axis2;
  40. public:
  41. Oval(double one,double two)
  42. {
  43. Axis1 = one;
  44. Axis2 = two;
  45. }
  46. double getAxis1()
  47. {
  48. return Axis1;
  49. }
  50. double getAxis2()
  51. {
  52. return Axis2;
  53. }
  54. double Area()
  55. {
  56.  
  57. return Axis1 * Axis2 * 3.14;
  58. }
  59. };
  60.  
  61. class Pentagon : public Shape
  62. {
  63. private:
  64. double oneSide;
  65. public:
  66. Pentagon(double side)
  67. {
  68. oneSide = side;
  69. }
  70. double getSide()
  71. {
  72. return oneSide;
  73. }
  74. double Area()
  75. {
  76. return 1.0 / 4 * sqrt( 5 * ( 5 + 2 * sqrt(5)) * oneSide * oneSide);
  77. }
  78. };
  79.  
  80. int main()
  81. {
  82. Shape* shape[10];
  83. int userChoice;
  84. int i= 0;
  85. double one, two;
  86. double side1, side2;
  87. double side;
  88.  
  89. do
  90. {
  91. cout << endl << ">1 =Type 1 to make a Diamond= ";
  92. cout << endl << ">2 =Type 2 to make an Oval= ";
  93. cout << endl << ">3 =Type 3 to make a Pentagon= ";
  94. cout << endl << ">4 =Type 4 to list all currently stored shape areas= ";
  95. cout << endl << ">5 =Type 5 to close the Menu and exit the program= ";
  96. cout << endl << "Please enter a letter choice: ";
  97. cin >> userChoice;
  98.  
  99. if(cin.fail())
  100. {
  101. cout<<"** Invalid.Must be an integer **"<<endl;
  102. cin.clear();
  103. cin.ignore(256, '\n');
  104. continue;
  105. }
  106. else if(userChoice<1 || userChoice>5)
  107. {
  108. cout<<"** Invalid Choice.Must be between 1-5 **"<<endl;
  109. continue;
  110. }
  111.  
  112.  
  113. switch(userChoice)
  114. {
  115. case 1:
  116. cout<< endl << "Input the two equal sides of the Diamond: ";
  117. cin >> side1 >> side2;
  118. shape[i] = new Diamond(side1 , side2);
  119. i++;
  120. break;
  121.  
  122.  
  123. case 2:
  124. cout<<"Input the two axes of the Oval: ";
  125. cin >> one >> two;
  126. shape[i] = new Oval(one , two);
  127. i++;
  128. break;
  129.  
  130.  
  131. case 3:
  132. cout << "Input a single side to the equal-sided Pentagon: ";
  133. cin >> side;
  134. shape[i] = new Pentagon(side);
  135. i++;
  136. break;
  137.  
  138.  
  139. case 4:
  140. cout<<"********************************************************"<<endl;
  141. for(int j = 0; j < i;j++)
  142. {
  143.  
  144. cout<<"Current shape "<<(j+1)<<" has area = "<<shape[j]->Area() << endl;
  145. }
  146. cout<<"********************************************************"<<endl;
  147. break;
  148.  
  149.  
  150. case 5:
  151. break;
  152.  
  153.  
  154. default :
  155. cout<<"\nInvalid option";
  156. break;
  157. }
  158.  
  159. }
  160. while(userChoice != 5);
  161. return 0;
  162.  
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement