programming tools
programming tools
LECTURE 6
Program Development tools: Flow
charts and algorithms.
3
A problem scenario
In our example, we well understand that the input is a bunch of grades. But we need to
understand the format of the grades.
Each grade might be a number from 0 to 100 or it may be a letter grade from A+ to F. If it
is a number, the grade might be a whole integer like 73 or it may be a real number like
73.42.
We need to understand the format of the grades in order to solve the problem.
We also need to consider missing grades. What if we do not have the grade for every
student (e.g., some were away during the test) ? Do we want to be able to include that
person in our average (i.e., they received 0) or ignore them when computing the average ?
We also need to understand what the output should be. Again, there is a formatting issue.
Should we output a whole or real number or a letter grade ? Maybe we want to display a
pie chart with the average grade. It is our choice.
Finally, we should understand the kind of processing that needs to be performed on the
6
data. This leads to the next step
Formulate a model
10
Pseudocode Vs Flowchart
Writing a program is often called "writing code" or “implementing an
algorithm”.
The code (or source code) is the program itself.
The code is written by using a programming language that is best suited
for the job.
A programming language is a vocabulary and set of grammatical rules
for instructing a computer or computing device to perform specific tasks.
Some examples of programming language are BASIC, C, C++, COBOL,
Java, FORTRAN, Ada, Python (etc). 12
Algorithm (Pseudocode) to Program
S/ Pseudocode Processing code (i.e., program)
N
1. set the sum of the grade values to 0. int sum int sum = 0;
= 0;
2. load all grades x1 … xn from file. byte[] x = loadBytes("numbers");
13
Test the Program
Once you have a program written that compiles, you need to make sure that it
solves the problem that it was intended to solve and that the solutions are correct.
Therefore the program is run in order to evaluate the compiled instructions.
After running the program, if all is well, then a correct output displayed.
It is possible however, that the program works correctly for some set of data input
but not for all.
If the output of the program is incorrect,
it is possible that the algorithm was not converted properly into a proper program.
It is also possible that the algorithm itself is flawed.
Or some instructions where written and performed out of sequence.
Whatever happened, such problems with your program are known as bugs. 14
Test the Program
16