IB DP Computer Science Topic 4: Computational thinking, problem-solving and programming -: 4.1 – General principles SL Paper 1

Question 

A teacher would like a simple program to store the names, marks and grades of students in a set of three parallel one-dimensional arrays called NAME [ ], MARK [ ] and GRADE [].
The grade boundaries for the individual grades are shown below:

     

The class has 30 students.

a. Identify two components in a conditional statement. [2]

b. Construct an algorithm using pseudocode to take the marks that have been stored in MARK [], convert them into the appropriate grade and store[5]

the calculated grades in GRADE [ ]

c. Outline how the name, mark and grade in the three arrays correspond to the same student.[2]

d. Construct an algorithm using pseudocode to output the names and grades of all students who achieve a grade of Merit or Distinction.

e. Explain how you would change your algorithm in part (d) to allow a user to choose a grade and output the names and marks of the students who have achieved this grade.

Answer/Explanation

Ans:

a. )
if;
then;
else;
Note to examiners: allow an alternative descriptive version such as:
test/condition;
action/consequence;
(optional) alternative action/consequence;

b. )
Award [1] for an appropriate loop with correct loop parameters to cover 30 array elements/all students
Award [1] for correct use of indexes in two arrays (MARK and GRADE)
Award [1] for each if statement with correct condition and grade assignment up to [4].
Note to examiners: Award [4] if candidate has correctly used an alternative conditional statement such as switch/ case.

Example answer 1:

loop COUNTER from 0 to 29
if MARK [COUNTER] >= 80
then GRADE[COUNTER] = “Distinction”
else
if MARK[COUNTER] $>^{\prime \prime}=60$
then GRADE [COUNTER] = “Merit”
else
if MARK[COUNTER $>=40$
then GRADE $[$ COUNTER] = “Pass”
else
end loop end if

Example answer 2:

COUNTER = 1
loop while COUNTER <= 30
if MARK[COUNTER-1] >= 80
then GRADE[COUNTER-1] = “Distinction”
end if
if MARK[COUNTER-1] >= 60 and MARK[COUNTER-1] < 80
then GRADE[COUNTER-1] = “Merit”
end if
if MARK[COUNTER-1} >= 40 and MARK[COUNTER-1] < 60
then GRADE[COUNTER-1] = “Pass”
end if
if MARK[COUNTER-1} < 40
GRADE[COUNTER-1] = “Fail”
end if
COUNTER = COUNTER + 1
end loop

c.)
Three arrays are parallel/ they have the same number of elements/ the same length; the same array index can be used to represent name, grade and mark of the same student/ the array index makes sure that data from the three arrays lines up;

d.)
Award [1] for correct loop to check all students
Award [1] for correct conditional statement checking correct array
Award [1] for correct output

Example answer 1 :
loop COUNTER from 0 to 29
if MARK[COUNTER] >= 60 then
output NAME[COUNTER], GRADE[COUNTER]
end if
end loop

Example answer 2:

loop C from 0 to 29
if GRADE[C].equals(“Merit”)OR GRADE[C].equals(“Distinction”)
then
output NAME[C], GRADE[C]
end if
end loop

e. )
Award [1] for an input statement before the loop;
Award [1] for changing the conditional statement so that it checks the GRADE [] array for the GRADE input (using the same variable)
Award [1] for outputting the name and marks of the student who has achieved the inputted grade
Note to examiners: Accept a written explanation or an amended algorithm that corresponds to candidate’s answer to part(d).

Example 1:
G=input ()
COUNTER $=0$
loop while COUNTER $<30$
if GRADE $[$ COUNTER $]=\mathrm{G}$
then output (NAME [COUNTER], MARK[COUNTER $]$ )
end if
COUNTER $=$ COUNTER +1
end loop

Question

Explain why abstraction is required in the design of algorithms.

Answer/Explanation

Ans:
Abstraction allows us to create a general idea of what the problem is and how to solve it;
Abstraction removes all specific detail, and any patterns that will not help in solving a problem. This helps in forming a “model” (If designers don’t abstract they may end up with the wrong solution to the problem they are trying to solve);
Abstraction is widely used because there exist a number of “patterns” in programming that keeps repeating in every application/program;
The pattern corresponding to an issue can be found, then the abstract solution to it can be found and implemented, and the problem is solved;
Most programming languages provide some built-in abstract patterns, which are easy to use (some API provides more advanced patterns);
Abstraction is the process of taking away or removing characteristics from something in order to reduce it to a set of essential characteristics; In object-oriented programming, abstraction is one of three central principles (along with encapsulation and inheritance); Through the process of abstraction, a programmer hides all but the relevant data about an object in order to reduce complexity and increase efficiency; The resulting object itself can be referred to as an abstraction, meaning a named entity made up of selected attributes and behavior specific to a particular usage of the originating entity. Abstraction is related to both encapsulation and data hiding;

Scroll to Top