Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

AST 103 Programming With C/C++ Lecture-02: Process of Writing A Program

Download as pps, pdf, or txt
Download as pps, pdf, or txt
You are on page 1of 21

AST 103

Programming with C/C++


Lecture-02: Process of writing a program
Tahmina Akter

Lecturer of Applied Statistics,


Institute of Statistical Research and
Training (ISRT), University of Dhaka,
Bangladesh.
Email: takter2@isrt.ac.bd

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

 Maintain and Modify the Program


Step 1: Define the program objectives
 Naturally enough, you should start with a clear idea
of what you want the program to do.
 Think in terms of the information your program
needs, the feats of calculation and manipulation the
program needs to do, and the information the
program should report back to you.
 At this level of planning, you should be thinking in
general terms, not in terms of some specific computer
language.
Step 2: Design the program
After you have a conceptual picture of what your
program ought to do, you should decide how the
program will go about it.
Choosing a good way to represent the information can
often make designing the program and processing the
data much easier.
Step 3: Pseudocode
Pseudocode is an artificial language that helps to
build an algorithm.
Example

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).

Example:Write the pseudocode, an algorithm and draw a


flowchart that will determine whether a student passed
(average marks above or equal 40) or failed. The final grade is
calculated as the average of four course marks.
Example

Algorithm:

Step 1: Input M1, M2, M3 M4.

Step 2: Grade ← (M1+M2+M3+M4)/4

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

When you create a program for yourself or for


someone else, that program could see extensive use. If
it does, you'll probably find reasons to make changes
in it. 
You could add a clever new feature. You might adapt
the program so that it runs on a different computer
system. All these tasks are greatly simplified if you
document the program clearly and if you follow sound
design practices.
Programming language
Programming Language

Based on the comprehensibility and transition steps,


programming language can be of the following levels
Machine level
Machine languages generally consist of numbers (ultimately
reduced to 1s and 0s).

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

You might also like