Sunteți pe pagina 1din 12

SELAMAT DATANG

UNIVERSITY MALAYSIA PERLIS


School of Manufacturing Engineering

Dr Azuwir Mohd Nor


Dr Mohd Sazli Saad

EPT 162
Computer Programming
Monday

8.00 am- 11.00 a.m. MPU 2


Lecture/Lab/Tutorial

EXPECTATION
YOUR COMMITMENT TOWARDS STUDY
 YOU ARE UNIV STUDENTS
 FULL ATTENDANCE
 DO A LOT OF INDEPENDENCE STUDY


 SELF

LEARNING
SEARCH
 READING

Instructor

 INFORMATION

Dr Azuwir Mohd Nor


Dr Mohd Sazli Saad

Room: MPU 7
Room: MPU8

BE PREPARED BEFORE COMING TO


CLASS
4

Evaluation

General Information

Main Objective:
 Students

can independently write, compile,


debug and execute computer programs to
solve problems, especially engineering
related problems.
Teaching Plan
PEO & PO

Exams:


Midterm exam => 20%

Final Exam => 50%

Lab reports => 15%


Assignment/Quiz=> 15%




Assignments are assessed individually & In Group


The two tests are written test/Lab test

References

Today Outline

Hanly, J.R. and Koffman, E.B., C Program


Design for Engineers, 2nd Ed., Addison-Wesley,
2001.
ISBN : 0321204174
 Deitel & Deitel, Suhizaz Sudin, R. Badlishah and
Yasmin Yacob, C How To Program, PearsonPrentice Hall, 2006.
 Tan, H.H. and DOrazio,T.B., C Programming for
Engineering & Computer Science, Mc Graw Hill,
1999.


Computer Fundamentals
 Computer organization

and hardware

 Computer software

Programming Languages
 Machine

language

 Assembly language
 High-level language




7

Algorithm : pseudo code and flowchart


Control Structures
Simple C Program
8

Computer Fundamentals



Computer system is divided into hardware


and software.
Hardware refers to physical components of
computer which are:
 Main

Memory
Processing Unit (CPU)
 Input Device
 Output Device
 Secondary Memory Device
 Central

Components of a Computer

1-10

The latest Intel microarchitecture on the 22 nm


manufacturing process delivers significant performance
advancementsincluding vastly improved graphics,
battery life, and securityfor a zero-compromise
computing experience.
With key features such as Intel
Hyper-Threading Technology, that
allows each processor core to work on
two tasks at the same time for greater
multitasking, to the Intel Iris
graphics for stunning 3-D visuals and
faster, more advanced video and photo
editing, the 4th generation Intel
Core i7 processor delivers top-ofthe-line performance for your most
demanding tasks.

1-11

12

Central Processing Unit (CPU)

Computer Hardware


CPU

Control Unit
Input Device

Arithmetic and
Logic Unit
Register

Output Device




Main Memory

CPU is the computers administrator and is


responsible for supervising the operation of the
other sections
Consists of two functional units; control unit
and arithmetic-logic unit (ALU)
Control unit supervises all activities of the
computer system
ALU performs basic arithmetic operations and
comparison operations

Secondary Memory

13

Main Memory

14

Main Memory

keeps information from the input unit


 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.


15

Main memory can be further classified


into two types:
 Random


 Read


Access Memory (RAM)

information in RAM will be lost when the


computer is turned-off.

Only Memory (ROM)

It has been set during manufacturing process.


ROM usually contains instructions and
information considered to be fundamental to
the computer.

16

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


1000 Memory Cells in


Main Memory

 E.g.
 E.g.

program file, data fail, etc


hard disk, diskette, CD

1-17

Secondary Storage Media

18

Input/Output Devices


Input devices - feed data and programs


into computers
 E.g.

keyboard, mouse, touch screen,


scanners

Output devices - display results produced


by computer
 E.g.

1-19

monitor, printer, speaker

20

Software

Software


As a complement to hardware, computer


system needs software to solve problems.
 Software are classified into :


