Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. bool isValidDimensions(double x, double y)
  7. {
  8. if ((x < 1 || x > 20) || (y<0.1 || y>1)){
  9. return false;
  10. }
  11.  
  12. else
  13. {
  14.  
  15. return true;
  16. }
  17.  
  18. }
  19.  
  20. double eval_volume(double x, double y)
  21. {
  22.  
  23. double volume;
  24.  
  25. volume = 3.1415 * ((y / 2) * (y / 2)) * x;
  26.  
  27. return volume;
  28. }
  29.  
  30. double eval_weight(double x, double y)
  31. {
  32. double weight;
  33.  
  34. weight = x / y;
  35. return weight;
  36. }
  37.  
  38. bool wedge_or_cylinder(double x, double y)
  39. {
  40. if (y - x > 0.01)
  41. {
  42. return true; //shard is wedge
  43. }
  44. else
  45. {
  46. return false;
  47. }
  48.  
  49. }
  50.  
  51. int main()
  52.  
  53. {
  54. double length = 0;
  55. double diameter = 0;
  56. double act_weight = 0;
  57. double est_volume = 0;
  58. double est_weight = 0;
  59.  
  60. cout << "Enter the length:" << endl;
  61. cin >> length;
  62. cout << "Enter the diameter" << endl;
  63. cin >> diameter;
  64. cout << "Enter the actual weight:" << endl;
  65. cin >> act_weight;
  66.  
  67. if (!isValidDimensions(length, diameter))
  68. {
  69. cout << "Dimensions are not valid";
  70. }
  71. else
  72. {
  73. // estimate volume
  74. est_volume = eval_volume(length, diameter);
  75. cout << "volume is: " << est_volume << endl;
  76.  
  77.  
  78. // estimate weight, density 0.05
  79. est_weight = eval_weight(est_volume, 0.05);
  80. cout << "Weight:" << est_weight << endl;
  81. // display if wedge or cylinder
  82. cout << "Wedge or Cylinder?\n";
  83.  
  84.  
  85. if (wedge_or_cylinder(est_weight, act_weight))
  86. {
  87. cout << "wedge";
  88. }
  89. else
  90. {
  91. cout << "cylinder";
  92. }
  93.  
  94. }
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement