Chapter 1
Chapter 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
Machine Language
Assembly Language
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
State the problem clearly. Get clear understanding of what is required for its solution.
Identify: i) Inputs (data) ii) Outputs (the desired results) iii) Additional requirements or constraints on the solution.
9
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.
Writing the algorithm as a program. Each algorithm step might be written into one or more statements in a programming language.
10
Test and verifying the program several times using different sets of data.
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.
Start / End
Input / Output Process
Flowline
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
Write S, A
End
17
Try this..
Start
Read A, B
BIG = A SMALL= B
A<B?
BIG = B SMALL= A
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