Practice Information Technology
Practice Information Technology
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
Activity # 43 - a
Possible Solution:
In a Pseudocode, a loop is a sequence of instructions that is continually repeated until a certain
condition is reached.
Possible Solution:
1) FOR
2) WHILE DO
Possible Solution:
FOR Loop construct
This repetition statement is called bounded iteration (iteration is the repetition of a sequence of
computer instructions a specified number of times or until a condition is met). This means that a
program will count to a definite number of times and might also carry out a procedure a certain
number of times. These actions are represented using the FOR construct.
WHILE construct
This construct is called unbounded or indefinite iteration. The WHILE statement is one of the
control flow statements that enables the execution of a sequence of logic multiple times in a
loop, until a specific condition is false.
This statement is generally used when the number of iterations to be executed is not known and
cannot be estimated.
2. Write an algorithm in Pseudocode and Pascal that will prompt the user to read the
amount of rainfall in the month of his birth. Display the total rainfall for that month.
(10 marks)
1
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
Possible Solution:
PSEUDOCODE
Start
Set TOT 0
FOR RAIN_FALL 1 TO 31 DO
Write “Enter amount of rainfall”
Read TOT
Set TOT TOT +1
Set TOT TOT + RAIN_FALL
Write “The total rain fall for the month is”, TOT
ENDFOR
Stop
PASCAL
BEGIN
TOT:= 0;
FOR RAIN_FALL: = 1 TO 31 DO
BEGIN
Writeln (‘Enter amount of rainfall’);
Readln (TOT);
TOT:=TOT +1;
TOT:= TOT + RAIN_FALL;
Writeln (‘The total rain fall for the month is: ', TOT);
Readln;
END;
END.
3. Write an algorithm in Pseudocode and Pascal that will accept 47 schools in a schools’ challenge
quiz. Print the number of schools that scored 10. (10 marks)
2
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
Possible Solution:
PSEUDOCODE
Start
Set SCHOOL 0
Set COUNT 0
FOR COUNT 1 TO 47 DO
Write “Enter school’s score”
Read SCORE
IF SCORE = 10 THEN
SCHOOL SCHOOL + 1
Write “the total number of schools that scores 10 are”, SCHOOL
ELSE
Write “No school scored 10”
END
ENDFOR
PASCAL
PROGRAM Schools_Challenge_Quiz (INPUT, OUTPUT);
USES CRT;
VAR
SCHOOL, SCORE, COUNT: integer;
BEGIN
SCHOOL:= 0;
COUNT:=0;
FOR COUNT : = 1 TO 47 DO
BEGIN
Writeln (‘Enter School Score’);
Readln (SCORE);
IF SCORE = 10 THEN
BEGIN
SCHOOL:= SCHOOL +1;
Writeln (‘The total number of schools that scored 10 are: ', SCHOOL);
END
ELSE
BEGIN
Writeln (‘No school scored 10’);
END;
Readln;
END;
END;
END.
TOTAL 25 MARKS
3
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
Activity # 44 - b
1. Write an algorithm in PASCAL which will accept the gender of students at CSS and
output the number of male students as well as female students. The algorithm should
terminate when you enter “Stop”. (5 marks)
Possible Solution:
PSEUDOCODE
Start
MALE_COUNT 0
FEMALE_COUNT 0
Write “Enter student gender”
Read GENDER
WHILE GENDER <> “STOP”
IF GENDER MALE THEN
MALE_COUNT MALE_COUNT + 1
ELSE
FEMALE_COUNT FEMALE_COUNT +1
Write MALE_COUNT, “ is the number of Males”
Write FEMALE_COUNT, “is the number of FEMALES”
Write “Enter Gender or STOP to terminate the program”
Read GENDER
ENDIF
ENDWHILE
PASCAL
4
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
CLRSCR;
MALE_COUNT: =0 ;
FEMALE_COUNT:=0;
Write (‘Please enter Student Gender: ');
Readln (GENDER);
Writeln;
WHILE GENDER <> ‘STOP’ DO
BEGIN
IF GENDER = MALE THEN
BEGIN
MALE_COUNT := MALE_COUNT + 1;
Writeln (MALE_COUNT, ‘is the number of Males’);
END
ELSE
BEGIN
FEMALE_COUNT := FEMALE_COUNT + 1;
Writeln (FEMALE_COUNT, ‘is the number of Females’);
END;
BEGIN
Writeln (‘Enter GENDER or STOP to stop the program’) ;
Readln (GENDER);
END;
END;
END.
2. Write an algorithm in PASCAL that takes the age of a student and adds it to the ages of
other students to get a total. The algorithm should terminate at 0. (5 marks)
Possible Solution:
PSEUDOCODE
Start
Set AGE 0
Set TOT 0
Write “Enter Students Age”
Read AGE
WHILE AGE <> 0 DO
TOT TOT + AGE
Write TOT, “is the total number of ages in the class”
Write “Enter Age or 0 to stop the program”
Read AGE
5
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
ENDWHILE
PASCAL
BEGIN
CLRSCR;
TOT: =0 ;
AGE :=0;
Write (‘Please enter Student Age: ');
Readln (AGE);
Writeln;
WHILE AGE <> 0 DO
BEGIN
TOT: =TOT + AGE;
Writeln;
Writeln (TOT, ‘ is the total number of ages in the class’);
Writeln;
Writeln (‘Enter Age or 0 to stop the program’) ;
Readln (AGE);
END;
END.
3. Write an algorithm that will terminate by 999, that accepts the price of an item,
calculates a 20% discount and shows the result. (5 marks)
Possible Solution:
PSEUDOCODE
Start
Set TOT 0
Set PRIC 0
Write “Enter Price and Item”
Read PRICE, ITEM
WHILE PRICE <> 999 DO
Set DISCOUNT PRICE * 20/100
6
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
TOTAL 15 MARKS
7
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
Activity # 45 - c
TEST YOUR KNOWLEDGE
Chapter 36: Implementing the Program – Loop Construct in Pascal
Possible Solution:
PSEUDOCODE
Start
Set MIN 999
FOR Num 1 TO 41 DO
Write “Enter Integer”
Read Num
IF Num < MIN THEN
Set MIN Num
ENDIF
ENDFOR
Write “Lowest number is”, MIN
Stop
PASCAL
8
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
2. Write an algorithm to find the lowest in a series of integers and then terminate the
program with 0. (10 marks)
Possible Solution:
PSEUDOCODE
Start
Set MIN 999
Write “Enter Integer”
Read Num
WHILE Num <> 0 DO
IF Num < MIN THEN
Set MIN Num
ENDIF
Write “Enter integer or 0 to stop”
Read Num
ENDWHILE
Write “Lowest number is”, MIN
Stop
PASCAL
9
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
Activity # 46 - d
A variable is given a value of 10. Repeat the following and compute the number until the
number reaches 20 or greater. Ensure to add 2 to the number and print the appropriate result.
(15 marks)
Possible Solution:
PSEUDOCODE
Start
Set NUMBER 10
REPEAT
Set NUMBER NUMBER + 2
Write “The Next Number is: ”, NUMBER
UNTIL Set Counter > 20
Stop
PASCAL
BEGIN
CLRSCR;
NUMBER: = 10;
REPEAT
NUMBER: = NUMBER + 2;
Writeln ('The Next Number is:’, NUMBER);
UNTIL NUMBER > 20;
Readln;
END.
10
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
Activity # 47 - e
Possible Solution:
An array is a collection or group of data that are all of the same data type, having the same
name. An array is used to store more than one value in a variable. A perfect example of an array
is a filing cabinet. The filing cabinet stores a group or a collection of files in one place.
Possible Solution:
A. One Dimension
B. Two Dimension
A one-dimensional array is called a vector. Its elements are arranged sequentially in the
memory of the computer. An element of a vector is specified by the variable name followed by
the index of the element enclosed in parentheses.
(lettuce, tomatoes, salad dressing, steak, mashed potatoes, string beans, cake, ice cream,
coffee)
Or
you could have a two-dimensional list of three courses, each containing three things you eat:
(lettuce, tomatoes, salad dressing) and (steak, mashed potatoes, string beans) and (cake, ice
cream, coffee)
11
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
Possible Solution:
[Index range]: This represents the size of the array , which starts at 1- example [1..10].
Possible Solution:
Data Type: Arrays carry the same data type. For example an array may be an integer only, real
only, character only and / or a string only.
c. Subscript (1 mark)
Possible Solution:
An array uses what is called storage locations. These storage locations store variables with the
same data type. Now, each storage location uses the name of the array and a subscript or
index.
3. Write THREE examples of Arrays being declared with the following data types:
a. INTEGER (1 mark)
b. CHAR (1 mark)
c. REAL (1 mark)
Possible Solution:
TOTAL 12 MARKS
12
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
Activity # 48 - f
TEST YOUR KNOWLEDGE
Chapter 36: Implementing the Program – Loop Construct in Pascal
PROGRAM Segment_Code;
USES CRT;
VAR
NUMBER: Array [1..7] of Integer;
BEGIN
CLRSCR;
NUMBER [1]:=12;
13
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
NUMBER [2]:=23;
NUMBER [3]:=54;
NUMBER [4]:=65;
NUMBER [5]:=6;
NUMBER [6]:=78;
NUMBER [7]:=6;
………………
END.
b. 12.4,54.6,6.90,23.54 (5 marks)
Possible Solution:
PROGRAM Segment_Code;
USES CRT;
VAR
NUMBER: Array [1..4] of Real;
BEGIN
CLRSCR;
NUMBER [1]:=12.5;
NUMBER [2]:=54.6;
NUMBER [3]:=6.90;
NUMBER [4]:=23.54;
………………
END.
Possible Solution:
Writing to an array is the method that is used to assign values manually to an array in Pascal.
TOTAL 26 MARKS
14
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
Activity # 49 - g
Possible Solution:
Traversing array : this is the accessing of each element in an array one by one. This is done using
the FOR loop, READ / READLN statement and WRITE/WRITELN statement.
Statement #1
FOR counter: = 1 TO 8 DO
Readln (Num_Array [counter]);
Possible Solution:
FOR LOOP construct e.g.
FOR school: = 1 TO 10 DO
Readln (Num_Array [school]);
15
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
4. Write a program that stores the prices of 10 items. The program should display the 10
prices. (10 marks)
Possible Solution:
TOTAL 16 MARKS
16
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
Activity # 50 - h
Possible Solution:
2. Write a program that stores the names of eight (8) vehicle prices. The program should
display the price of the first, fourth, and last vehicle. (8 marks)
Possible Solution:
17
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
Writeln;
Writeln (‘The Third vehicle Price is : $ ‘ , VEH_PRICE [3] :0:2);
Writeln;
Writeln (‘The Fourth vehicle Price is : $ ' , VEH_PRICE [4] :0:2);
Writeln;
Writeln (‘The Eight vehicle Price is : $ ' , VEH_PRICE [8] :0:2);
END;
Readln;
END.
3. ComputerLearningEZ.com wants the names of all the programmers, database analysts and
webmasters. All this data must be stored in an array called staff. The company’s staff is 45
in total.
Possible Solution:
18
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
4. Write a program that will create an array called staff and allow the users of the program
to enter the names of each employee in that array. (4 marks)
Start
Set EMPLOYEE 0
Set STAFF: array [1..X] of sting
Write “Enter size of the array”
Read X
Write “Enter name of all employee”
FOR EMPLOYEE = 1 TO DO
Read STAFF [EMPLOYEE]
Endfor
NB: for practise attempt this question in PASCAL.
TOTAL 20 MARKS
Activity # 51 - i
1. Develop a program that will search for the number 33 in an array of 100 numbers. The
program should print the index number and what value is found. (8 marks)
Possible Solution:
19
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
found:='NO';
Writeln;
Writeln ('Now enter the number you want to searching for');
Readln (searchNUMBER);
REPEAT
counter:=counter+1;
IF NUMBER [counter] = searchNUMBER THEN
found:='YES';
UNTIL ((counter = 100) OR (found = 'YES'));
IF found = 'YES' THEN
Writeln (' Employee position found at: ' , counter)
ELSE
Writeln (' Employee position not found');
Readln;
END.
2. Write a program for a company that will search for five employees’ social security
numbers (1334, 4354, 5465, 123, and 5676) in an array of 5 numbers. The program
should print the subscript number and the value that is found. (8 marks)
Possible Solution:
BEGIN
FOR COUNTER:=1 TO 5 DO
END;
COUNTER:=0;
20
Information Technology in FOCUS for CSEC
SECTION 3 OF SYLLABUS: CHAPTER 36: Implementing the Program – Loop Constructs in Pascal
FOUND:='NO';
Writeln;
Writeln ('Now enter Social Security Number you want to searching for');
Readln (search_SS_NUMBER);
REPEAT
COUNTER:= COUNTER+1;
IF SS_NUMBER [COUNTER] = search_SS_NUMBER THEN
FOUND := 'YES';
UNTIL ((COUNTER = 5) OR (FOUND = 'YES'));
IF FOUND = 'YES' THEN
Writeln (' Social Security Number position found at: ' , COUNTER)
ELSE
TOTAL 16 MARKS
21