0% found this document useful (0 votes)
8 views

Algorithm Thinking Solution

The document discusses algorithm thinking and problem solving, providing examples of assignment, iteration, input, and output statements. It includes pseudocode for various scenarios, such as inputting patient names and validating number ranges, as well as identifying errors in pseudocode and extending algorithms to find highest and lowest marks. The content emphasizes the importance of correct syntax and logic in algorithm design.

Uploaded by

tazmeenaqeel950
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Algorithm Thinking Solution

The document discusses algorithm thinking and problem solving, providing examples of assignment, iteration, input, and output statements. It includes pseudocode for various scenarios, such as inputting patient names and validating number ranges, as well as identifying errors in pseudocode and extending algorithms to find highest and lowest marks. The content emphasizes the importance of correct syntax and logic in algorithm design.

Uploaded by

tazmeenaqeel950
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Topic :Algorithm Thinking and problem solving

QUESTION 1

4. Connect each statement type with the correct example.

• Assignment: X ← Y + Z

• Iteration: FOR X ← 1 TO 10

• Input: READ X

• Output: PRINT X

5. Data structure for storing hourly temperatures

• Data structure: Array

• Reason: An array allows you to store a fixed number of elements (e.g., 24 values for hourly
temperatures in a day) in a sequential manner, enabling easy indexing and retrieval.

6. Two selection statements in pseudocode

1. IF...THEN...ELSE

2. CASE...OF...OTHERWISE

QUESTION 2

5 (a). Purpose of each statement in the algorithm

• FOR I ← 1 TO 300: Loops through 300 iterations, one for each patient.

• INPUT Name[I]: Inputs and stores the name of each patient into the array Name[I].

• NEXT I: Ends the current iteration and moves to the next one.

(b). Another loop structure

WHILE I <= 300 DO

INPUT Name[I]

I←I+1

ENDWHILE
(c). Algorithm to input a number between 0 and 100

REPEAT

OUTPUT "Enter a number between 0 and 100:"

INPUT Number

IF Number < 0 OR Number > 100 THEN

OUTPUT "Error: Number out of range."

ENDIF

UNTIL Number >= 0 AND Number <= 100

QUESTION 3

4 (a). Why the algorithm will never end

The condition UNTIL Count = 0 will never be met because Count starts at 0 and is incremented after
each iteration. It will never go back to 0.

(b). Corrected pseudocode

Count ← 0

REPEAT

INPUT Value

IF Value >= 100 THEN

Values[Count] ← Value

Count ← Count + 1

ENDIF

UNTIL Count = 50
(c). Modify pseudocode to limit values to 100–200

Count ← 0

REPEAT

INPUT Value

IF Value >= 100 AND Value <= 200 THEN

Values[Count] ← Value

Count ← Count + 1

ENDIF

UNTIL Count = 50

QUESTION 4

3 (a). Four errors in the pseudocode

• Error 1 (Line 7): Counter is undefined.

• Correction: Replace Counter with Count.

• Error 2 (Line 10): HighestMarkStudents ← HighestMarkStudents - 1 is incorrect.

• Correction: Change -1 to +1.

• Error 3 (Line 14): Mark[Count] ← HighestMark overwrites the mark instead of assigning
HighestMark.

• Correction: Change to HighestMark ← Mark[Count].

• Error 4 (Line 18): Incorrect grammar in the output.

• Correction: Add a space after the comma in ", HighestMarkStudents,".


(b). Extend algorithm to find the lowest mark

LowestMark ← 100

LowestMarkStudents ← 0

FOR Count ← 1 TO 35

OUTPUT "Please enter student name"

INPUT Name[Count]

OUTPUT "Please enter student mark"

INPUT Mark[Count]

IF Mark[Count] = HighestMark THEN

HighestMarkStudents ← HighestMarkStudents + 1

ENDIF

IF Mark[Count] > HighestMark THEN

HighestMark ← Mark[Count]

HighestMarkStudents ← 1

ENDIF

IF Mark[Count] = LowestMark THEN

LowestMarkStudents ← LowestMarkStudents + 1

ENDIF

IF Mark[Count] < LowestMark THEN

LowestMark ← Mark[Count]

LowestMarkStudents ← 1

ENDIF

NEXT Count

OUTPUT "There are ", HighestMarkStudents, " students with the highest mark of ", HighestMark

OUTPUT "There are ", LowestMarkStudents, " students with the lowest mark of ", LowestMark

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy