Lab Manual 2
Lab Manual 2
• Control Structures
CLO2
o Sequential Structure
o Decision/Selection Structure
▪ if statement
▪ if/else statement
▪ if/elif/else statement
o Repetition Structure
▪ while structure
▪ for structure
Practice Programs
Write the following program in your jupyter notebook and state the output in the space provided.
Exercise 2 x 10
1. Write a program to find the volume of cylinder (the cylinder's volume is π r² h)
2. Write a program that separately prints even numbers and odd numbers from a range
specified by the user
3. Write a program to calculate sales tax on an item sold. Consider the following
information:
Price of one packet of jellies = 10 rs
Price of one packet of juice = 50 rs
Price of one bag of chips = 40 rs
Price of one cup of ice-cream = 60 rs
Price of one bar of chocolate = 35 rs
Sales Tax = 5% of the item price
4. Write a program to calculate grade of each student. Consider the following information;
a. Grade A for students who obtain marks greater than or equal to 85%
b. Grade B when marks are greater than or equal to 75%
c. Grade C when marks are greater than or equal to 65%
d. Grade D when marks are greater than or equal to 55%
e. Grade E when marks are greater than or equal to 45%
f. Grade F when marks are below than 45%
g. Invalid marks if marks are greater than 100 or less than 0
h. Also adjust A+, B+, C+, D+, E+ grades
5. Serendipity Booksellers has a book club that awards points to its customers
based on the number of books purchased each month.
The points are awarded as follows:
• If a customer purchases 0 books, he or she earns 0 points.
• If a customer purchases 1 book, he or she earns 5 points.
• If a customer purchases 2 books, he or she earns 15 points.
• If a customer purchases 3 books, he or she earns 30 points.
• If a customer purchases 4 or more books, he or she earns 60 points.
Write a program that asks the user to enter the number of books that he or she has purchased this
month and then displays the number of points awarded.
6. Write a Menu driven program that outputs the following information about the shape:
a. For a rectangle, it outputs the area and perimeter
b. For a circle, it outputs the area and circumference
c. For a cylinder, it outputs the volume and surface area
7. Write a program to add numbers as much as the user wants. Hint: use while loop
8. This program displays the numbers 1 through 10 and their squares. Hint use for loop
9. Write a C++ Program that read an alphabet (e.g. a,b,c,d,…..z) and display whether the
input alphabet is a vowel (i.e. a, e, i, o, u) or consonant.