BITP 1113 Programming Technique
Lecture 1 – Introduction to Computers and Programming Language
Learning Outcomes
At the end of this lecture, you should be able to
explain the use of computer programs
describe what is computer, computer system components
(hardware and software)
describe what is programs and programming language
explain the programming process
FTMK - UTeM - Semester 1 2019/2020
Why Program?
Computer – programmable machine designed to follow
instructions
Program – instructions in computer memory to make it do
something
Programmer – person who writes instructions (programs) to
make computer perform a task
SO, without programmers, no programs; without programs, a
computer cannot do anything
FTMK - UTeM - Semester 1 2019/2020
Main Hardware Component Categories:
1. Central Processing Unit (CPU)
2. Main Memory
3. Secondary Memory / Storage
4. Input Devices
5. Output Devices
FTMK - UTeM - Semester 1 2019/2020
Main Hardware Component Categories
Figure 1-1
FTMK - UTeM - Semester 1 2019/2020
Central Processing Unit (CPU)
Comprised of:
Control Unit
Retrieves and decodes program instructions
Coordinates activities of all other parts of computer
Arithmetic & Logic Unit
Hardware optimized for high-speed numeric calculation
Hardware designed for true/false, yes/no decisions
FTMK - UTeM - Semester 1 2019/2020
CPU Organization
Figure 1-2
FTMK - UTeM - Semester 1 2019/2020
Main Memory
It is volatile. Main memory is erased when program
terminates or computer is turned off
Also called Random Access Memory (RAM)
Organized as follows:
bit: smallest piece of memory. Has values 0 (off, false) or 1 (on,
true)
byte: 8 consecutive bits. Bytes have addresses.
FTMK - UTeM - Semester 1 2019/2020
Main Memory
Addresses – Each byte in memory is identified by a unique
number known as an address.
FTMK - UTeM - Semester 1 2019/2020
Main Memory
In Figure 1-3, the number 149 is stored in the byte with the address 16, and the number
72 is stored at address 23.
FTMK - UTeM - Semester 1 2019/2020
Secondary Storage
Non-volatile: data retained when program is not running
or computer is turned off
Comes in a variety of media:
magnetic: floppy disk, zip disk, hard drive
optical: CD-ROM
Flash drives, connected to the USB port
FTMK - UTeM - Semester 1 2019/2020
Input Devices
Devices that send information to the computer from
outside
Many devices can provide input:
Keyboard, mouse, scanner, digital camera, microphone
Disk drives and CD-ROM
FTMK - UTeM - Semester 1 2019/2020
Output Devices
Output is information sent from a computer program to
the outside world.
The output is sent to an output device
Many devices can be used for output:
Computer monitor and printer
Floppy, zip disk drives
Writable CD drives
FTMK - UTeM - Semester 1 2019/2020
Software – Programs That Run on a
Computer
Categories of software:
Operating system: programs 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
FTMK - UTeM - Semester 1 2019/2020
Programs and Programming Languages
A program is a set of instructions that the computer
follows to perform a task
We start with an algorithm, which is a set of well-defined
steps.
FTMK - UTeM - Semester 1 2019/2020
Example Algorithm for
Calculating Gross Pay
FTMK - UTeM - Semester 1 2019/2020
Machine Language
Although the previous algorithm defines the steps for
calculating the gross pay, it is not ready to be executed on
the computer.
The computer only executes machine language
instructions.
FTMK - UTeM - Semester 1 2019/2020
Machine Language
Machine language instructions are binary numbers, such
as
1011010000000101
Rather than writing programs in machine language,
programmers use programming languages.
FTMK - UTeM - Semester 1 2019/2020
Programs and
Programming Languages
Categories of languages:
Low-level: used for communication
with computer hardware directly.
Often written in binary machine code
(0’s/1’s) directly.
High-level: closer to human language
FTMK - UTeM - Semester 1 2019/2020
Some Well-Known Programming Languages
FTMK - UTeM - Semester 1 2019/2020
From a High-level Program to an
Executable File
a) Create file containing the program with a text editor.
b) Run preprocessor to convert source file directives to source code
program statements.
c) Run compiler to convert source program into machine instructions.
d) Run linker to connect hardware-specific code to machine instructions,
producing an executable file.
Steps b–d are often performed by a single command or button click.
Errors detected at any step will prevent execution of following steps.
FTMK - UTeM - Semester 1 2019/2020
From a High-level Program to an
Executable File
Source Code Object Code
Preprocessor Linker
Modified Executable Code
Source Code
Compiler
FTMK - UTeM - Semester 1 2019/2020
Integrated Development Environments
(IDEs)
An integrated development environment, or IDE, combine
all the tools needed to write, compile, and debug a
program into a single software application.
Examples are Microsoft Visual C++, Borland C++
Builder, CodeWarrior, etc.
FTMK - UTeM - Semester 1 2019/2020
Integrated Development Environments
(IDEs)
FTMK - UTeM - Semester 1 2019/2020
What Is a Program Made Of?
Common elements in programming languages:
Key Words
Programmer-Defined Identifiers
Operators
Punctuation
Syntax
FTMK - UTeM - Semester 1 2019/2020
Program 1-1
1 // This program calculates the user's pay.
2 #include <iostream>
3 using namespace std;
4 Key words
5 int main()
6 { Programmer-defined identifiers
7 double hours, rate, pay;
8
9 // Get the number of hours worked.
10 cout << "How many hours did you work? ";
11 cin >> hours;
12
13 // Get the hourly pay rate.
14 cout << "How much do you get paid per hour? ";
15 cin >> rate;
16
17 // Calculate the pay.
18 pay = hours * rate;
operators
19
20 // Display the pay.
21 cout << "You have earned $" << pay << endl; punctuation
22 return 0;
23 }
FTMK - UTeM - Semester 1 2019/2020
Input, Processing, and Output
Three steps that a program typically performs:
1) Gather input data:
from keyboard
from files on disk drives
2) Process the input data
3) Display the results as output:
send it to the screen
write to a file
FTMK - UTeM - Semester 1 2019/2020
The Programming Process
FTMK - UTeM - Semester 1 2019/2020
Ask yourself
Do you understand why computer program is useful?
Can you describe what are the components in a computer
system?
Do you know the two categories of programming
language?
Do you know the steps involved in programming?
FTMK - UTeM - Semester 1 2019/2020