Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- bool isValidDimensions(double x, double y)
- {
- if ((x < 1 || x > 20) || (y<0.1 || y>1)){
- return true;
- }
- else
- {
- return false;
- }
- }
- double eval_volume(double x, double y)
- {
- // v= pi r^2 l
- y = y / 2;
- int r = y * y;
- return 3.142 * x * r;
- }
- double eval_weight(double x, double y)
- {
- return x * y;
- }
- bool wedge_or_cylinder(double x, double y)
- {
- if (y - x > 0.01)
- {
- return true; //shard is wedge
- }
- else
- {
- return false;
- }
- }
- int main()
- {
- double length = 0;
- double diameter = 0;
- double act_weight = 0;
- double est_volume = 0;
- double est_weight = 0;
- cout << "Enter the length:" << endl;
- cin >> length;
- cout << "Enter the diameter" << endl;
- cin >> diameter;
- cout << "Enter the actual weight:" << endl;
- cin >> act_weight;
- if (isValidDimensions(length, diameter))
- {
- cout << "Dimensions are not valid";
- }
- else
- {
- // estimate volume
- est_volume = eval_volume(length, diameter);
- cout << "volume:" << est_volume << endl;
- // estimate weight, density 0.05
- est_weight = eval_weight(est_volume, 0.05);
- cout << "Weight:" << est_weight << endl;
- // display if wedge or cylinder
- cout << "Wedge or Cylinder?\n";
- if (wedge_or_cylinder(est_weight, act_weight))
- {
- cout << "wedge";
- }
- else
- {
- cout << "cylinder";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement