T6 Homework 6.docxInterpret correct complete algorithms, Assignments of Computer Science

To interpret, correct, and complete an algorithm, you need to understand its purpose, identify any errors, and ensure it provides the expected output for all valid inputs. This involves several steps

Typology: Assignments

2024/2025

Uploaded on 05/22/2025

bananana-apple
bananana-apple 🇬🇧

4

(1)

25 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Homework 6
Interpret, correct and complete algorithms
Unit 6 Algorithms
Name:............................................................................. Class:................... Mark:................
1. The pseudocode algorithm below is intended to calculate the average birth weight of all
babies born in a hospital over a period of time, and the maximum and minimum birth weight
recorded. It does not give the correct results.
1 total = 0
2 maximum = 0
3 minimum = 100
4 numB = 0
5 weight = 0
6 while weight != -1
7 weight = float(input("Please enter weight"))
8 if weight != -1
9 total = total + weight
10 if weight > maximum
11 weight = maximum
12 endif
13 if weight < minimum
14 weight = minimum
15 endif
16 numB = numB + 1
17 endif
18 endwhile
19 average = total / numB
20 print(numB)
21 print(average)
22 print(maximum)
23 print(minimum)
(a) Give five line numbers which show the program structure sequence. [1]
(b) Give the line numbers on which iteration starts and ends. [2]
(c) Give the line numbers on which selection starts and ends. [2]
1
pf3
pf4

Partial preview of the text

Download T6 Homework 6.docxInterpret correct complete algorithms and more Assignments Computer Science in PDF only on Docsity!

Interpret, correct and complete algorithms

Unit 6 Algorithms

Name: ............................................................................. Class: ................... Mark: ................

  1. The pseudocode algorithm below is intended to calculate the average birth weight of all babies born in a hospital over a period of time, and the maximum and minimum birth weight recorded. It does not give the correct results. 1 total = 0 2 maximum = 0 3 minimum = 100 4 numB = 0 5 weight = 0 6 while weight != - 7 weight = float(input("Please enter weight")) 8 if weight != - 9 total = total + weight 10 if weight > maximum 11 weight = maximum 12 endif 13 if weight < minimum 14 weight = minimum 15 endif 16 numB = numB + 1 17 endif 18 endwhile 19 average = total / numB 20 print(numB) 21 print(average) 22 print(maximum) 23 print(minimum) (a) Give five line numbers which show the program structure sequence. [1] (b) Give the line numbers on which iteration starts and ends. [2] (c) Give the line numbers on which selection starts and ends. [2]

Interpret, correct and complete algorithms

Unit 6 Algorithms

(d) How will the user indicate that all the baby weights have been entered? [1] (e) There are two logic errors in the algorithm. Find and correct the errors. [2] (f) Complete the trace table below for the corrected algorithm, if the user enters the following values: 3.0, 4.4, 2.8, 3.4, -1 [6] total maximum minimu m numB weight average OUTPUT

  1. A program produces statistics on the number of passes and distinctions in an exam, and the number of candidates who took the exam. A student achieving a Distinction is also counted among the number of students who passed the exam. The exam is graded as follows: 50-79 Pass 80-100 Distinction The program has been written in pseudocode, but has errors in it. The programmer tests it by inputting the exam results 60, 65, 70, 90, 95, 100. The end of data entry is signified by entering a dummy mark of -1. The program outputs the following results: Number of students: 7 Number of students with pass or distinction: 6 Number of students with distinction: 0 Average mark: 1.

Interpret, correct and complete algorithms

Unit 6 Algorithms

Error 3 [Total 20 Marks]