System software : manages the computer and


its peripheral devices (hardware)
 E.g.

Operating system (OS)


editor
 Pre-processor
 Language translator
 Linker
 Loader
 Text

 System

software
 Application software

Compiler: reads something.c source, writes something.o object.


Linker: joins several *.o files into an executable program.
Loader: code that loads an executable into memory and starts it
running.
21

Software



 Program

Programming Languages

Application software : performs specific tasks


There are two types:
 Program

22

to solve specific problems


written by user to solve specified problem

Programming language is divided into


three categories:
 Machine

Language
Language
 High-Level Language
 Assembly

E.g. word processor, desktop publishing


software, spreadsheets, database, graphics,
communication, programs perform specific tasks
such as accounting, scientific, engineering,
education, etc
23

24

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.




Relationship Between a Byte and a Bit

0101 0001 1100 0100 1011 1000


0101 1000 0101 1001 1100 0111
25

1-26

Assembly Language

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
LOAD
rate
 E.g.

Nevertheless, needs language translator


called Assembler to change Assembly
Language to Machine Code for execution
purpose
 still too long and not portable

MULT
STOR

hour
wages

27

28

High-Level Language

Algorithms






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

a process or set of rules to be followed in calculations


or other problem-solving operations, especially by a
computer.
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
E.g.
if students grade is greater than or equal to 50
Print Pass
else
Print Fail

29

30

Algorithm-Basic symbols in a
flowchart

Algorithms
Flowchart: visual-form of an algorithm
 E.g.


Start/End

Begin

Flow
direction

Process

Data

Connector
Input/Output

Process 1

Decision

Process 2
Decision

End

31

32

TRY THIS!!!

Flowchart

Pseudo code

Write a pseudo code, flowchart and program that


calculates and prints the SUM of two integers A and B.

Begin

Begin
Input A and B
Calculate A + B
Print result of SUM
End

Input
A,B

Calculate
A+ B
Print SUM

End
33

Sequence Structure

Control Structure


34

All programs could be written in terms of


three control structures:

 Sequence

structure
 Selection structure
 Repetition structure

Is a series of steps executed sequentially


by default
Pseudo code

Read num1, num2

Flowchart
Read num1, num2

Calculate total=num1+num2
Print total

total = num1+num2
print total

35

36

Selection Structure

The if Selection Structure

Used to choose among alternative courses


of action
 C has three types: if, if..else, and
switch

if structure is a single-entry/single-exit
structure
If students grade is greater than or equal to 60
Print Pass
grade >= 60

true

print Pass

false

37

Repetition Structure

The if..else Selection Structure




Specifies an action to be performed both


when the condition is true and when it is
If students grade is greater
false

Specifies a block of one or more


statements that are repeatedly executed
until a condition is satisfied
 Three types : while, for,
do-while


than or equal to 60
Print Pass
else
Print Fail
false

print Fail

grade >= 60

38

true

print Pass

39

40

10

Basics of a Typical C Program


Development Environment

The while Repetition Structure




Programmer specifies an action is to be


repeated while some conditions remain true

true
product <= 1000

product = 2 * product

false
While product is less than or equal 1000
calculate product=2 * product

41

42

Flow of Information During Program Execution

Entering, Translating,
and Running
a High-Level
Language Program

1-44

11

Simple C Program: Program to add two numbers

Any Question?

#include <stdio.h>
int main(void)
{
int A, B, SUM;
printf (input first integer \n);
scanf (%d, &A)
printf (input second integer \n);
scanf (%d, &B)

Reading assignment: Find out...


Data types?
Variables?
Arithmetic operators
Relational and Logical Operators

OUTPUT

SUM = A + B;

Input first integer


39

printf (Sum is %d\n, SUM);


return 0;
}

Input second integer


27
Sum is 66

45

46

Reference
EKT 120 notes, School of Computer &
Communication, UNIMAP.
 Hanly & Koffman, C Program Design for
Engineers. Addison Wesley, 2nd Edition,
2001.


47

12

S-ar putea să vă placă și