Chap01 - Intro To Programming
Chap01 - Intro To Programming
Chap01 - Intro To Programming
Chapter 1
Introduction To Programming
Objectives
In this chapter you will:
• Program and software
• Learn about the language of a computer
• Learn about the evolution of programming languages
• Examine high-level programming languages
• Discover what a compiler is and what it does
• Examine how a high-level language program is processed
• Compilation, executing and debugging
• Good programming habits
2
Computer Components
Input
Hardware
Output Process
Computer Operations
• Data
Processing • Information
• Keyboard data • Validation • Reports
• Mouse click • Calculation • Audio
• Others • Storing
• Others
Input Output
Program and Software
5
Program and Software
6
Program and Software
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
1. Make payment
2. Get tickets
3. Leave the counter
Computer Languages
9
Evolution of Computer Languages
10
Machine Language
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
Build: To compile code
Build
Memory
5) Ready to run
CPU
(platform-dependent)
17
Program Development
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 Develop a solution
the problem
• Design the logic of the program by
using tools such as:
Develop a
solution
− Structure chart
− Pseudocode
− Flowchart
Write the
program
Test the
program
20
Program Development
Understand Write the program
the problem
• Code the actual program by using
the preferred programming
Develop a language.
solution
Write the
program
Test the
program
21
Program Development
Understand Test the program
the problem
• Run and test the program to
ensure it is free of logical errors.
Develop a
solution
Write the
program
Test the
program
22
Example 1-1 : Rectangle
23
Tool: Structure Chart
24
Example 1.1: Structure chart
Area &
perimeter of
rectangular
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