7.8 Writing and Amending Algorithms
7.8 Writing and Amending Algorithms
1. Analyse the problem and make sure that you understood it properly.
2. Determine what would be the -
Inputs,
Processes and
Outputs.
3. Break down the problem into sub-problems if it is complex.
4. Write down all the steps needed to solve the problem sequentially from start to end.
5. Determine what variables and constants need to be declared and initialized to setup
the program.
6. Determine the sequential statements and compound statements (like, selection and
looping) need to be used.
7. Construction your algorithm using either flowchart or pseudocode designing tools.
8. Making sure that it can be easily read and understood by others. Use meaningful
names for variables and constants.
9. Use several sets of test data (normal, abnormal and boundary) and trace tables to
find any errors in your algorighm.
10. Debug the errors if found, and test your algorithm until it works perfectly to
produce the desired output.
Q2. A school with 600 students wants to produce some information from the results of the
four standard tests in Maths, Science, English and IT. Each test is out of 100 marks. The
information output should be the highest, lowest and average mark for each test and the
highest, lowest and average mark overall. All the marks need to be input.
For the algorithm to be tested by dry running, I would reduce the number of students to 5 and
the number of subjects to 2.
The variable ClassSize contains the number of students in the class. The variable SubjectNo
contains the number of subjects studied. All students study the same number of subjects.
Q4. Write an algorithm that allows to input a password and check if it contains at least eight
characters. The program should ask to re-enter the password to check that both inputs are the
same.
The user is allowed three attempts at inputting a password of the correct length and a
matching pair of passwords.
The pre-defined function LEN(X) returns the number of characters in the string, X.
IF PassCheck THEN
// Output success if password is valid.
OUTPUT "Password successful"
ELSE
OUTPUT "Password failed"
ENDIF
You must use pseudocode or program code and add comment to explain how your code
works.
CASE Option OF
1:
OUTPUT “Enter your new password : ”
If password is invalid then output appropriate message with reason and ask to re-enter.
Q7. Write and test a program that uses a two-dimensional array, Game[ ] to store the
moves in a noughts and crosses game.