Professional Documents
Culture Documents
1. Accepts the distance between the pivot point and point of force to be applied at
2. Accepts the distance between the weight placed on the log and the pivot point
3. Accepts the weight placed on the lever (Conditional Statements should be coded using
IF-ELSE statements)
a. If the weight entered is in grams convert it into kilograms
b. If the weight entered is in milligrams convert it into kilograms
c. If the weight entered is negative or zero then display the appropriate warning
message
4. Calculates the force to be applied in order to lift the weight placed on the lever
( weight x distance of weight placed ¿ pivot point )
force=
distance between the pivot point∧the point of force applied
5. Display to the user all the entered data and the calculated force to be applied
Page 1 of 4
Code:
#include<iostream>
#include<string>
using namespace std;
int main() {
int d1, d2,unit;
double weight,CWeight,force;
cout << "Enter distance between the pivot point and point of force to be applied:
";
cin >> d1;
cout << "Enter distance between the weight placed on the log and the pivot point:
";
cin >> d2;
cout << "Enter Weight and Unit: ";
cout << "weight: ";
cin >> weight;
cout << "press 1 for kg\npress 2 for gram\npress 3 for miligram ";
cin >> unit;
if (unit == 1 ) {
force = (weight * d2)/d1;
cout << "Force is: " << force<<endl;
}
else {
if (unit== 2) {
CWeight = weight / 1000;
force = (CWeight * d2) / d1;
cout << "Force is: " << force << endl;
}
else if (unit==3) {
CWeight = weight / 1000000;
force = (CWeight * d2) / d1;
cout << "Force is: " << force << endl;
}
else {
cout << "Error!Please Enter right Unit: " << endl;
}
system("pause");
return 0;
}
Page 2 of 4
Question 2) Write a code that does the following:
Code:
#include<iostream>
#include<string>
using namespace std;
int main() {
int pulleys,weight;
float force;
cout << "Enter Number Of pulleys: ";
cin >> pulleys;
if(pulleys>0){
cout << "Enter Wieght: ";
cin >> weight;
switch (weight) {
case 0:
cout << "Enter right weight\n";
break;
case 500:
cout << "Too much weight\n";
break;
default:
force = weight / pulleys;
Page 3 of 4
cout << "Force is: " << force << endl;
break;
}
}
else {
cout << "Error!Enter correct number of pulleys" << endl;
}
system("pause");
return 0;
}
Page 4 of 4