Sie sind auf Seite 1von 38

PLT 101 Computer Programming

CHAPTER 1
INTRODUCTION TO COMPUTER
PROGRAMMING
(Part 1)
Lecturer: Mrs Nurul Izni Rusli
nurulizni@unimap.edu.my
UNICITI S2 BK5 Level 1

Code: PLT 101


Course Title: Computer Programming
Course Type: Core
Credit Hour: 3

Course Synopsis
One of the aspects of a good engineer is to have the capability of
integrating the hardware and the software, thus an electrical engineer
should be competence in programming.
This course introduces basic programming using high level language (C
language).

The main objective of this course is


to prepare the students

with the ability of problem solving with

programming,
familiarize with the programming tools such as organization chart,

flowchart and pseudo code and,


2

to implement them by developing C program.

Course Outcomes
CO1:

Ability to differentiate programming concepts , problem solving and problem


analysis based on a given topic.
C4, P3 Assignment, laboratory, mid-term and final examination
CO2:

Ability to solve programming techniques and tools such as flowchart and


pseudo code to design computer programs.
C3, P3 Assignment, laboratory, mid-term and final examination
CO3:

Ability to design engineering related problems using computer programming


techniques.
C5, P4 Assignment, mini project, laboratory, mid-term and final examination

Evaluation Contribution
Final Exam
Midterm Exam

10%

Laboratory

10%
40%

20%
20%

PLT101 2013/2014

Mini Project
Assignment

Schedule for RY32


Lecture 2 hours/week
UNICITI-BK5, Monday (9:00am 11:00am)
Laboratory 3 hours/week
RY32 Group1
UNICITI Computer Lab 1, Friday (8:00am-11:00am)
RY32 Group2
UNICITI Computer Lab 1, Tuesday (8:00am-11:00am)

References
Deitel P. and Deitel H., C How to Program. 7th Edition. New Jersey: Pearson-

Prentice Hall., 2012.


Cheng H. H., C for Engineers and Scientists: An Interpretive Approach. United

States: McGraw-Hill Education., 2010.


Sprankle M. and Hubbard J., Problem Solving and Programming Concepts. 9th

Edition. New Jersey: Pearson-Prentice Hall., 2011.


Hanly J. R. and Koffman E. B., Problem Solving and Program Design in C. 7th

Edition. New Jersey: Pearson-Prentice Hall., 2012.


King K. N., C Programming A Modern Approach. 2nd Edition. New York: W. W.

Norton & Co., 2008.


Dey P. and Ghosh M., Computer Fundamentals and Programming in C. 2nd

Edition. New Delhi: Oxford University Press., 2013.

Deitel P. and Deitel H.,


C How to Program. 7th Edition.,2012

Outline
Computer Fundamentals
Computer organization and hardware
Computer software

Programming Languages
Machine language
Assembly language
High-level language

Algorithm : pseudo code and flowchart


Simple C Program

Computer Fundamentals
Computer

system is divided into hardware and

software.
Hardware refers to physical components of computer

which are:
Main Memory

Central Processing Unit (CPU)


Input Device
Output Device
Secondary Memory Device

Components of a Computer

Figure 1.1 Computer hardware


9

Computer Hardware Architecture

CPU
Control Unit
Input Device

Arithmetic and
Logic Unit
Register

Main Memory
Secondary Memory

10

Output Device

Figure 1.2
Hardware Architecture

Central Processing Unit (CPU)


CPU is the computers administrator and is responsible

for supervising the operation of the other sections.


Consists of three functional units;
Control unit - supervises all activities of the computer

system
Arithmetic-logic unit (ALU) - performs basic arithmetic
operations and comparison operations
Registers - fast memory

11

Figure 1.3
The Intel Atom processor chip contains the full circuitry of a central
processing unit in an integrated circuit whose small size and low power
requirements make it suitable for use in mobile internet devices. (Intel
12

Corporation Pressroom Photo Archives)

Main Memory
Keeps information from the input unit for rapid access.
Also keeps processed information until it can be

placed on output devices.


All programs must be loaded into main memory

before they can be executed and all data must be


brought into main memory before it can be
manipulated.

13

Main Memory cont.


Main memory can be further classified into two types:
Random Access Memory (RAM)
Information in RAM will be lost when the computer is

