Chap01a - Intro To Program Development
Chap01a - Intro To Program Development
2
Computer Components
Input
Hardwar
e
Output Process
Computer Operations
Processin
• Data g • Information
• Keyboard data • Validation • Reports
• Mouse click • Calculation • Audio
• Others • Storing
• Others
Input Output
Program & Software
Computer – programmable machine designed to
follow instructions
Program – instructions in computer memory which
computer follows to perform a task
Programmer – person who writes instructions
(programs) to make computer perform a task
5
Program & Software
• Software is a collection of programs and data that
instruct the computer what to do
• Categories of software:
− System software: Operating System that
manage the computer hardware and the
programs that run on them. Examples:
Windows, UNIX, Linux
− Application software: programs that provide
services to the user. Examples : word
processing, games, programs to solve specific
problems
6
Program & Software
• The programmer uses Computer / Programming
Language to write programs
• Syntax refers to the spelling and grammars of a
programming language
• Algorithm is a sequence of instructions written for
computer to solve a problem.
7
Algorithms (Example)
Steps for a customer to buy a movie ticket
1. Queue up
2. Go to the designated counter
3. Order ticket
✔ Specify movie
✔ Specify time
✔ Specify number of tickets
4. Make payment
5. Get tickets
6. Leave the counter
Computer Languages
9
Evolution of
Computer Languages
10
Machine Language
• The computer can only understand and execute
machine language instructions
• Machine language instructions consist of binary
numbers (0s and 1s) such as 10110100000101
• It is platform-dependent
• Rather than writing programs in machine language
which is very hard, the programmers use other
programming languages
11
Symbolic/Assembly Language
• Use symbolic codes, mnemonic and meaning
abbreviations. It is also platform-dependent
• Assembler: used to translate a program written in
assembly language into machine language for
execution by the computer
• Easier to program
12
High-Level Language
13
Creating a Simple Program
• Program coding
• Text editor (such as Notepad)
• Integrated Development Environment (IDE)
• Type of application
• Console (command line)
• Windows (desktop)
• Web
Example of IDE - Visual Studio
18
Program Development
Understand
the problem
Understand the problem
• Carefully study the user
Develop a requirements.
solution
• Understand what he wants the
program to do and what kind of
Write the output he wants to have.
program
Test the
program
19
Program Development
Understand
the problem Develop a solution
• Design the logic of the program by
Develop a using tools such as:
solution − Structure chart
− Pseudocode
Write the − Flowchart
program
Test the
program
20
Program Development
Understand
the problem
Write the program
• Code the actual program by using
Develop a the preferred programming
solution
language.
Write the
program
Test the
program
21
Program Development
Understand
the problem
Test the program
• Run and test the program to
Develop a ensure it is free of logical errors.
solution
Write the
program
Test the
program
22
Example 1-1 : Rectangle
• Write a C++ program to find the area and
perimeter of a rectangle
• The area and perimeter of the rectangle
are given by the following formulas:
23
Tool: Structure Chart
• A hierarchy chart that shows the
functional flow through the program.
• Shows how the program is broken into
logical steps. Each step will be a separate
module.
24
Example 1.1: Structure chart
Area &
perimeter of
rectangular
Calculate
Get length & Display area
area &
width & perimeter
perimeter
Tool: Pseudocode (Algorithm)
26
Example 1-1 : Pseudocode
Start
1. Get length of the rectangle
2. Get width of the rectangle
3. perimeter = 2 * (length + width)
4. area = length * width
5. Display area and perimeter
End
27
Tool: Flowchart
28
Flowchart Symbols
On-page Off-page
Connector Connector
Example 1.1: Flowchart
START
Read
length &
width
area =
Length * width
perimeter =
2 * (Length + width)
Display area
& perimeter
END
Example 1-1 : C++ program
1. #include <iostream>
2. using namespace std;
3. main() {
4. int length, width, area, perimeter;
5. cout<<"Enter length and width of
rectangle\n";
6. cin>>length;
7. cin>>width;
8. area = length * width;
9. perimeter = 2*(length + width);
10. cout<< "Area = "<<area;
11. cout<< "Perimeter = "<<perimeter;
12. return 0;
13. }
31
Exercise
32
Debugging
• To find any error in the program
• Bugs – error, also known as exception, occurs during
compilation or execution.
• Common programming errors:
• Syntax errors (Compilation errors)
• Run-time errors
• Logic errors
Common programming errors
• Syntax Errors
✔ Code violation during compilation, e.g.:
o Missing semicolon (;)
o Undefined variable
o Did not close ’/*’ with ‘/’
• Run-time Errors
✔ Illegal operation occur during execution , e.g.:
o Divide a number by zero
o Open a non-existing file
o Write to a non-existing printer
Common programming errors
• Logic Errors
✔ Passed Syntax and Run-time Errors but produce
false result
✔ It is usually caused by the algorithm of the
program