User interface language: English | Español

Date May 2022 Marks available 4 Reference code 22M.1.HL.TZ0.14
Level HL Paper 1 Time zone no time zone
Command term Construct Question number 14 Adapted from N/A

Question

The flowchart below represents an algorithm that allows a user to enter the number of sides, length of side and apothem (see diagram below) for a regular polygon. It then calculates and outputs the area and perimeter of this shape.

Worked example: a regular hexagon

Number of sides = 6

Length of side = 10 cm

Apothem = 8.66 cm

Perimeter = Number of sides × Length of side

               = 6 × 10               

               = 60 cm

Area =Perimeter×Apothem2


        = 60 × 8.662

        = 259.8 cm2

From the flowchart, pseudocode is to be created that will include sub‑programs to calculate and return the perimeter and area of the shape.

Construct pseudocode for the body of the following sub-program to calculate and return the perimeter of the shape.

SUB_PERIMETER(NUM_SIDES, LENGTH_SIDE)
// Pseudocode to be added
end SUB_PERIMETER
[2]
a.i.

Construct a similar sub-program to the one in part (i) to calculate and return the area of the shape.

You must use an appropriate name for the sub-program and appropriate names for the parameters.

[4]
a.ii.

Construct pseudocode based on the flowchart to collect input from the user, call the sub-programs created in parts (i) and (ii), and output the results.

[5]
a.iii.

Without using pseudocode, explain how your algorithms could be altered to also find the area and circumference of a circle.

Note:

Area of circle = πr2

Circumference of circle = 2πr

[4]
b.

Markscheme

Award [2 max]
Award [1] for a correct formula that uses the passed arguments;
Award [1] for a return statement;

Example 1:

SUB_PERIMETER(NUM_SIDES, LENGTH_SIDE)
//Pseudocode to be added
return NUM_SIDES * LENGTH_SIDE
End SUB_PERIMETER
a.i.

Award [4 max]
Award [1] for a correct sub-program (function) defined with end statement;
Award [1] for the correct arguments passed;
Award [1] for the correct use of return;
Award [1] for the correct formula used;

Example 1:

SUB_AREA(PERIM, APOTHEM)
AREA = PERIM * APOTHEM / 2
return AREA
end SUB_AREA
a.ii.

Award [5 max]
Award [1] for all three correct inputs;
Award [1] for all three inputs with appropriate prompts;
Award [1] for the correct definition of PERIM;
Award [1] for the correct call of perimeter sub-program, including variables/arguments passed;
Award [1] for the correct call of area sub-program, including variables/arguments passed;
Award [1] for the return/output of both values;

Example 1:

//Main Program
output "Number of sides?"
input NUM_SIDES
output "Length of each side?"
input LENGTH_SIDE
output "Length of apothem?"
input APOTHEM
PERIM = SUB_PERIMETER(NUM_SIDES, LENGTH_SIDE)
output "Perimeter is ", PERIM
output "Area is ", SUB_AREA(PERIM, APOTHEM)
a.iii.

Award [4 max]

Award [1] for determining whether the shape is a polygon or a circle
Award [1] for inputting the radius (if a circle);
Award [1] for the creation of new subprogram (for area) OR
                changing values of input parameters for the existing one (SUB_AREA ) OR
                the calculation using correct formula (as given in the question paper PI * RADIUS * RADIUS)
Award [1] for the creation of a new subprogram (for circumference) OR
                appropriately changing values of input parameters to the existing one (SUB_PERIMETER ) OR
                the calculation using formula (as given in the question paper 2*PI * RADIUS)
Award [1] for calling both subprograms / outputting both values
Award [1] if after the alteration of the algorithm, it should still be able to calculate the area and the perimeter of the polygon as well as the area and the circumference of the circle

Example answer 1 (with existing subprograms, after inputting the three values: NUM_SIDES, LENGTH_SIDE, APOTHEM):
check if the inputted value for the NUM_SIDES is 1 or 0 (then the shape is a circle);
then inputted value for LENGTH_SIDE is to be used as radius;
2*3.14 should be set as NUM_SIDES and LENGTH_SIDE as APOTHEM;
call already written sub-programs(SUB_AREA and SUB_PERIMETER) so that algorithm calculates/finds correct area of circle and circumference;
if the shape is not a circle then code (as in Part(a)) for the polygon ( no other changes needed);

Example answer 2 (with new subprograms for area and circumference created):
construct two new sub-programs (for example, getCircleArea and getCircumference) ;
(in the main program) ask the user if the shape is a polygon or a circle;
if it is a polygon then code is as written in part a (no changes);
if it is a circle then ask the user to input the radius;
call both new subprograms to output area and circumference/ call the getCircleArea(radius) to find area and getCircumference(radius) sub-program to find circumference;

Example answer 3 (with simple if statement and formulas given in the question paper):
ask user to input if the shape is circle and use if statement to check this input value;
if not circle then code for the polygon (as written in part a);
otherwise (it is circle!) input radius;
calculate area;
and circumference using formulas given in the question;

Note to examiners: there may be other examples of correct answers.

b.

Examiners report

Some candidates constructed excellent algorithms in part (a).

Some candidates showed little or no ability at algorithm construction.

a.i.
[N/A]
a.ii.

Some candidates did not correctly call subprograms in part (a)(iii).

a.iii.
[N/A]
b.

Syllabus sections

Topic 4: Computational thinking, problem-solving and programming » 4.3 Introduction to programming
Show 34 related questions
Topic 4: Computational thinking, problem-solving and programming

View options