1 What Is Programming
1 What Is Programming
1
Definitions
Program
A set of directions telling a computer exactly what
to do.
Programming languages
Languages for specifying sequences of directions
to a computer.
Algorithm
A sequence of language independent steps
which may be followed to solve a problem.
Flowchart
Diagrammatic representation of step for solving
the given problem.
2
Many Aspects of Programming
Algorithm:
1. Start.
2. Input radius in cm.
3. Calculate, area = 3.14 * (radius * radius)
4. Display area.
5. Stop
4
Sample Algorithm
Calculate the division obtained by the student according
to inputted marks.
1. Start.
2. Accept five different subjects’ marks,
i.e. m1, m2, m3, m4, m5.
3. Calculate, per = (m1+m2+m3+m4+m5) / 5
4. If per>= 75 then display “Distinction” else
If per>= 60 then display “First class” else
If per>= 50 then display “Second class” else
If per>= 40 then display “Pass class” else
Display “Fail”.
5. Stop.
5
FLOW CHART SYMBOLS
Start / Stop
General Processing
Decision
Input / Output
Connector
Function / Subroutine
6
Calculating area of the circle.
Start
Input radius
in cm.
Calculate area =
3.14 * (radius * radius)
Display
area
Stop
7
Start
Calculate, per =
(m1+m2+m3+m4+m5) / 5
Yes
Display
per >=75 “Distinction”
No
Yes
Display
per >=60 “First Class”
No
Yes
Display
per >=50 “Second
Class”
No
Yes
Display
per >=40 “Pass Class”
No
Display
“Fail”
Stop
8
Final Maze Solving Program
step forward;
while (inside the maze?)
{
turn right;
while (facing a wall?)
{
turn left;
}
step forward;
}
9
Programming Languages
• Machine language:
It is computer’s native language having a sequence of zeroes
and ones (binary). Different computers understand different
sequences. Thus, hard for humans to understand: e.g. 0101001...
• Assembly language:
It uses mnemonics for machine language. In this each instruction
is minimal but still hard for humans to understand:
e.g. ADD AH, BL
• High-level languages:
FORTRAN, Pascal, BASIC, C, C++, Java, etc.
Each instruction composed of many low-level instructions,
closer to English. It is easier to read and understand:
e.g. hypot = sqrt(opp*opp + adj * adj);
10
Running Compiled Programs
Process:
compilation: Your program Æ executable file
machine executes your program by “running” each
machine language instruction in the executable file.
11
Software Development: A 5-Step Process
Algorithm and
Testing
flowchart
12
Errors
13
Created By,
14