turned-off.
Read Only Memory (ROM)
It has been set during manufacturing process. ROM usually

contains instructions and information considered to be


fundamental to the computer.

14

Figure 1.4
1000 Memory Cells in Main Memory

15

Secondary Memory
Main memory is only used during processing

following certain instructions.


Permanent information is NOT stored in main

memory but is stored in secondary memory or


external memory.
E.g. hard disk, diskette, CD/DVDs, USB stick/flash drive

16

Secondary Storage Media

Figure 1.5 Secondary storage

17

Input/Output Devices
Input devices - feed data and programs into

computers
E.g. keyboard, mouse, touch screen, scanners

Output devices display or present results produced

by computer
E.g. monitor, printer, speaker

18

(a) Notebook Computer (HP


Pavilion dv5, Courtesy of
Hewlett-Packard).
(b) Palmtop Computer (iPhone
3G, Courtesy of Apple, Inc.)
(c) Desktop Computer (iMac,
Courtesy
of
Apple,
Inc.)

Figure 1.6 Output Devices

19

Software
As a complement to hardware, computer

system needs software to solve problems.


Software are classified into:
System software
Application software

20

Software cont.
System software : manages the computer and its

peripheral devices (hardware)


E.g. Operating system (OS)
Text editor
Pre-processor
Language translator
Linker
Loader

21

Software cont.
Application software : performs specific tasks
There are TWO types:
Program to solve specific problems
Program written by user to solve specified problem
E.g. word processor, desktop publishing software,

spreadsheets, database, graphics, communication,


programs perform specific tasks such as accounting,
scientific, engineering, education.
22

Programming Languages
Programming language is divided into THREE

categories:
Machine Language

Assembly Language
High-Level Language

23

Machine Language
Language understood by the computer
Bunch of 0s and 1s
Program written in machine language can be executed

without being translated

Nevertheless, hard to learn because it is written in 0s and

1s

Program is too long to solve simple problem

Machine-dependant and not portable


E.g.
0101 0001 1100 0100 1011 1000
0101 1000 0101 1001 1100 0111
24

Figure 1.7 Relationship Between a Byte and a Bit

25

Assembly Language
Strings of 0s and 1s are replaced into instructions

which resemble English language to represent


computer operation element
Easier to understand and write
E.g.

26

LOAD
MULT
STOR

rate
hour
wages

Assembly Language cont.

Nevertheless, needs language translator called

Assembler to change Assembly Language to


Machine Code for execution purpose
Still too long and not portable

27

High-Level Language
Improves weaknesses in Machine Language and

Assembly Language
Portable
Written in one instruction to carry out several

instructions in machine level


E.g. discount_price = price discount;

Must be changed to machine code before executed,

needs compiler : a system software that translates


source program to object program
28

Algorithms

The solution to any computing problem involves


executing series of actions in a specific order

Pseudo code : artificial and informal language that


helps programmers develop algorithms

Example:
if students grade is greater than or equal to 50
Print Pass
else
Print Fail

29

Algorithms cont.
Flowchart: visual-form of an algorithm
Example:
Begin

Data

Process 1

Decision

End
30

Process 2

Algorithm-Basic Symbol in a Flowchart

Start/End

Process

Input/Output

Decision

31

Flow
direction

Connector

Flowchart (Example)
Start

read num1, num2

sum=num1+num2
print sum

End

32

TRY THIS!!!
Write a pseudo code, flowchart
and program that calculates and
prints the SUM of two integers A
and B.
Pseudo code
Begin
Input A and B
Calculate A + B
Print result of SUM
End

Flowchart
Begin
Input
A,B
Calculate
A+ B
Print SUM

End
33

Typical C Program Development


Environment

34

Figure 1.8
Entering, Translating, and Running a HighLevel Language Program

35

Figure 1.9 Flow of Information during Program Execution


36

Simple C Program:
Program to add two numbers
#include <stdio.h>
int main()
{
int A, B, Sum;
printf (input first integer \n);
scanf (%d, &A);
printf (input second integer \n);
scanf (%d, &B);
Sum = A + B;
printf (Sum is %d\n, Sum);
return 0;
}

OUTPUT
Input first integer
39
Input second integer
27
Sum is 66

37

End Week 1 Session 1


Thank You
Q & A!

3
8

Das könnte Ihnen auch gefallen