T4Tutorials .PK

VU Past Papers CS201-Most Importants MCQs on If/Else Structures and Decision-Making

Q#1: What is the discount rate used in the program?
(A) 5.0
(B) 10.0
(C) 15.0
(D) 0.15
Answer: (B) 10.0

Q#2: Why is it necessary to write at least one operand in decimal form in the discount calculation statement?
(A) To increase precision
(B) To simplify the calculation
(C) To avoid integer division
(D) To speed up the calculation
Answer: (C) To avoid integer division

Q#3: In the given program, what happens if the amount is not greater than 5000?
(A) The program terminates
(B) The discount is calculated
(C) The if block is executed
(D) The else block is executed
Answer: (D) The else block is executed

Q#4: What type of variables are declared in the program code?
(A) int
(B) char
(C) double
(D) float
Answer: (C) double

Q#5: According to the tips provided, what is advised for if/else structures?
(A) Avoid using braces
(B) Use single selection if statements
(C) Always use braces for clarity
(D) Use braces only for if statements
Answer: (C) Always use braces for clarity

Q#6: Which chapter of the book C++ How to Program is referenced in the reading material?
(A) Chapter 2.7
(B) Chapter 2.8
(C) Chapter 2.10
(D) Chapter 2.20
Answer: (B) Chapter 2.8

Q#7: What kind of loop structure is discussed in the lecture?
(A) for loop
(B) do-while loop
(C) while loop
(D) repeat-until loop
Answer: (C) while loop

Q#8: What does the statement sum = sum + number; do in the context of the while loop?
(A) Multiplies sum and number
(B) Initializes sum with the value of number
(C) Adds the value of number to sum
(D) Subtracts number from sum
Answer: (C) Adds the value of number to sum

Q#9: Why is it good programming practice to initialize variables when declared?
(A) It is not necessary
(B) It makes the code longer
(C) It prevents unexpected values
(D) It speeds up the program
Answer: (C) It prevents unexpected values

Q#10: What does the condition while (number <= 1000) mean in the while loop?
(A) Repeat until number is greater than 1000
(B) Repeat while number is less than or equal to 1000
(C) Repeat until number is exactly 1000
(D) Repeat until number is less than 1000
Answer: (B) Repeat while number is less than or equal to 1000

Q#11: How is the sum of integers initialized in the program?
(A) sum = 1;
(B) sum = 0;
(C) sum = number;
(D) sum = 1000;
Answer: (B) sum = 0;

Q#12: Which type of loop structure is explicitly mentioned in the flow chart?
(A) for loop
(B) do-while loop
(C) while loop
(D) repeat-until loop
Answer: (C) while loop

Q#13: What is the purpose of the statement discount = amount * (10.0 / 100);?
(A) Add a discount to the amount
(B) Calculate 10% discount of the amount
(C) Multiply the amount by 10
(D) Divide the amount by 100
Answer: (B) Calculate 10% discount of the amount

Q#14: What happens if the logical expression in the while loop becomes false?
(A) The program terminates
(B) The loop is skipped or ends
(C) The else block is executed
(D) The loop runs again
Answer: (B) The loop is skipped or ends

Q#15: How is the next integer obtained in the program?
(A) Multiplying the current integer by 2
(B) Subtracting 1 from the current integer
(C) Adding 1 to the current integer
(D) Dividing the current integer by 2
Answer: (C) Adding 1 to the current integer

Q#16: What is the type of the variable “number” used in the program?
(A) float
(B) char
(C) int
(D) double
Answer: (C) int

Q#17: In the given program, what happens when the value of “number” becomes 1000?
(A) The program terminates
(B) The discount is calculated
(C) The if block is executed
(D) The loop runs one last time and then stops
Answer: (D) The loop runs one last time and then stops

Q#18: According to the tips provided, what is recommended when using while constructs?
(A) Omit using braces
(B) Use single statements after while
(C) Use proper indentation and braces
(D) Indentation is not important
Answer: (C) Use proper indentation and braces

Q#19: Why do we declare variables as double in the program?
(A) To save memory space
(B) To simplify calculations
(C) To handle decimal values accurately
(D) To speed up the program
Answer: (C) To handle decimal values accurately

Q#20: What is the purpose of the statement number = 1; in the program?
(A) Subtracting 1 from the number
(B) Initializing the number to 1
(C) Ending the loop
(D) Multiplying the number by 2
Answer: (B) Initializing the number to 1

Q#21: What happens if the condition in the if statement is false?
(A) The program will terminate
(B) The if block will be skipped
(C) The loop will stop
(D) The else block will be executed
Answer: (D) The else block will be executed

Q#22: What will be the result if the amount is 6000 in the given program?
(A) The program will terminate
(B) The discount will be 600
(C) No discount will be applied
(D) The else block will be executed
Answer: (B) The discount will be 600

Q#23: What is the purpose of the statement sum = sum + 1;?
(A) Initializing the sum to 1
(B) Increasing the sum value
(C) Adding 1 to the sum
(D) Multiplying the number by 2
Answer: (C) Adding 1 to the sum

Q#24: How is the next integer obtained in the while loop?
(A) Adding 1 to the current integer
(B) Subtracting 1 from the current integer
(C) Multiplying the current integer by 2
(D) Dividing the current integer by 2
Answer: (A) Adding 1 to the current integer

Exit mobile version