1
is a set of rules, symbols, and specified words used to construct a computer program. types of Programming Language: 1- High-level programming language. 2- Low-level programming language.
Programming Language
Low Level Language
High Level Language
Machine Language
Assembly Language
00000000 00010101 00010110 00110101 01110111
CLR ADD SUB SFT DC
Fortran COBOL C Ada BASIC Prolog Lisp C++ C#
Scientific programming Business data processing System programming Real-time distributed systems
Machine language is a collection of binary numbers represent the actual instructions used by computers. Assembly language is a language which computer operations are represented by mnemonics. A single instruction (mnemonic) is translated directly into a single machine instruction.
4
Example: Machine Language 100101 011001 100111 110011 Assembly Language ADD SUB JMP JNZ
Example: Assembly Language LDA X ADD Y SUB Z STO A C++ Language a=x+y-z
Programming is a problem-solving activity. 6 steps in problem solving using Software Development Method:
1) Specify the problem requirements 2) Analyze the problem 3) Design the algorithm to solve the problem 4) Implement the algorithm 5) Test and verify the completed program 6) Maintain and update the program
8
1) Specify the problem requirements
State the problem clearly. Get clear understanding of what is required for its solution.
2) Analyze the problem
Identify: i) Inputs (data) ii) Outputs (the desired results) iii) Additional requirements or constraints on the solution.
9
3) Design the algorithm to solve the problem
Algorithm is a list of steps for solving a problem. Use top-down design: i) List down the major steps (subproblems) ii) Solve original problem by solving each subproblems.
4) Implement the algorithm
Writing the algorithm as a program. Each algorithm step might be written into one or more statements in a programming language.
10
5) Test and verify the completed program
Test and verifying the program several times using different sets of data.
6) Maintain and update the program
Modify the program to remove previously undetected errors.
11
Example 1: You are required to write a program to convert miles to kilometers. Step 1 (Specify problem requirement): - Write a program to convert measurement from miles to kilometers only (not vice versa). Step 2 (Analyze the problem): - Problem input: distance in miles. - Problem output: distance in kilometers. - Additional requirement: 1 miles = 1.609 km
12
Step 3 (Design the algorithm): - Algorithm: i- Get the distance in miles. ii- Convert the distance to kilometers. iii- Display the distance in kilometers.
-
Detailed algorithm: i- Get the distance in miles. ii- Convert the distance to kilometers. The distance in km = 1.609 x distance in miles. iii- Display the distance in kilometers.
13
Step 4 (Implement the algorithm): - Write the algorithm in C++ program. #include <iostream.h> #define n 1.609 main() { float m, k; // input distance in miles, output-distance in km cout<<\nEnter distance in miles = ...; cin>>m; k = n*m; cout<<\nDistance in kilometers = <<k; }
Step 5 (Test and verify program): - Test the program by entering distance in miles (example: 1 miles, 10 miles, 20 miles etc..) and check the result. - Fix any problem occurs. Step 6 (Maintain and update program) - Check the program if update needed.
Flowchart:- a diagram that represents sequence of operation in a program.
Start / End
Input / Output Process
Flowline
Connector
Off page Connector
Pseudo Code:-Decision an informal language (text) that help programmers develop algorithms.
16
Example:
Flowchart Start Pseudo Code
Read x, y, z
Read x, y, z
S=x+y+z
A=S 3
Compute Sum (S) as x + y + z
Compute Average (A) as S/3
Write S, A
Display the Sum and Average
End
17
Try this..
Start
Read A, B
BIG = A SMALL= B
A<B?
BIG = B SMALL= A
Write BIG, SMALL
End
18
Once the program has been written it must be compiled and executed. This is accomplished by an editor and compiler.
Documentation
1) 2) 3) 4)
Program must be documented for future references and maintenance process. Documentation should consists of: An accurate specification of requirement Detail input, output, constraint and formula for the above problems Algorithm in the form of flowchart or pseudo code Program source complete with comment
19
Sample program which had been run and executed and the tested data. 6) Guideline on how to use the program
5)
20