Q: [9691/J-2002]
In a mathematical experiment, two six-sided dice, each labeled 1, 2, 3,
4, 5, 6, are thrown a number of times. Each time they are thrown, the
numbers on the two discs are added together. At the end of the
experiment, a report is made of the number of times each score, from 2
to 12, has occurred. Additionally, the results are reported as a
percentage of the total number of throws.
This experiment is to be simulated by using a computer. The number of
throws is to be set by the operator. Write an algorithm to simulate this
activity.
========================================
Q: [9691/J-2002]
Twenty students in a science class take five tests during the term. Each
test is out of 100 marks. The teacher wants to record the test marks for
each student and calculate their overall grades as well as for each test.
The teacher also wants to allocate a predicated grade to each student,
based on their average test mark gained in the tests so far.
The grade boundaries are as follows:
Grade Average marks
A 80 – 100
B 70 – 79.9
C 60 – 69.9
D 50 – 59.9
E 40 – 49.9
U 0 – 39.9
Write an algorithm to help the teacher achieve his objective.
========================================
Q: [9691/N-2002]
BEGIN
Read m
For a = 1 to m
read x(a)
next a
read n
for b = 1 to n
read y(b)
next b
s = t = d = 1
while s <= m and t<= n
if x(s) < y(t) then
z(d) = x(s)
s = s + 1
d = d + 1
elseif x(s) > y(t) then
z(d) = x(s)
t = t + 1
d = d + 1
else
z(d) = x(s)
s = s + 1
d = d + 1
end if
end while
while m >= s
z(d) = x(s)
d = d + 1
s = s + 1
end while
while n >= t
z(d) = y(t)
d = d + 1
t = t + 1
end while
END
(a) Implement this algorithm. Write the final out put contents of arrays
x, y and z when the algorithm is executed with the following data.
(i) 3, 1, 4, 9, 3, 2, 3, 7
(ii) 4, 2, 4, 6, 7, 3, 3, 5, 9
(b) The test data does not test all branches of the algorithm.
(i) Write down the part of the algorithm not yet tested.
(ii) Write a set of test data which will test this branch.
(iii) Using your set of test data, write down the final contents of
array z.
(c) Explain the purpose of this algorithm.
========================================
Q: [9691/N-2002]
An examination consists of two papers, each marked out of 100. Each
candidate has a four-digit candidate number.
If a candidate scores 80 or more marks on each paper, he is awarded a
DISTINCTION. If he fails to be awarded a distinction but the sum of
his marks is 120 or more, he is awarded a MERIT. If he fails to be
awarded a distinction or a merit but the sum of his marks is 100 or
more, he is awarded a PASS. If none of these conditions is met, he is
awarded a FAIL.
A computer will process and grade the examination results for
candidates taking the examinations, using the following conditions.
(i) Each candidate's number and marks will be input and then
processed.
(ii) The list of candidate's numbers and marks will be ended with the
rouge data 9999, 0, 0.
(iii) The candidate's number and DISTINCTION, MERIT, PASS or
FAIL grade will be printed as appropriate.
(iv) Following the printout of individual results, the total number of
candidates who took the examination will be printed along with the
total number of DISTINCTION, MERIT, PASS and FAIL grades
awarded.
Write an algorithm that will allow the candidates' marks to be
processed.
========================================
Q: [9691/J-2003] SPT
Factors of a number are numbers that will divide into it exactly.
(a) State the output of the following algorithm. Note: INT() gives the
integer part of a number, e.g. INT(3.22) = 3, INT(56.334) = 56
BEGIN
for n = 5 to 12
s = 0
output n
for x = 1 to INT(n/2)
y = n/x
if y = INT(n/x) then
s = s + 1
end if
END
========================================
Q: [9691-01/N-2003]
BEGIN
total = 10
repeat
read k
if k >= 2 then
total = total + k
else
k = k * k
total = total + k
end if
print total
until k = 2
print total
END
Write down the output of this algorithm with the following input:
3,5,1,2,4,0
========================================
Q: [9348-02/J-2002]
A special reaction chamber is used in a chemical company for
producing certain chemical product. Measured amounts of two
chemicals A and B are input to the chamber through valves W and X
which are then shut. Heat is applied to the chamber to bring the
chemical mixture to the required temperature. If the pressure in the
chamber becomes too great, a safety valve Y is opened to relieve the
pressure. After five minutes at the required temperature the finished
product is released from the chamber by opening valve Z. The process
is then repeated. It has been decided to automate this process using
computer control.
Write an algorithm that will control the process.
========================================
Q: [9348-02/J-2001]
A prime number is any whole number (integer) which has only two
factors, 1 and the number itself. (That is, the number is only divisible
by 1 and itself, leaving no remainder.)
Example: 5 is a prime number because its only factors are 1 and 5.
Exception to this rule is 1, which is not a prime number.
(a) A mathematician wishes to print out all the prime numbers up to
1000, and also print the total of the prime numbers up to 1000. Write
an algorithm which allow the mathematician to do this.
(b) Rewrite the algorithm to give the same output for first 1000 prime
numbers.
========================================
Q: [9348-01/N-2000]
The following algorithm describes a binary search for finding a name in
an alphabetically ordered array of N names.
BEGIN
first = 1
last = N
item = ""
Input item
repeat
mid = INT((first+last)/2)
if mid < item then
first = mid + 1
else
last = mid - 1
end if
until (first > last) or (mid = item)
END
One hundred thirty six (136) names are stored in the array and
Hawkstone is the 42nd name.
(a) Write down index numbers of the subscripts which are examined
while searching for Hawkstone.
(b) If the name being searched for is not in the array, what is the largest
number of subscripts that may need to be checked before the searched
ends with no result?
========================================
Q: [9348-02/J-2000]
A large tire company specializes in replacing tyres on private cars. They
stock a large number of tyres, which are of three types:
High performance tyres (H)
Maximum grip tyres (M)
General purpose tyres (G)
Each type of tyre comes in four different sizes: 14, 15, 16, 17.
A computer terminal is installed on the forecourt at company's
outlet, which will allow customers to input their requirements and
will then output the price of the tyres.
In addition to requiring input of type of tyre (T) and size of tyre (S),
the system also asks for the number of tyres required (N). One tyre
or two tyre are standard requests and have no effect on price output,
four tyres carries a discount of 20% in the cost of each tyre, while
three tyres is considered unsafe because one old tyre will still be left
on the car and no price will be quoted.
Write an algorith that will ask for the required input and output a
suitable response.
========================================
Q: [9348-01/N-1995]
The elements of an array are numbered 0 to MAX. It is wished to copy
all the data items stored in the part of the array between START and
FINISH to a different position in the array, the item at START moving
to NEWSTART.
Describe in detail an algorithm to accomplish this. You may assume
that no items will be moved beyond the range of the array, but
remember that the copying may be in either direction, and that the new
position may overlap the old.
========================================
Q: [9348-01/N-1995]
The manager of a supermarket wishes to know the least number os
checkouts needed at different times of the day in order that the
checkout staff are kept busy, but without queues becoming unduly
long. A computer simulation is being designed to show how the queue
lengths are likely to vary under different conditions. At a certain time
of day there are six checkouts open and the number of customers
arriving during any one-minute period is equally likely to be 0, 1, 2, 3,
4, 5 or 6. Each customer joins the shortest of the six queues, and, after
waiting in the queue (if there is one), is equally likely to require 1, 2, 3
or 4 minutes at the checkout point.
(a) Write a subroutine to determine which of the six queues is the
shortest.
(b) Write an algorithm, using the subroutine you wrote in part (a)
above, to run the simulation over a period of 60 minutes. You may
assume a random number generator function RAN().
(c) Modify the algorithm to also output the length of time each
customer waits in the queue before being served at the checkout point.
========================================
Q: [9348-02/N-1995]
The program RADIX_CONVERT, listed below, calls a recursive
procedure, OUT. The program is run, and the values 46 and 3 are
input. Write down, in the correct order, all the values printed. Note
that INT(x/y) will return the integer part of the division while the
expression x MOD y will return the remainder.
procedure RADIX_CONVERT
integer : a
integer : b
input a
input b
OUT(a, b)
end procedure
procedure OUT(x, y)
integer : a
integer : b
a = INT(x/y)
b = x MOD y
if a > 0 then
OUT(a, y)
end if
print b
end procedure
========================================
Q: [7010-01/J-2002]
Write an algorithm that will take information about each transaction at
a supermarket till, calculate and output
a) the number of sales
b) the number of refunds
c) the total amount of money in the till
========================================
Q: [7010-01/N-2002]
Read this algorithm
BEGIN
total_1 = 0
total_2 = 0
counter = 1
while counter < 8
counter = counter + 1
input number
if number > 0 then total_1 = total_1 + number
if number < 0 then total_2 = total_2 + number
end while
output total_1
output total_2
END
(a) Write down the output if the following numbers are input.
4, 1, -3, 2, -5, 0, 6
(b) Modify the algorithm so that it will accept any number of numbers,
the input is terminated by a rouge value and the output is the total of
all the numbers input except the rouge value.
========================================
Q: [7010-01/N-2002]
Write an algorithm that will input any three different numbers and then
print them out in ascending order.
========================================
Q: [7010-01/J-2003]
A school wants to monitor the number of hours spent by a class of 30
students on the Internet. Write an algorithm which will:
a) for each student, record the times logged on and logged off
b) calculate the length of times each student spends online
c) calculate and output the average length of time per day spent by
each student on the Internet.
========================================
Q: [C Programming Book]
A program is required which will read in the breadth and height of a
rectangle and which will output the area and the length of the
perimeter of the rectangle. Write an algorithm for this problem.
========================================
Q: [C Programming Book]
A series of positive and negative numbers are entered in a list. Write an
algorithm that will sum all postive number and negative numbers
seperately.
========================================
B
Write an algorithm that inputs three numbers from the user and outputs
the largest of the three.
------------------------------------------------------------------------
B
Rewrite the algorithm in #1 to output the smallest of the three numbers.
------------------------------------------------------------------------
B
Write an algorithm that inputs any five numbers and computes their
average and outputs the result.
------------------------------------------------------------------------
B
Write an algorithm that inputs user's age in years and outputs the age in
days, hours, minutes and seconds.
------------------------------------------------------------------------
B
Write and algorithm that inputs any ten numbers (positive or negative)
from the user and outputs the sum of all positive numbers entered.
------------------------------------------------------------------------
B
Write an algorithm that inputs a number and finds out if it is an even
number. The output should be a message in case the number is even.
------------------------------------------------------------------------
B
Write an algorithm to find out the first nine even numbers.
------------------------------------------------------------------------
B
Write an algorithm to find out the first nine odd numbers.
------------------------------------------------------------------------
I
Write an algorithm that inputs a number from the user and finds out if
it is a Prime number.
------------------------------------------------------------------------
I
Write an algorithm that finds out the first five Prime numbers.
------------------------------------------------------------------------
B
Write an algorithm that inputs a series of positive and negative numbers
and sums all negative numbers and positive numbers separately.
------------------------------------------------------------------------
I
Write an algorithm that inputs ten numbers from user and sums all numbers
that were greater than the first number entered.
------------------------------------------------------------------------
I
Write an algorithm that inputs a number from the user and finds out if it
is a Perfect number or not.
------------------------------------------------------------------------
I
Write an algorithm that finds Perfect numbers from 1 to 10000.
------------------------------------------------------------------------
I
Write an algorithm that inputs prices of three computers and prints them
in order of most expensive to least expensive.
------------------------------------------------------------------------
I
A doctor in a school has to take heights of four students in meters and
then put them in order of tallest to shortest. Write an algorithm that
performs this procedure.
------------------------------------------------------------------------
I
Write an algorithm that accepts a positive number from the user and
outputs its Factorial.
------------------------------------------------------------------------
I
Write an algorithm that prints first 100 Prime numbers.
------------------------------------------------------------------------
B
Write an algorithm that inputs student's marks for three subjects and
shows the grade by checking where the average falls according to this
formula:
A* = 90 - 100
A = 80 - 89
B = 70 - 79
C = 60 - 69
D = 50 - 59
E = 40 - 49
U below 40
__________________________________________
I
A client wants to buy a house from the bank. The bank will charge him
according to this formula:
total price = base price + (interst rate * loan period) + commission
The interest rates and commisions are as follows:
TERM INTEREST COMMISSION
---------------------------------------------------------------------
1 - 5 year plan 10% 2% of base price
6 - 9 year plan 15% 3% of base price
10 year plan 20% 4% of base price
Write an algorithm that calculates the total price by inputing the required data.
____________________________________________
A Computerized Voting Machine
-----------------------------------------------------
The department of elections requires a computerized voting machine
that can accept public votes and output the result automatically. The
following are the requirements.
Displays
--------------
1. There should be a menu (any style) that should display these
options:
a. Voting Section
b. Results Section
c. Save/Load Results
2. The machine should be able to display THREE candidates on the
screen.
Input
---------
1. The machine should enable the voter to choose ONLY one of the
candidate.
2. Show a confirm button to finalize the vote. When clicked, voter's
turn is over and next voter will be able to cast his/her vote.
Output
-----------
1. The machine should be able to display the statistics of the voting.
This should include:
a. Total Number of Votes
b. Number of Votes taken by each candidate
c. Percentage of votes taken by each candidate
2. The machine should be able to save the above results of the election.
4. The machine should be able to load the above results of the election and
display them.
-----------------------------------------------------------------------------------------------------------