Published by Patrick Mutisya · 14 days ago
Identifiers are the names we give to variables, constants, arrays, functions and other data items in an algorithm. Good identifiers:
totalScore rather than ts.totalScore) or snakecase (totalscore) – choose one style and stick to it.avg for average is acceptable, but tp is ambiguous.num for integers, is for booleans, arr for arrays.An identifier table records every data item used by an algorithm together with its type and a short description. This table is a useful reference when designing, analysing, or debugging an algorithm.
| Identifier | Data Type | Description | Example \cdot alue |
|---|---|---|---|
| numStudents | integer | Number of students in the class | 30 |
| totalMarks | integer | Sum of all marks entered | 2150 |
| averageMark | real | Average mark = \$ \frac{totalMarks}{numStudents} \$ | 71.7 |
| passedCount | integer | Number of students whose mark ≥ 50 | 24 |
| isPass | boolean | True if a particular student's mark ≥ 50 | True |
Consider the problem: “Given the marks of all students in a class, determine the average mark and how many students passed (mark ≥ 50).”
averageMark and passedCount.totalMarks – running sum of marks.numStudents – count of marks processed.isPass – temporary boolean for each mark.INPUT marks[1 … n]
SET totalMarks ← 0
SET passedCount ← 0
SET numStudents ← n
FOR i ← 1 TO n DO
SET totalMarks ← totalMarks + marks[i]
IF marks[i] ≥ 50 THEN
SET passedCount ← passedCount + 1
END IF
END FOR
SET averageMark ← totalMarks / numStudents
OUTPUT averageMark, passedCount
Write an identifier table for the following problem statement:
“A library keeps a record of each book’s ISBN (a 13‑digit number), title, author, and whether it is currently on loan. Write an algorithm that counts how many books are on loan and lists the titles of books that are not on loan.”
After completing the table, draft a brief pseudocode outline that uses the identifiers you have chosen.