Online Class : wednesday 10 sep 2025
2210
Practice Questions
Part 1: if–else if (10 Questions)
1. Write a program that checks if a number is positive, negative, or zero using if–else if
statements.
2. Which of the following conditions is correct for checking if a number x is between 10 and
20 (inclusive)?
a) if (x >= 10 || x <= 20)
b) if (x >= 10 && x <= 20)
c) if (x <= 10 && x >= 20)
d) if (x = 10 && x = 20)
3. What will happen if none of the if–else if conditions are true and there is no else?
a) Program will crash
b) Program will skip the block
c) Program will always print zero
d) Program will ask for input again
4. Write a program that takes marks as input and displays grades: A (80+), B (70–79), C
(60–69), D (50–59), F (below 50) using if–else if.
5. Which of the following represents correct if–else if structure?
a) if() { } elseif() { } else { }
b) if() { } else if() { } else { }
c) if() { } else() { } elseif() { }
d) if() elseif() else { }
Predict the output:
int n = 5;
if (n > 10)
cout << "High";
else if (n > 3)
cout << "Medium";
else
cout << "Low";
______________________________________________________
6. Write a program that checks if a year is a leap year using if–else if.
7. Why is else if used instead of multiple if statements?
a) Faster execution
b) Less memory
c) To avoid unnecessary checking after a true condition
d) All of the above
What will be the output if x = 15 in this code?
if (x < 10)
cout << "Small";
else if (x < 20)
cout << "Medium";
else
cout << "Large";
8. Write a program using if–else if to determine whether a character is a vowel, consonant,
digit, or special symbol.
Part 2: switch–case (10 Questions)
1. Write a program that displays the day name based on a number (1 = Monday, 2 =
Tuesday, etc.) using switch–case.
2. Which of the following is not allowed in a switch expression?
a) Integer
b) Character
c) String
d) Enum
3. What is the purpose of the break statement in a switch?
a) Ends the program
b) Exits from the switch block
c) Skips a case
d) Starts a loop
Predict the output:
int x = 2;
switch(x) {
case 1: cout << "One"; break;
case 2: cout << "Two"; break;
case 3: cout << "Three"; break;
default: cout << "Other";
}
4. Write a program using switch–case to perform basic arithmetic (+, –, *, /) based on user
choice.
5. What happens if break is missing in a switch case?
a) Program ends
b) Compiler error
c) All following cases also execute
d) Nothing happens
6. Which statement is optional in a switch–case block?
a) case
b) switch
c) default
d) break
7. Can a switch statement work with floating-point numbers?
a) Yes, always
b) No, only integers and characters are allowed
c) Only if they are cast to int
d) Only if default is used
What will this code print?
char ch = 'B';
switch(ch) {
case 'A': cout << "Apple"; break;
case 'B': cout << "Ball"; break;
default: cout << "None";
}
8. Write a program using switch–case that takes a grade (A, B, C, D, F) as input and
displays a remark (Excellent, Good, Average, Poor, Fail).