Monday, December 12, 2011

Tutorial 2: Chapter 2 - Week 2

*Past Year Paper: December 2009

QUESTION 1 (4 Marks)
Write pseudocode for a WHILE loop to display the following numbers in the given order:
1 3 5 7 9

QUESTION 2 (4 Marks)

Explain the similarities and differences between a variable and a constant in a program.

QUESTION 3 (7 Marks)
Write pseudo-code to solve the following problem:

Your program needs to calculate the cost of paint for a rectangular wall, given the height and
width of the wall in metres and the cost of the paint as 80 pence per square metre. The result
should be printed out in pounds and pence (1 pound = 100 pence). You can assume that the
dimensions of the wall are an exact number (integer) of metres.
Your program should display the message “invalid entry” if the height and the width are the
same.
Note: Cost off Paint = height * width * cost

QUESTION 4 (10 Marks)
Write pseudocode for the Straight Selection sort algorithm to sort TEN (10) integers.

*Past Year Paper: September 2009
QUESTION 5 (4 Marks)
Give the following function, procedure and main program in pseudo-code:

      INTEGER FUNCTION sum (num1, num2 of TYPE Integer)
         RETURN num1+num2
      ENDFUNCTION

      PROCEDURE displayResult (name of TYPE String, total of TYPE
Integer)
         Display name
         Display total
     ENDPROCEDURE

     MAIN Program
         use variable:
         name of TYPE String
         num1, num2, total of Integer
         ACCEPT name
         ACCEPT num1
         ACCEPT num2
         //missing statement 1 – call the function sum
         //missing statement 2 – call the displayResult procedure

    ENDMAIN

Write the missing statements to call the function and procedure.
(Note: the total variable can be used to hold the value returned by the sum function)

QUESTION 6 (8 Marks)
State FOUR (4) reasons for using procedures or functions.

QUESTION 7 (2 Marks)
 Explain the differents between Attributes and Operations in the context of a class.

QUESTION 8 (8 Marks)
Write pseudo-code to solve the following problem:
Your system must allow the user to input FIVE (5) employee's annual incomes. If the annual
income is greater or equal to $100,000, a 10% tax on the income must be charged on the whole
salary, otherwise only 4% will be charged.

No comments:

Post a Comment