Anda di halaman 1dari 9

INFORMATION TECHNOLOGY

INTRODUCTION TO PROGRAMMING

Tutorial Sheet A
1.

Write an algorithm to calculate and print the area and perimeter of a triangle using the formula for
perimeter 2 (Height) + Base.
(4 marks)

2.

Write an algorithm to calculate and print the area of a circle.

(4 marks)

3.

Write an algorithm to find and print the area and perimeter of a rectangle.

(4 marks)

4.

Write an algorithm to find and calculate the area of a square and find its perimeter. Your algorithm
should also print the area and perimeter of the square.
(4 marks)

5.

Write an algorithm to calculate the number of weeks worked for X days inputted. Your algorithm
should print the number of weeks.
(4 marks)

6.

Write an algorithm to enter the amount of liquid purchased in quarts and calculate its equivalent in
pints where 2 pints equals 1 quart. Print the equivalent amount.
(4 marks)

7.

Write an algorithm that prompts the user to enter the number of stages a person traveled on a bus
and calculate the total fare to be paid if 1 stage is traveled at a cost of $20. Print the total fare in
your answer.
(5 marks)

8.

Write a program in Basic, or Pascal or another program of your choice (not psuedocode) to request
the values of the acceleration of an object (from standing still) and the time taken by the object in
motion. Your program must then use the formula DISTANCE = Acceleration * Time Taken2 to
find the distance covered by the object.
Your program must print the answer.

9.

CXC Jan 2003 Quest.16


N

What does the following algorithm prints?

(4 marks)

SUM

N = 20
SUM = 0
WHILE N < 30 DO
SUM = SUM + N
N=N+3
ENDWHILE
CXC 1995 Quest. 8
1

(5 marks)

10.

Copy the following trace table. Complete the trace table, given that the number 4 is the input
value for X.
X
M
Y
Z
Read X
4
1
For M = 1 to X do
4
8
4
Y=XM
4
Z =5*YM
END
Print Z
What does the algorithm prints?

11.

CXC 1996 Quest. 8


COUNT

What is printed by the following algorithm?

(5 marks)

COUNT = 1
X=2
WHILE COUNT < 26 DO
X=X*2
Print COUNT, X
COUNT = COUNT + 5
ENDWHILE
CXC June 1995 Quest 8
12.

(4 marks)

Copy and complete the following trace table below for the algorithm given:
X=5
K = 10
SUM = 45

X
5

K
10

SUM

20

WHILE SUM < 75 DO

SUM = SUM + K
Print K
K=K+X
ENDWHILE
Print SUM
b.

What is printed by the algorithm?

CXC 1998 Quest. 9 (7 marks)

13.

a.

DIFFERENCE = 0
Input A, B
IF A <=B THEN
DIFFERENCE = A B

A
20
100
50

B
30
100
10

DIFFERENCE

ELSE
DIFFERENCE = B A
ENDIF
Print DIFFERENCE
What does the algorithm above print if the input values are as stated in the table above?
CXC 1999 Quest 9 a (3 marks)
14.

a.

Write an algorithm, which reads three numbers into variables a, b, c, and print the largest
of the three numbers inputted.
CXC 2000 Quest. 8 a (4 marks)

b.

This part is based on the algorithm given below:


SET A to 3
SET B to 5

Use the algorithm to complete


the following trace table.
A
B
SUM
3
5
1

SET SUM to 1
WHILE SUM <= 50 DO
A= A+ B
B=B+A
SUM = SUM + B

c.
15.

ENDWHILE
Print SUM
STOP
State what the algorithm prints.

CXC 2000 Quest. 8 b & c

Read Num
J=1

Num

(6 marks)

WHILE J < Num DO


X = (J * 2) 2
Print J
J=J+2
ENDWHILE
a. Given that 10 is the input value, create a trace table for the algorithm above using Num, J and
X as table headings.
(4 marks)
3

b. Given that 10 is the input value, determine the output of the algorithm.
(2 marks)
CXC 2002 Jan. Quest. 8
16.

Write an algorithm or program to read in two numbers and find the average of the numbers.
CXC 2002 June Quest 11

17.

a.

(5 marks)

Copy and complete the following trace table, for the algorithm.

X=1
Y=2
Z=3

3
4

