TUTORIAL SHEET 1
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
Input/Ingredients Required Ingredients_List: 500g spaghetti 500g ground beef 2 onions 3
garlic cloves 2 cans crushed tomatoes 2 tablespoons olive oil Salt and pepper Italian herbs
BEGIN
// Preparation Phase
CHOP onions into small pieces MINCE garlic cloves
// Start Sauce
HEAT frying pan
ADD olive oil to pan
WHEN oil is hot
ADD chopped onions
COOK for 5 minutes
ADD minced garlic
COOK for 2 minutes
ADD ground beef
WHILE beef is not brown
STIR and break up lumps
END WHILE
ADD crushed tomatoes
ADD herbs, salt, and pepper
REDUCE heat to low
SET timer to 20 minutes
END WHEN
// Parallel Pasta Cooking
WHILE sauce is simmering
FILL large pot with water
ADD 1 tablespoon salt
BRING water to boil
WHEN water is boiling
ADD spaghetti
SET timer to 10 minutes
WHILE pasta is cooking
STIR occasionally
END WHILE
END WHEN
END WHILE
// Final Steps
DRAIN pasta in colander
IF sauce is too thick
ADD 1/4 cup pasta water
END IF
COMBINE pasta and sauce in large pot
SERVE while hot
END
Exercise 2:
ANS-
BEGIN
DISPLAY "Press AC button to turn ON"
READ ac_status // (ON or OFF)
IF ac_status == ON THEN
DISPLAY "Enter desired temperature"
READ desired_temp
// Measure the current cabin temperature
READ current_temp
// Check if cooling is needed
IF current_temp > desired_temp THEN
START compressor
START cooling fan
DISPLAY "Cooling in progress..."
ELSE
DISPLAY "Cabin already at the desired temperature"
ENDIF
// User can adjust fan speed
DISPLAY "Enter fan speed (Low, Medium, High)"
READ fan_speed
SET blower fan speed to fan_speed
// Maintain temperature
WHILE ac_status == ON
READ current_temp
IF current_temp > desired_temp THEN
CONTINUE cooling
ELSE
STOP compressor
ENDIF
ENDWHILE
ELSE
STOP cooling system
DISPLAY "AC is turned OFF"
ENDIF
END
Exercise 3:
ANS-
ORIGINAL CODE
#include <stdio.h>
int main() {
printf("You just ran your first C program, good job!");
return 0;
OUTPUT - You just ran your first C program, good job!
Modified Code for student number:
#include <stdio.h>
int main() {
printf("Student Number: 24025727\n");
return 0;
OUTPUT - Student Number: 24025727
Exercise 4:
ANS-
BEGIN
DISPLAY "Enter speed in meters per second (m/s):"
READ speed_mps
SET conversion_factor = 2.23694 // approximate
SET speed_mph = speed_mps * conversion_factor
DISPLAY "The speed in miles per hour (mph) is:", speed_mph
END
Explanation of Each Step
1. DISPLAY "Enter speed in meters per second (m/s):"
○ This is where you prompt the user to provide the speed.
2. READ speed_mps
○ Capture the user’s input (their speed in m/s) and store
it in a variable, for example, speed_mps.
3. SET conversion_factor = 2.23694
○ Prepare a conversion factor (2.23694) that converts
meters/second directly into miles/hour.
4. SET speed_mph = speed_mps * conversion_factor
○ Multiply the user’s input speed by that factor to find
the speed in mph.
5. DISPLAY "The speed in miles per hour (mph) is:", speed_mph
○ Output the converted speed to let the user see the
result.
Exercise 5: Module mark calculation pseudocode
BEGIN
// Step 1: Input marks
DISPLAY "Enter Progress Submission 1 mark (0-100):"
READ ps1
DISPLAY "Enter Progress Submission 2 mark (0-100):"
READ ps2
DISPLAY "Enter Logbook mark (0-100):"
READ logbook
DISPLAY "Enter Mini Coursework mark (0-100):"
READ mini_coursework
DISPLAY "Enter Exam mark (0-100):"
READ exam
// Step 2: Determine if any task needs a resit
// Create a boolean flag or just print messages
IF ps1 <= 39 THEN
DISPLAY "Progress Submission 1 requires a resit"
ENDIF
IF ps2 <= 39 THEN
DISPLAY "Progress Submission 2 requires a resit"
ENDIF
IF logbook <= 39 THEN
DISPLAY "Logbook requires a resit"
ENDIF
IF mini_coursework <= 39 THEN
DISPLAY "Mini Coursework requires a resit"
ENDIF
IF exam <= 39 THEN
DISPLAY "Exam requires a resit"
ENDIF
// Step 3: Calculate overall module mark
// Adjust these weightings if your module differs
SET overall_mark = ( (ps1 * 0.10)
+ (ps2 * 0.10)
+ (logbook * 0.10)
+ (mini_coursework * 0.20)
+ (exam * 0.50) )
// Step 4: Display overall module mark
DISPLAY "Overall module mark is:", overall_mark
END
Exercise 6
ANS-
#include <stdio.h>
int main() {
int num1, num2, sum;
while(1){
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
sum = num1 + num2;
printf("The sum of %d and %d is %d\n", num1, num2, sum);
if (sum%2 == 0) {
printf("The sum is positive\n");
} else if (sum == 0) {
printf("The sum is zero\n");
else if (sum < 0) {
printf("The sum is negative\n");
}
printf("\n");
return 0;
Input (num1, Sum Expected Actual Output Comments
num2)
(2, 2) 4 Positive The sum is ✓ Correct
positive
(because 4 % 2
== 0)
(2, -2) 0 Zero The sum is ✗ Incorrect (0 is
positive even, so it hits
the sum % 2 == 0
branch).
(3, 2) 5 Positive No “positive,” ✗ Incorrect (5 is
“negative,” or odd, code misses
“zero” message it entirely).
appears
(-5, 3) -2 Negative The sum is ✗ Incorrect
positive (negative even
hits sum % 2 ==
0).
(0, 0) 0 Zero The sum is ✗ Incorrect.
positive
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.”