Tutorial_1_Solution
Tutorial_1_Solution
Exercise 1
ANS-
For this exercise we will use the example of making Spaghetti Bolognese
ALGORITHM: Prepare_Spaghetti_Bolognese
Input/Equipment Required Equipment_List: Large pot Large frying pan Wooden spoon
Colander Chopping board Sharp knife Measuring cups Timer
BEGIN
// Preparation Phase
// Start Sauce
END WHILE
ADD spaghetti
STIR occasionally
END WHILE
END WHEN
END WHILE
// Final Steps
END IF
END
Exercise 2:
ANS-
BEGIN
DISPLAY "Press AC button to turn ON"
IF ac_status == ON THEN
READ desired_temp
READ current_temp
START compressor
ELSE
ENDIF
READ fan_speed
// Maintain temperature
WHILE ac_status == ON
READ current_temp
CONTINUE cooling
ELSE
STOP compressor
ENDIF
ENDWHILE
ELSE
ENDIF
END
Exercise 3:
ANS-
ORIGINAL CODE
#include <stdio.h>
int main() {
return 0;
#include <stdio.h>
int main() {
return 0;
Exercise 4:
ANS-
BEGIN
READ speed_mps
BEGIN
READ ps1
READ ps2
READ logbook
READ mini_coursework
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
+ (ps2 * 0.10)
+ (logbook * 0.10)
+ (mini_coursework * 0.20)
+ (exam * 0.50) )
END
Exercise 6
ANS-
#include <stdio.h>
int main() {
while(1){
scanf("%d", &num1);
scanf("%d", &num2);
if (sum%2 == 0) {
} else if (sum == 0) {
}
printf("\n");
return 0;
Main Issue: The program confuses “even (sum % 2 == 0)” with “positive”.
Impact: Negative even sums are wrongly labeled “positive,” zero is incorrectly
labeled “positive,” and positive odd sums produce no message.
Evidence: From testing with various integer inputs, the output doesn’t match the
stated goal of telling the user if the sum is “positive, negative, or zero.”