Z=Z+X
X=ZX
Y=Z+Y
Z =YZ
Y=YXZ
Print X, Y, Z
END
b.

What is printed by the algorithm?


CXC 2002 June Quest. 14

18.

a.

(5 marks)

Copy and complete the following trace table for the algorithm given. Note there are seven
lines to be traced in the algorithm.
X

X=1
Y=2
Z=3

Y
2

X=X+Y
Y=X*Y
Z=X+Y
X=X+Y
Y=X*Y
IF Z < X, THEN X = Z
IF Z > =X, THEN Y = X
Print X, Y, Z
END
4

Z
3

b.
19.

What is printed by the algorithm?

CXC Specimen 2002 Quest. 14

(6 marks)

Copy and complete the following trace table to show the final printed values of X, Y, and Z for the
algorithm given below.
X=3

X
3

Y=2

Y
2

Z
1

Z=1
DO WHILE Z > 0 THEN
X=X*Y
Y=Y+ Z
Z=Z1
LOOP
Print X, Y, Z
END

CXC Jan 2003 Quest 14

(4 marks)

20.

Write a program, in BASIC, or PASCAL, or another programming language of your choice, not a
Psuedocode, to input a number, and print the square of that number.
CXC Jan 2003 Quest. 12
(3 marks)

21.

Write an algorithm, using either psuedocode, or language of your choice, to read in TWO values
and to print the value of the quotient that is found by dividing the Larger Number by the smaller
number.
CXC Jan 2003 Quest. 13
(5 marks)

22.

Programs are written with the general purpose of solving problems. However, it is unlikely that a
program will run completely error-free on the first attempt. (A) The process whereby a program
is checked to ensure that it does what it was designed for is important in the development of the
program. There are two main types of errors that can occur: (B) one type of error occurs when
the programmer fails to properly think through the solution to the problem and (C) the other
occurs when the programmer does not adequately know the rules of the programming
language. It is good practice to perform a (D) manual trace on the program, using (E)
appropriately selected input values, which checks each segment of the program.

23.

State the proper technical term for each of the underline phrases above labelled A E.
CXC 1999 Quest. 8 (5 marks)
Before writing a program in a (A) high level language, it is advisable to write an algorithm that
solves the problem. This algorithm can be written in (B) psuedocode and tested thoroughly for
(C) logic errors. First, you perform a (D) dry run of the algorithm using a wide variety of test
data to ensure that your algorithm works for all possible cases. Next, convert your algorithm to
the high level language. (E) Compile your program and correct any (F) syntax errors which you
may have. Run your program and use the same set of test data you used for the dry-run. If you
get the same result, your program is working correctly.
Explain the meaning of EACH of the underlined phrases labelled A F above.
CXC 2000 Quest. 3 (6 marks)
5

24.

Define the following:


a.

Source code

d.

Draw a diagram showing the relationship between the three terms above. (3 marks)
CXC 1995 Quest 9

25.

a.
b.

Explain the difference between a high level language and a machine language program.
Explain the difference between an interpreter and a compiler. CXC 1997 Quest 9 a & b
(4 marks)

26.

a.

Give two advantages of high level computer languages over low-level computer languages.
(2 marks)
Arrange the following processes in the order in which they could be done:

c.

b.

Object Code

c.

Compiler.

Loading, Creating Object code, Creating Source Code, Executing


c.

How are the terms related to each other?

CXC Jan 2003 Quest. 11

(3 marks)

(2 marks)
(3 marks)

INFORMATION TECHNOLOGY
INTRODUCTION TO PROGRAMMING

Tutorial Sheet B
1.

Write a psuedocode algorithm to read in THREE numbers and print the highest and lowest
numbers.
CXC 1996 Quest 7 (5 marks)

2.

Write an algorithm to read in TWO numbers into A and B. The algorithm should store the
smaller in A and the larger in B, and them print A and B
CXC 1996 Quest. 9b (5 marks)

3.

Write a psuedocode algorithm to read two numbers and print the lower value.
(5 marks)
CXC 1997 Quest. 9c

4.

Write an algorithm to interchange the values of TWO variables A and B. CXC 1998 Quest. 9a
(3 marks)

5.

Write a structured algorithm to read in TWO numbers and print the higher value. (4 marks)
CXC 1998 Quest 8 i.

6.

