AST 103 Programming With C/C++ Lecture-02: Process of Writing A Program
AST 103 Programming With C/C++ Lecture-02: Process of Writing A Program
AST 103 Programming With C/C++ Lecture-02: Process of Writing A Program
January, 2018
ogramming with
Steps of writing a program
Define a problem
Analysis and designing of the problem
Pseudocode
Algorithm and
flowchart
Code (programming): Levels of
programming
Execution of code
Test and debug the program
Pseudocode:
Input a set of four course marks of first year students.
Calculate their average by dividing the sum by 4.
If the average is below 40 Print "Fail"
If the average is above or equal 40 Print "Pass"
Step 4: Algorithm and Flowchart
Algorithm: a sequence of steps (logic and instruction) for solving
a defined problem.
Flowchart: a graphical representation of the algorithm.
→ Ellipse (start or stop), parallelogram (input or output),
rectangle (computation), diamond (decision), hexagon (do
loop), circle (connection), arrow (direction of flow of control).
Algorithm:
Step 3:
If (Grade < 40) Then Print "Fail"
If (Grade >= 40) Then Print "Pass"
Start
Example
Input M1, M2, M3,M4
Grade = (M1+M2+M3+M4)/4
Yes No
Is
Grade
>40
Print Print
“Pass” “Fail”
Stop
Figure 1: Flowchart
Write an algorithm and draw a flowchart that will
calculate the roots of a quadratic equation ax2 + bx + c
= 0.
Solution cont…
Start
Input a, b, c
d = sqrt(b*b –
4*a*c) X1 = (-b +
d)/(2*a)
X2 = (-b - d)/(2*a)
Print
X1, X2
Stop
Figure : Flowchart
Back to steps
Step 5: Code
Need to implement program by writing the code
Compile the program. This means use a program called a
compiler to translate your program into something the
computer can understand
You have to translate your program design into the C
language
#include <stdio.h>
int main(void) {
printf("Good morning");
return 0;
}
Step 6: Execution of code
Run your program and see if it makes the computer do
what you wanted.
Step 7: Test and debug the program
The fact that your program runs is a good sign, but it's
possible that it could run incorrectly.
Consequently, you should check to see that your
program does what it is supposed to do. You'll find
that some of your programs have mistakes—bugs, in
computer jargon.
Debugging is the process of finding and fixing
program errors.
Step 8: Maintain and Modify the Program
Assembly level
Using English like abbreviations to represent elementary
operations-assembly languages.
Assemblers are used to convert assembly language programs to
machine language.
Programming Language
High level
High level language is a human English like language that contains
commonly used mathematical expressions.
Compilers convert high level language into machine level language.
Google drive
https://support.google.com/drive/answer/7329379