Monday, April 17, 2006

2005 Past Paper - programming question12

As promised! Start with the programming question: Section 3, question 12.

Write an algorithm using pseudocode to do the following sequence of tasks:

a) read in 2 values
b) multiply both values by the number 10 and add the results
c) square both values and add the squares
d) check if the answer to (b) is greater than the answer to (c)
e) if the (c) answer is greater, print a statement indicating that "The squares have won". If the (b) answer is greater print "The products have produced a win"

It's worth 8 marks!

NOTE - this was an unusual question, as the problem is actually broken down into steps for you already. Normally, the question would be more like this:

B
Write an algorithm to read in 2 values. You should first multiply both values by the number 10 and add the results, then square both values and add the squares. If the answer to the multiplication is greater than the answer to the squares, print a statement indicating that "The products have produced a win", otherwise print "The squares have won".

TASK ONE
I would suggest for practice that you look at B and try now to write down the steps needed (the ALGORITHM) to produce the program.

HINT: Print out or copy the question and underline what you think are the key words. For example, the first key words are "read in 2 values".

When you have finished, you should have around 5 steps needed to write the code. If you get stuck, look back at the original question.

TASK TWO
Now try the pseudocode. Pseudocode is close to real code (such as Visual Basic), but does not need the exact syntax of any particular language. You can use words like INPUT and PRINT, and it will help you to write the actual code when you are ready.

Don't forget - READ IN 2 VALUES simply means you need to get 2 numbers INTO the computer. This is an input statement using variables. You MUST get each number in separately - in other words it is best to first write one input statement and then another one on a new line. (1 mark)

Carrying out the multiplication part involves making up a variable name for the answer. Do it correctly and you get 2 marks.

Carrying out the squares is the same kind of problem - also worth 2 marks.

Using an IF statement correctly gets 1 more mark.

Getting the correct logic in the IF statement (i.e. printing the correct phrase depending on the numbers typed in) gets 2 more marks.


If you have ANY problems with part A or part B please email me and I will try to point you in the right direction. Remember, it's not as hard as it first appears; GIVE IT A GO!

I will not be going over this question in class!

0 Comments:

Post a Comment

<< Home