XpertSolvers: Your Partner in Building Innovative Software Solutions
If switch structure
1. Assignment Questions
Question (1):Only “if (condition) {}”
1. Write a program that inputs marks and displays “Congratulations! You have passed.”
If the marks are 40 or more.
2. Write a program that inputs two numbers and find whetherboth are equal.
3. Write a program that inputs two numbers and finds if second number is square of
first.
4. Write a program that inputs marks of three subjects. If the average of marks is more
than 80, it displays two messages “You are above standard!” and Admission granted!”
5. Write a program that inputs three numbers and displays the maximum number.
6. Write a program that inputs three numbers and displays the minimum number.
7. Write a program to input a numberand determine whether it is positive, negative or 0
8. Write a program that inputs five integers. It finds and prints the largest and smallest
integer.
9. Write a program that inputs a characterand displays whether it is vowel or not.
10. Write a program that inputs a number and finds whether it is even or odd.
Question (2):Only “if (condition) {} else{}”
1. Write a program that inputs a number and finds whether it is even or odd.
2. Write a program that inputs a year and finds whether it is leap year or not.
3. Write a program that inputs salary and grade. It adds 50% bonus if the grade is greater
than 15. It adds 25% bonus if the grade is 15 or less and then displays total salary.
4. Write a program that inputs two integer. It determines and prints it the first integer is
a multiple of second integer.
Question (3):Only “if (condition) {} elseif {} else {}”
1. Write a program that inputs test score of a student and displays his grade according to
the following criteria:
a. >=90 A
b. 80-89 B
c. 70-79 C
d. 60-69 D
e. Below 60 F
2. Write a program that calculates the electricity bill. The rates are given below:
a. If units consumed are <=300, then the cost is Rs.2 per unit.
b. If units consumed are >300 and <=500, then the cost is Rs.5 per unit.
c. If units consumed exceed 500, then the cost is Rs.7 per unit.
2. d. A line rent Rs.150 is also added to the total bill and a surcharge of 5% extra if
the bill exceeds Rs.2000.
e. Calculate the total bill with all the conditions given above.
3. Write a program that inputs radius and user’s choice. It calculates area of circle if user
enters 1 as choice. It calculates circumference if the user enters 2 as choice.
4. Write a program that inputs salary. It the salary is 20000 or more, it deducts 7% of
salary. If the salary is 10000 or more but less than 20000, it deducts 1000 from the
salary. It the salary is less than 10000, it deducts nothing. It finally displays the net
salary.
5. Write a program that inputs a characterand displays whether it is vowel or not.
Question (4):Only “Nesting of if-else”
1. Find grade using nesting in question mention above.
Question (5):Only “Logical operatorsin if ()”
1. Write a program that inputs three numbers and displays the maximum number.
2. Write a program that inputs three numbers and displays the minimum number.
3. Write a program that inputs a characterand displays whether it is vowel or not.
4. Write a program that allows the user to enter any character through keyboard and
determines whether it is a capital letter, small case letter, a digit number or a special
character.
5. Write a program that inputs a number and displays whether it is even or odd.
Question (6):Only “switch”
1. Write a program that inputs number of week’s day and displays the name of the day.
2. Write a program that inputs a characterfrom the user and checks whether it is vowel
or consonant.
3. Write a program that displays the following menu of a health club.
1. Standard Adult membership
2. Child Membership
3. Senior Citizen Membership
4. Quit the Program
5. It inputs choice and number of months and calculates membership charges are:
i. Standard Adult Membership Rs.50
ii. Child Membership Rs.20
iii. Senior Citizen Membership Rs.30
Question (7):Only “conditional/ternary operator”
1. Write a program that inputs a number and finds whether it is even or odd.
2. Write a program that inputs a number and displays whether it is divisible by 3 or not.