Lab 6 Selection Statement and Intro of Loop
Lab 6 Selection Statement and Intro of Loop
Lab 6 Selection Statement and Intro of Loop
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.
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 a number: 5
54321012345