Transcript
Page 1: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Week 1 Introduction to Computers and

Programming Languages

UniMAP Sem II – 12/13

EKT120: Computer Programming 1

Page 2: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

General Information• Contributes 4 units:

• 2 hours – lectures• 4 hours – labs

• Main Objective:• Students can independently write, compile, debug and execute

computer programs to solve problems, especially engineering related problems.

UniMAP Sem II – 12/13

EKT120: Computer Programming 2

Page 3: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Course Outcomes• Ability to define and describe programming concepts and principles.

• Ability to apply programming techniques and tools such as flowchart and pseudo code to design computer programs.

• Ability to apply GNU/Linux for coding, compiling, executing and debugging computer programs.

• Ability to solve engineering related problems using computer programming techniques.

UniMAP Sem II – 12/13

EKT120: Computer Programming 3

Page 4: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Overall Evaluation• 4 main components:

• Theoretical Tests (2) => 20% (Test1 = 10%, Test2 = 10%)

• Lab Assignments (4) => 30% (Asg1 = 6%, Asg2 = 6%, Asg3 = 8%, Asg4 = 10%)

• Lab Test => 10%• Final Exam => 40%

• Assignments are assessed individually • The two tests are written tests

UniMAP Sem II – 12/13

EKT120: Computer Programming 4

Page 5: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

References

• Deitel & Deitel, Sudin, S., Ahmad, R. Badlishah, and Yacob, Y., “C How to Program”, Pearson-Prentice Hall, 2006.

• Cheng, H., “C for Engineers and Scientists”, McGraw Hill, 2010.

• Hanly, J.R. and Koffman, E.B., “C Program Design for Engineers”, 2nd Ed., Addison-Wesley, 2001.

ISBN : 0321204174UniMAP Sem II – 12/13

EKT120: Computer Programming 5

Page 6: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Notes

• This course is NOT about the language per se, it is about problem solving, analytical skills and to apply C to solve problems.

• Write C program in Linux environment.• Do early reading.• Do not hesitate to ask during lecture sessions.

UniMAP Sem II – 12/13

EKT120: Computer Programming 6

Page 7: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Outline• Computer Fundamentals

• Computer organization and hardware• Computer software

• Programming Languages• Machine language• Assembly language• High-level language

• Algorithm : pseudo code and flowchart

• Control Structures

• Simple C ProgramUniMAP Sem II – 12/13

EKT120: Computer Programming 7

Page 8: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

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

UniMAP Sem II – 12/13

EKT120: Computer Programming 8

Page 9: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

UniMAP Sem II – 12/13

EKT120: Computer Programming 9

Figure 1.1 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 Corporation Pressroom Photo Archives)

Page 10: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Figure 1.2

(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.)

UniMAP Sem II – 12/13

EKT120: Computer Programming 10

Page 11: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Figure 1.3 Components of a Computer

UniMAP Sem II – 12/13

EKT120: Computer Programming 11

Page 12: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Computer Hardware

UniMAP Sem II – 12/13

EKT120: Computer Programming 12

Input Device Output Device

Secondary Memory

Control UnitArithmetic and

Logic UnitRegister

CPU

Main Memory

Page 13: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Central Processing Unit (CPU)

• CPU is the computer’s 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

UniMAP Sem II – 12/13

EKT120: Computer Programming 13

Page 14: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

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.

UniMAP Sem II – 12/13

EKT120: Computer Programming 14

Page 15: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Main Memory

• 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.

UniMAP Sem II – 12/13

EKT120: Computer Programming 15

Page 16: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Figure 1.4 1000 Memory Cells in Main Memory

UniMAP Sem II – 12/13

EKT120: Computer Programming 16

Page 17: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

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• E.g. program file, data file, etc• E.g. hard disk, diskette, CD

UniMAP Sem II – 12/13

EKT120: Computer Programming 17

Page 18: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Figure 1.5 Secondary Storage Media

UniMAP Sem II – 12/13

EKT120: Computer Programming 18

Page 19: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

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. monitor, printer, speaker

UniMAP Sem II – 12/13

EKT120: Computer Programming 19

Page 20: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Software

• As a complement to hardware, computer system needs software to solve problems.

• Software are classified into :• System software• Application software

UniMAP Sem II – 12/13

EKT120: Computer Programming 20

Page 21: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Software• System software : manages the computer and its peripheral devices (hardware) • E.g. Operating system (OS)• Text editor• Pre-processor• Language translator• Linker• Loader

UniMAP Sem II – 12/13

EKT120: Computer Programming 21

Page 22: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Software

• 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, etc

UniMAP Sem II – 12/13

EKT120: Computer Programming 22

Page 23: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Programming Languages

• Programming language is divided into three categories:• Machine Language• Assembly Language• High-Level Language

UniMAP Sem II – 12/13

EKT120: Computer Programming 23

