You are on page 1of 4

Capital University of Science and Technology

Department of Civil Engineering

CSCE: Computer Programming: Spring 2020

Assignment 2: Conditional Statements


Maximum Marks: 20 Instructor: Ms. Maryam Zahid
Announcement Date: 7th April, 2020 Due Date: 14th April, 2020 before 11: 59 pm
Guidelines:
 You are required to submit the following:
o A picture of solution design
o Code
o Picture of program with dry run
o Picture of your output screen
 This assignment is for individual students
 Plagiarized Content will be marked ZERO
 No Late submissions will be accepted
QUESTIONS:
Question 1) Write a code that does the following:

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

Figure 1: Sample Picture of the Problem

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:

1. Accepts the number of movable pulleys used


a. If the number of movable pulleys entered is negative or zero then display the
appropriate warning message
2. Accepts the weight placed on the movable pulley (use Switch Case statement for the
following conditions)
a. If the weight entered is 500 KG display an appropriate message
b. If the weight entered is negative or zero then display the appropriate warning
message
3. Calculates the force to be applied in order to lift the weight placed on the pulley
( weight attached ¿the movable pulley )
force=
number of movable pulleys used
4. Display to the user all the entered data and the calculated force to be applied

Figure 2: Sample picture of the problem

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

You might also like