Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include<cmath>
  4. using namespace std;
  5.  
  6.  
  7. double isValidDimensions(double lenght, double diameter);
  8. double eval_volume(double lengthF, double diameterF);
  9. double eval_mass(double est_volumeF, double massF);
  10. void wedge_or_cylinder(double est_massF, double act_massF);
  11. int main()
  12. {
  13. double length = 0; double diameter = 0;
  14. double act_mass = 0;
  15. double est_volume = 0; double est_mass = 0;
  16.  
  17. cout << "Enter the length:" << endl;
  18. cin >> length;
  19.  
  20. cout << "Enter the diameter" << endl;
  21. cin >> diameter;
  22.  
  23. cout << "Enter the actual weight:" << endl;
  24. cin >> act_mass;
  25.  
  26. if (!isValidDimensions(length, diameter))
  27. // check len is within the range 1mm to 20mm and dia is in range 0.1mm - 1mm
  28. {
  29. cout << "Dimensions are not valid";
  30. }
  31. else
  32. {
  33. // estimate volume
  34. est_volume = eval_volume(length, diameter);
  35.  
  36. // estimate weight, density 0.05
  37. est_mass = eval_mass(est_volume, 0.05);
  38.  
  39. // display if wedge or cylinder
  40. wedge_or_cylinder(est_mass, act_mass);
  41. }
  42.  
  43.  
  44. return 0;
  45.  
  46. }
  47.  
  48.  
  49. double isValidDimensions(double lenghtF, double diameterF)
  50. {
  51. double x = lenghtF;
  52. double y = diameterF;
  53.  
  54. if( x >= 1 && x <=20 && y >= 0.1 && y <= 1 )
  55. {
  56. return true;
  57. }
  58. else
  59. {
  60. return false;
  61. }
  62.  
  63. }
  64.  
  65. double eval_volume(double lengthF, double diameterF)
  66. {
  67. double pi = 3.142;
  68. double x = lengthF;
  69. double y = diameterF;
  70.  
  71. double volume = pi * pow(y, 2) * x;
  72. return volume;
  73.  
  74. }
  75.  
  76.  
  77. double eval_mass(double est_volumeF, double massF)
  78. {
  79. double x = est_volumeF;
  80. double y = massF;
  81. double mass = (x * y);
  82. return mass;
  83.  
  84.  
  85. }
  86.  
  87.  
  88.  
  89. void wedge_or_cylinder(double est_massF, double act_massF)
  90. {
  91. double x = est_massF;
  92. double y = act_massF;
  93. double z = x - y;
  94. if (z > 0.1)
  95. {
  96. cout << " The shard is wedge-shaped";
  97.  
  98. }
  99. else
  100. cout << " The shard is cylinder shaped";
  101.  
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement