pclovechristian

Untitled

Apr 1st, 2012
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. system("CLS"); //Flush the stream
  11. int loop = 1;
  12. int choice;
  13. string getinput;
  14. bool done = false;
  15.  
  16. while (loop ==1)
  17. {
  18. system("CLS"); //Flush the stream
  19. cout << "--Menu--" << endl << endl;
  20. cout << "1. Cube" << endl;
  21. cout << "2. Rectengular Prism" << endl;
  22. cout << "3. Sphere" << endl;
  23. cout << "4. Cylinder" << endl;
  24. cout << "5. Cone" << endl;
  25. cout << "6. Quit" << endl; // menu
  26. cin >> choice;
  27.  
  28.  
  29. if(choice < 0 || choice > 7)
  30. cout << "Between 1~6 please." << endl; // between 1~6
  31. system("pause");
  32.  
  33. switch(choice)
  34. {
  35. case 1:// Cube
  36. {
  37. system("CLS");
  38. double Cube_Length = 0.0;
  39. cout << "One side length? " << endl;
  40. cin >> Cube_Length;
  41.  
  42. while(Cube_Length <= 0) {
  43. cout << "Cannot be negative, Try again: ";
  44. cin >> Cube_Length;
  45. }
  46. cout << "Surface area: " << (Cube_Length*Cube_Length)*6 << endl; // calculates surface ares
  47. cout << "Volume: " << Cube_Length*Cube_Length*Cube_Length << endl;
  48. system("pause");
  49. break;
  50. }
  51.  
  52.  
  53. case 2://Rectangular
  54. {
  55. system("CLS");
  56. double RP_Length = 0.0, RP_Width = 0.0, RP_Height = 0.0;
  57. cout << "length? " << endl;
  58. cin >> RP_Length;
  59.  
  60. while(RP_Length <= 0) {
  61. cout << "Cannot be negative, Try again: ";
  62. cin >> RP_Length;
  63. }
  64.  
  65.  
  66. cout << "Width? " << endl;
  67. cin >> RP_Width;
  68.  
  69. while(RP_Width <= 0) {
  70. cout << "Cannot be negative, Try again: ";
  71. cin >> RP_Width;
  72. }
  73.  
  74.  
  75. cout << "Height? " << endl;
  76. cin >> RP_Height;
  77.  
  78. while(RP_Height <= 0) {
  79. cout << "Cannot be negative, Try again: ";
  80. cin >> RP_Height;
  81. }
  82.  
  83.  
  84. cout << "Surface area: " << ((RP_Length*RP_Width)*2)+((RP_Width*RP_Height)*2)+((RP_Length*RP_Height)*2) << endl;
  85. cout << "Volume: " << RP_Length*RP_Width*RP_Height << endl;
  86. system("pause");
  87. break;
  88. }
  89.  
  90.  
  91. case 3: //Sphere
  92. {
  93. system("CLS");
  94. double Sph_radius = 0.0;
  95. cout << "Radius? " << endl;
  96. cin >> Sph_radius;
  97.  
  98. while(Sph_radius <= 0) {
  99. cout << "Cannot be negative, Try again: ";
  100. cin >> Sph_radius;
  101. }
  102.  
  103. cout << "Surface area: " << 4*M_PI*pow(Sph_radius, 2) << endl;
  104. cout << "Volume: " << (4*M_PI*pow(Sph_radius, 3))/3 << endl;
  105. system("pause");
  106. break;
  107. }
  108.  
  109.  
  110. case 4://Cylinder
  111. {
  112. system("CLS");
  113. double Cylin_radius = 0.0, Cylin_height = 0.0;
  114. cout << "Radius? " << endl;
  115. cin >> Cylin_radius;
  116.  
  117. while(Cylin_radius <= 0) {
  118. cout << "Cannot be negative, Try again: ";
  119. cin >> Cylin_radius;
  120. }
  121.  
  122. cout << "Height? " << endl;
  123. cin >> Cylin_height;
  124.  
  125. while(Cylin_height <= 0) {
  126. cout << "Cannot be negative, Try again: ";
  127. cin >> Cylin_height;
  128. }
  129.  
  130. cout << "Surface area: " << (2*M_PI*pow(Cylin_radius, 2)) + (2*M_PI*Cylin_radius*Cylin_height) << endl;
  131. cout << "Volume: " << M_PI*Cylin_height*pow(Cylin_radius, 2) << endl;
  132. system("pause");
  133. break;
  134. }
  135.  
  136.  
  137. case 5://Cone
  138. {
  139. system("CLS");
  140. double Cone_radius = 0.0, Cone_height = 0.0;
  141. cout << "Radius? " << endl;
  142. cin >> Cone_radius;
  143.  
  144. while(Cone_radius <= 0) {
  145. cout << "Cannot be negative, Try again: ";
  146. cin >> Cone_radius;
  147. }
  148.  
  149. cout << "Height? " << endl;
  150. cin >> Cone_height;
  151.  
  152. while(Cone_height <= 0) {
  153. cout << "Cannot be negative, Try again: ";
  154. cin >> Cone_height;
  155. }
  156.  
  157. cout << "Surface area: " << M_PI*Cone_radius*sqrt(pow(Cone_radius, 2)+pow(Cone_height, 2)) << endl;
  158. cout << "Volume: " << (M_PI*pow(Cone_radius, 2)*Cone_height)/3 << endl;
  159. system("pause");
  160. break;
  161. }
  162.  
  163.  
  164. case 6: //Quit, couldn't find any method, other than exit(0);
  165. {
  166. if(choice==6)
  167. {
  168. cout << "Thank you for using the program and See you later!";
  169. exit(0);
  170. }
  171. }
  172. }
  173. }
  174. return 0;
  175. }
Advertisement
Add Comment
Please, Sign In to add comment