Lec 2 - Programming Language, Algortihm, Pseudocode, Flow Chart
Lec 2 - Programming Language, Algortihm, Pseudocode, Flow Chart
Fundamentals
2
Levels of Programming Languages
3
Programming Languages
Load the number from memory location 2001 into the CPU
Load the number from memory location 2002 into the CPU A Lot of
Add the two numbers in the CPU
Work!
Store the result into location 2003
4
High-Level to Low-Level
Languages
• In a high-level language like C, the addition of two
numbers can be expressed more naturally:
5
Programming Languages
6
Compiling a High-Level Language
7
Interpreting a High-Level Language
9
Portability
10
Algorithms
11
Steps in Problem Solving
12
Analyze the Problem
13
Design the Solution
14
Program Components
A few basic instructions appear in every language:
Input - Get data from the keyboard, a file, or some
other device.
Output - Display data on the screen or send data to a
file or other device.
Math Perform basic mathematical operations like
addition and multiplication.
Conditional execution - Check for certain conditions
and execute the appropriate sequence of statements.
Repetition/Looping - Perform some action
repeatedly, usually with some variation.
15
Algorithm & Pseudocode
16
Algorithm & Pseudocode
17
Algorithm & Pseudocode
Pseudocode:
18
Algorithm & Pseudocode
Detailed Algorithm:
19
Flowcharts
• A flow chart:
• shows logic of an algorithm
• emphasizes individual steps and their interconnections
• e.g. control flow from one action to the next
20
Flowchart Basic Symbols
Name Symbol Use in Flowchart
21
Flowchart - Example
22
Flowcharts
Pseudocode
23
Flowcharts
Algorithm
24
Flowcharts
Lcm Lft x 30
Print
Lcm
STOP
25
What is debugging?
❖ Programming errors are called bugs and the process of tracking
them down and correcting them is called debugging.
❖ Three kinds of errors can occur in a program:
1. Syntax errors
▪ A program can only be executed if it is syntactically correct; otherwise, the
process fails and returns an error message.
▪ syntax refers to the structure of a program and the rules about that
structure.
2. Runtime errors
▪ So called because the error does not appear until you run the program.
▪ These errors are also called exceptions because they usually indicate that
something exceptional (and bad) has happened.
3. Semantic errors
▪ If there is a semantic error in the program, it will run successfully, in the
sense that the computer will not generate any error messages, but it will
not do the right thing. It will do something else. Specifically, it will do what
the programmer told it to do.
▪ But the written program does not solve the original problem. The meaning
of the program (its semantics) is wrong.
26
Exercises
ax 2 + bx + c = 0
27