Page 24: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

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

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

• 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

UniMAP Sem II – 12/13

EKT120: Computer Programming 24

Page 25: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Figure 1.6 Relationship Between a Byte and a Bit

UniMAP Sem II – 12/13

EKT120: Computer Programming 25

Page 26: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Assembly Language

• Strings of 0’s and 1’s are replaced into instructions which resemble English language to represent computer operation element

• Easier to understand and write• E.g.

UniMAP Sem II – 12/13

EKT120: Computer Programming 26

LOAD rateMULT hourSTOR wages

Page 27: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Assembly Language

• Nevertheless, needs language translator called Assembler to change Assembly Language to Machine Code for execution purpose

• still too long and not portable

UniMAP Sem II – 12/13

EKT120: Computer Programming 27

Page 28: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

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

UniMAP Sem II – 12/13

EKT120: Computer Programming 28

Page 29: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

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

• E.g. if student’s grade is greater than or equal to 50

Print “Pass” else

Print “Fail”

UniMAP Sem II – 12/13

EKT120: Computer Programming 29

Page 30: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Algorithms

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

UniMAP Sem II – 12/13

EKT120: Computer Programming 30

Process 2Decision

Data

Process 1

Begin

End

Page 31: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Algorithm-Basic symbols in a flowchart

UniMAP Sem II – 12/13

EKT120: Computer Programming 31

Start/End

Process

Input/Output

Decision

Flow direction

Connector

Page 32: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Flowchart-(example)

UniMAP Sem II – 12/13

EKT120: Computer Programming 32

Start

read num1, num2

sum=num1+num2

print sum

End

Page 33: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

UniMAP Sem II – 12/13

EKT120: Computer Programming 33

TRY THIS!!!

Write a pseudo code, flowchart and program that calculates and prints the SUM of two integers A and B.

Page 34: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

UniMAP Sem II – 12/13

EKT120: Computer Programming 34

Pseudo code

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

Flowchart

Begin

Input A,B

CalculateA + B

Print SUM

End

Page 35: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Control Structure

• All programs could be written in terms of three control structures:• Sequence structure• Selection structure• Repetition structure

UniMAP Sem II – 12/13

EKT120: Computer Programming 35

Page 36: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Sequence Structure

• Is a series of steps executed sequentially by default

UniMAP Sem II – 12/13

EKT120: Computer Programming 36

Read num1, num2Calculate total=num1+num2Print total

Pseudo code Flowchart

Read num1, num2

total = num1+num2

print total

Page 37: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Selection Structure

• Used to choose among alternative courses of action• C has three types: if, if..else, and switch

UniMAP Sem II – 12/13

EKT120: Computer Programming 37

Page 38: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

The if Selection Structure

• “if” structure is a single-entry/single-exit structure

UniMAP Sem II – 12/13

EKT120: Computer Programming 38

true

false

grade >= 60

print “Pass”

 

If student’s grade is greater than or equal to 60

Print “Pass”

Page 39: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

The if..else Selection Structure

• Specifies an action to be performed both when the condition is true and when it is false

UniMAP Sem II – 12/13

EKT120: Computer Programming 39

truefalse

print “Fail” print “Pass”

grade >= 60

If student’s grade is greater than or equal to 60

Print “Pass”else

Print “Fail”

Page 40: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Repetition Structure

• Specifies a block of one or more statements that are repeatedly executed until a condition is satisfied

• Three types : while, for, do-while

UniMAP Sem II – 12/13

EKT120: Computer Programming 40

Page 41: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

The while Repetition Structure

• Programmer specifies an action is to be repeated while some conditions remain true

UniMAP Sem II – 12/13

EKT120: Computer Programming 41

product <= 1000 product = 2 * producttrue

falseWhile product is less than or equal 1000

calculate product=2 * product

Page 42: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Basics of a Typical C Program Development Environment

UniMAP Sem II – 12/13

EKT120: Computer Programming 42

Page 43: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

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

UniMAP Sem II – 12/13

EKT120: Computer Programming 43

Page 44: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Figure 1.8 Flow of Information During Program Execution

UniMAP Sem II – 12/13

EKT120: Computer Programming 44

Page 45: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

Simple C Program: Program to add two numbers #include <stdio.h>int main(void){ int dA, dB, dSum; printf (“input first integer \n”); scanf (“%d”, &dA) printf (“input second integer \n”); scanf (“%d”, &dB) dSum = dA + dB;

printf (“Sum is %d\n”, dSum); return 0;}

UniMAP Sem II – 12/13

EKT120: Computer Programming 45

OUTPUTInput first integer39Input second integer27Sum is 66

Page 46: Week 1 Introduction to Computers and Programming Languages UniMAP Sem II – 12/13 EKT120: Computer Programming 1

End Week 1

UniMAP Sem II – 12/13

EKT120: Computer Programming 46

Q & A!


Recommended