You are on page 1of 18

INTRODUCTION TO COMPUTING AND PROGRAMMING

PRACTICAL 8
Problem Statement 1:Write a program that prompts the user to input a decimal number and outputs
the number rounded to the nearest integer.

16EL84 | Abdul Rehman Shah

INTRODUCTION TO COMPUTING AND PROGRAMMING

Output on screen:

Problem Statement 2:
Write a C++ program that prompts the user in seconds. The program then
outputs the elapsed time in hours, minutes, and seconds. (For example, if the
elapsed time is 9630 seconds, then the output is 2:40:30).

16EL84 | Abdul Rehman Shah

INTRODUCTION TO COMPUTING AND PROGRAMMING

16EL84 | Abdul Rehman Shah

INTRODUCTION TO COMPUTING AND PROGRAMMING

Output on screen:

Problem Statement 3:Write a program that prompts the user to input a length expressed in
centimeters. The program should then convert the length to inches (to the
nearest inch) and output the length expressed in yards, feet, and inches, in that
order. For example, suppose the input for centimeters is 312. To the nearest inch,
312 centimeters is equal to 123 inches. 123 inches would thus be output as: 3
yard(s), 1 feet (foot), and 3 inch (es) .

16EL84 | Abdul Rehman Shah

INTRODUCTION TO COMPUTING AND PROGRAMMING

16EL84 | Abdul Rehman Shah

INTRODUCTION TO COMPUTING AND PROGRAMMING

Output on screen:-

Problem Statement 4:A milk carton can hold 4.78 litres of milk. Each morning, a dairy farm ships cartons
of milk to a local grocery store. The cost of producing one litre of milk is $0.41,
and the profit of each carton of milk is $0.51. Write a program that does the
following:
a) Prompts the user to enter the total amount of milk produced in the morning.
b) Outputs the number of milk cartons needed to hold milk. (Round your answer
to the nearest integer.)
c) Outputs the cost of producing milk.
d) Outputs the profit for producing milk.

16EL84 | Abdul Rehman Shah

INTRODUCTION TO COMPUTING AND PROGRAMMING

16EL84 | Abdul Rehman Shah

INTRODUCTION TO COMPUTING AND PROGRAMMING

Output on screen:-

16EL84 | Abdul Rehman Shah

INTRODUCTION TO COMPUTING AND PROGRAMMING

PRACTICAL 9
Problem Statement 1:
Newtons law states that the force, F, between two bodies of masses M1and M2
is given by:

in which k is the gravitational constant and d is the distance between the bodies.
The value of k is approximately.
Write a program that prompts the user to input the masses of the bodies and the
distance between the bodies. The program then outputs the force between the
bodies.

16EL84 | Abdul Rehman Shah

INTRODUCTION TO COMPUTING AND PROGRAMMING

16EL84 | Abdul Rehman Shah

10

INTRODUCTION TO COMPUTING AND PROGRAMMING

Output on screen:

Problem Statement 2:
One metric ton is approximately 2205 pounds. Write a program that prompts the
user to input the amount of rice, in pounds, in a bag. The program outputs the
number of bags needed to store one metric ton of rice.

16EL84 | Abdul Rehman Shah

11

INTRODUCTION TO COMPUTING AND PROGRAMMING

Output on screen:-

16EL84 | Abdul Rehman Shah

12

INTRODUCTION TO COMPUTING AND PROGRAMMING

Problem Statement 3:
Write a logic circuit solver program in C++ that solves the following logic circuit.
Where all the inputs are logic switches (which can be either Turned ON (True, 1)
or Turned OFF (False, 0)). The program should display the output value.

16EL84 | Abdul Rehman Shah

13

INTRODUCTION TO COMPUTING AND PROGRAMMING

Output on screen:-

16EL84 | Abdul Rehman Shah

14

INTRODUCTION TO COMPUTING AND PROGRAMMING

PRACTICAL 10:
Object: Working with Conditional Control Structures of C++.
TASKS
Problem Statement 1:
There are two circular grounds Ground-A and Ground-B. Ground-A is having diameter of 15 meters and
Ground-B is having diameter of 20 meters. Ashar is running in Ground-A and Abbas is running in GroundB. Write a computer program that asks the user to input the time taken, in seconds, to complete one
compete round of the ground by both the friends and displays who is running faster.

Output on screen:-

16EL84 | Abdul Rehman Shah

15

INTRODUCTION TO COMPUTING AND PROGRAMMING

Problem Statement 2:
Write a computer program that asks the user to enter three angles of a triangle.
The program displays whether the triangle is right-angle, acute-angle, Isosceles or
obtuse-angle.

16EL84 | Abdul Rehman Shah

16

INTRODUCTION TO COMPUTING AND PROGRAMMING

Output on screen:-

Problem Statement 3:
Write a computer program that asks the user to enter date of birth and month of
birth. The program should display the zodiac star.

16EL84 | Abdul Rehman Shah

17

INTRODUCTION TO COMPUTING AND PROGRAMMING

Output on screen:-

16EL84 | Abdul Rehman Shah

18

You might also like