In this exercise, we shall look into the creation of a solution to a given problem. Let us assume a very basic problem to do with. We will analyse and design an algorithm for the solution.
'''
In a test of five students, the marks, 40, 78, 91, 59 and 12 were obtained.
If the test score was over 100. Find the:
1. sum of the scores obtained by the student
2. average of the score
3. number of students who scored above the average score
4. number of students who scored below the average score
'''
To analyse the sample problem above, there are three things we need to look out for in the given problem. These are:
- the input
- the output
- the process
This is simply the parameters that are given in the problem, and for the above problem, they are:
- the total number of students, which is five.
- the individual scores, which are 40, 78, 91, 59 and 12.
- the overall score, which is 100.
This is what the program is expected to do - the expected outcome, what the user would see, finally after the process. Usually, we look at the process ( calculations before the output). We are expected to compute the values for the:
- sum of the scores
- average of the scores
- number of students who scored above the average score
- number of students who scored below the average score
Usually, the desired output dictates how to compute on the input to obtain the output.
From the problem, we are to compute the sum of the scores and the others. Our focus here is to find how to achieve the output. Most often, there would be a straight forward formula to use, other than that we have to find it. So now, all we have to think about is how to compute the :
- sum of the scores
- average of the scores
- number of students who scored above the average score
- number of students who scored below the average score
The result from the computation is what becomes our output though not all becomes the output.
continuation in
exercise 5 b (Design of a solution)