You are on page 1of 3

Introduction to Computing

LAB # 6
Instructor Name: Faiza Khadim

Instructions:
 You have to submit CPP files of the program in a folder, named your Registration Number.
 You have to upload your lab tasks on CMS.
 All program codes should be written in C/C++. Students should use Visual studio compiler
for coding.
 Indent and comment your code.
 Use meaningful variable names
 Plan your code carefully on a piece of paper before you implement it.
Learning Objectives:
 Demonstrate knowledge of basic concepts of Conditional Statements (Nested, switch) and
Loops(for and while )in programming C++
 Recall previously learned basic concepts
 Understanding problem statements and designing an appropriate solution
 Solve different problems using selection statements.

Task 1: (Using Nested If else/ Multiple if)

Write a C++ program that takes 4 number from the user and print it in descending order.
Sample Output:
Enter four values: 4,10 ,55,96
Descending order: 96,55,10,4
Task 2: (Using Switch Statement)

Write a program to determine the weight of chocolates being sold. The program takes as input, the
number of chocolates being sold, weight of one chocolate in ounces and the choice of weighing i.e.
ounces, pounds, grams or kilograms. User enters ‘O’ as a choice to calculate weight in ounces, ‘P’
for pounds, ‘G’ for grams and ‘K’ for kilograms. Depending on the choice entered by the user the
program calculates the weight of chocolates. Display an appropriate message if invalid choice is
entered. Use following formulas to calculate total weight of chocolates.
For weighing in Ounces
total_weight = number_of_chocolates * weight_of_Chocolate
For weighing in Pounds
total_weight = number_of_chocolates * weight_of_Chocolate / 16
For weighing in Grams
total_weight = number_of_chocolates*weight_of_Chocolate * 28.349
For weighing in Kilograms
total_weight = number_of_chocolates*weight_of_Chocolate*28.349/1000;
Expected Output:

Enter the number of chocolates being sold 20


Enter weight of one chocolate in ounces 2
Enter the choice for weighing
Enter O to calculate in ounces
Enter P for pounds
Enter G for grams
Enter K for kilograms
Enter your Choice O
Weight in Ounces is 40

Task 3: (using while loop)


Write a program in which the user enters a number X and your program prints all the numbers from
X to zero and then back up again.
Expected Output

Enter a number: 5
54321012345

Task 4: (Using loop)


Write a C++ program to print all the divisor of number that is prompted from the user.
Expected Output
Enter a Number: 15
Divisor of 15 is=1, 3, 5, 15
Task 5: (While and for both)
Write a C++ program that take input from user and sperate it. Number can be any digit.
Expected Output
Enter a Number: 45785
Separated number : 4 5 7 8 5
End of LAB 6 😊

You might also like