Write a structured algorithm to prompt the user to input two values which are then stored in A and
B. The algorithm must divide A by B and print the result. The algorithm must keep prompting the
user for the second number as long as the user enters 0 (zero) for the second number.
CXC 1998 Quest 9 b (7 marks)

7.

Write a psuedocode algorithm (or program) to read a number and print the following message if
the number is greater than 5:
Number is greater than five
The algorithm should print the number if it is less than or equal to 5. CXC 2002 Jan. Quest. 9b
(5 marks)

8.

A concert organizer wants to charge different entrance prices as follows:


Males over the age of 15 pay $50. Females over the age of 15 years old pay $40. Females fifteen
years old or younger must pay $20, males fifteen and under pay $30. No person under 2 years old
is allowed.
Write a program or algorithm to read the name, age and sex of EACH patron and for EACH
person, to print out the name and entrance fee. The program must stop when it encounters a
person named END.
CXC 2002 June Quest 14 (14 marks)

INFORMATION TECHNOLOGY
INTRODUCTION TO PROGRAMMING

Tutorial Sheet C
1.

Write a program to read the names and prices of 100 items, and print the names of items with price
being less that fifty dollars ($50).
CXC 2002 June Quest. 12 (5 marks)

2.

Write an algorithm to read the names and ages of 10 people and print the name of the oldest
person. Assume that no two people have the same age. Data is supplied in the following form:
Name, Age, Name, Age, etc.
CXC 1994 June Quest. 9 b (10 marks)

3.

The following data represents some sample score obtained by students in a test:
5, 4, 7, 10, 0, 6, 0, 1, 0, 9, 8, 999
999 is a dummy value that terminates the data. Write a psuedocode algorithm to read any data in
the above format, and print the number of students scoring 0 and the number of students scoring
10.
CXC 1995 June Quest. 10 (10 marks)

4.

Write an algorithm to read ELEVEN numbers, find their average and print it. The algorithm
should also print the number of times the number 6 occurs in the data.
For example, given the input data:
8, 4, 6, 9, 6, 5, 6, 10, 7, 0, 16
the algorithm should print 7 as the average and 3 as the number of times 6 occurs.
CXC 1996 June Quest. 10 (10 marks)

5.

The following data represents some sample data of the number of children in several families:
1, 3, 5, 0, 4, 6, 4, 3, 5, 2, 4, 0, 999
999 is the value that terminates the data. Write a psuedocode algorithm to read in data in the
above format, and print:
a. the number of families with no children
b. the largest number of children existing in any family CXC 1997 June Quest. 10 (10 marks)

6.

Write a structured algorithm to read the names and scores of 15 students in a class. The algorithm
must print the name of the students and his grade, which is determined according to the grading
scale below.
The algorithm must also calculate and print the average for the class.
GRADING SCALE
GRADE
SCORE
80 or more
A
Less than 80 but 60 or more
B
Less than 60 but 50 or more
C
Less than 50
F
CXC 1998 June Quest. 10

(10 marks)

7. The following data represents a sample of the batting scores (runs) of a batsman:
10, 0, 35, 47, 74, 17, 23, 106, 52, 3, 999
999 is the value, which terminates the data. Write a psuedocode algorithm (or program) to read the
data and print the batsmans highest and lowest scores (assume that there is one highest and lowest
score). The algorithm must also print the total number of runs scored by the batsman. You may
assume that all score would be less than 999.
CXC 2002 Jan Quest. 10
(10 marks)
8. Under a certain income tax system, taxation is computed according to the following:
Income Range
Below $200,000
Between $200,000
More than $400,000

Taxation
NO TAX
20% of the excess income above $200,000
$40,000 plus 40% of the excess income above $400,000

Write a structured algorithm to read the names and incomes of 15 persons, and to compute their
income taxes. For each person, the algorithm must print the name of the person alongside his or her
tax figure.
CXC 2002 Specimen Quest. 10 (10 marks)
9.

Write an algorithm, which carries out the following operations for a set of N numbers typed in by
user.
(i)
(ii)

The algorithm keeps a running total of the numbers in the set as they are typed.
The algorithm finds and prints the average of the N numbers in the set.

NOTE:

Your algorithm need not check the validity of N or any of the numbers typed.
CXC 2003 Jan. Quest. 15 (7 marks)

TOTAL MARKS 75
9

Anda mungkin juga menyukai