PLT 101 Computer Programming CHAPTER 1 INTRODUCTION TO

  • Slides: 38
Download presentation
PLT 101 Computer Programming CHAPTER 1 INTRODUCTION TO COMPUTER PROGRAMMING (Part 1) Lecturer: Sir

PLT 101 Computer Programming CHAPTER 1 INTRODUCTION TO COMPUTER PROGRAMMING (Part 1) Lecturer: Sir Zaid Aihsan zaid@unimap. edu. my UNICITI S 4 DK 2 Level 2

Code: PLT 101 Course Title: Computer Programming Course Type: Core Credit Hour: 3 Course

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 � CO 1: Ability to apply programming techniques and tools such as

Course Outcomes � CO 1: Ability to apply programming techniques and tools such as flowchart and pseudo code to design computer programs. C 4, P 3 Assignment, laboratory, mid-term and final examination � CO 2: Ability to differentiate programming concepts and principles. C 4, P 3 Assignment, laboratory, mid-term and final examination � CO 3: Ability to design engineering related problems using computer programming techniques. C 5, P 5 Assignment, mini project, laboratory, mid-term and final examination 3

Evaluation Contribution l a u t n i n t n me o 10%

Evaluation Contribution l a u t n i n t n me o 10% C ess s s 10% A Final Exam Midterm Exam Laboratory Mini Project 40% 20% n o i at 20% Ex n i am 4 PLT 101 2013/2014 Assignment

Schedule � Lecture – 2 hours/week � UNICITI-DK 2, Tuesday (11: 00 am –

Schedule � Lecture – 2 hours/week � UNICITI-DK 2, Tuesday (11: 00 am – 1: 00 pm) � Laboratory – 3 hours/week � RY 31 Group 1 � UNICITI – Computer Lab 2, Thursday (8: 00 am-11: 00 am) � RY 31 Group 2 � UNICITI – Computer Lab 2, Monday (11. 00 am-2. 00 am) � RY 32 Group 1 � UNICITI – Computer Lab 2, Friday (3: 00 pm-6: 00 pm) � RY 32 Group 2 � UNICITI – Computer Lab 2, Monday (8: 00 am-11: 00 am) 5

References � Deitel P. and Deitel H. , C How to Program. 7 th

References � Deitel P. and Deitel H. , C How to Program. 7 th Edition. New Jersey: Pearson- Prentice Hall. , 2012. � Cheng H. , C for Engineers and Scientists: An Interpretive Approach. United States: Mc. Graw-Hill Education. , 2010. � Sprankle M. and Hubbard J. , Problem Solving and Programming Concepts. 9 th Edition. New Jersey: Pearson-Prentice Hall. , 2011. � Hanly J. R. and Koffman E. B. , Problem Solving and Program Design in C. 7 th Edition. New Jersey: Pearson-Prentice Hall. , 2012. � King K. N. , C Programming A Modern Approach. 2 nd Edition. New York: W. W. Norton & Co. , 2008. � Dey P. and Ghosh M. , Computer Fundamentals and Programming in C. 2 nd Edition. New Delhi: Oxford University Press. , 2013. 6 Deitel P. and Deitel H. , C How to Program. 7 th Edition. , 2012

Outline � Computer Fundamentals �Computer organization and hardware �Computer software � Programming Languages �Machine

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 7

Computer Fundamentals � Computer system is divided into hardware and software. � Hardware refers

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 8

Components of a Computer Figure 1. 1 Computer hardware 9

Components of a Computer Figure 1. 1 Computer hardware 9

Computer Hardware Architecture CPU Control Unit Input Device Arithmetic and Logic Unit Register Main

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 computer’s administrator and is responsible for supervising

Central Processing Unit (CPU) �CPU is the computer’s administrator and is responsible for supervising the operation of the other sections. �Consists of three functional units; v Control unit - supervises all activities of the computer system v 11

Figure 1. 3 The Intel Atom processor chip contains the full circuitry of a

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

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: �

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

Figure 1. 4 1000 Memory Cells in Main Memory 15

Secondary Memory �Main memory is only used during processing following certain instructions. �Permanent information

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

Secondary Storage Media Figure 1. 5 Secondary storage 17

Input/Output Devices � Input devices - feed data and programs into computers �E. g.

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 dv 5©, Courtesy of Hewlett-Packard). (b) Palmtop Computer (i.

(a) Notebook Computer (HP Pavilion dv 5©, Courtesy of Hewlett-Packard). (b) Palmtop Computer (i. Phone 3 G©, Courtesy of Apple, Inc. ) (c) Desktop Computer (i. Mac©, Courtesy of Apple, Inc. ) Figure 1. 6 Output Devices 19

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

Software �As a complement to hardware, computer system needs software to solve problems. �Software classified into: �System software �Application software 20

Software cont. � System software : manages the computer and its peripheral devices (hardware)

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:

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

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 0’s and 1’s

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 24

Figure 1. 7 Relationship Between a Byte and a Bit 25

Figure 1. 7 Relationship Between a Byte and a Bit 25

Assembly Language � Strings of 0’s and 1’s are replaced into instructions which resemble

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 write � E. g. 26 LOAD MULT STOR rate hour wages

Assembly Language cont. � Nevertheless, needs language translator called Assembler to change Assembly Language

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 �

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

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 student’s 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

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

Algorithm-Basic Symbol in a Flowchart Start/End Process Input/Output Decision 31 Flow direction Connector

Flowchart (Example) Start read num 1, num 2 sum=num 1+num 2 print sum End

Flowchart (Example) Start read num 1, num 2 sum=num 1+num 2 print sum End 32

TRY THIS!!! Write a pseudo code, flowchart and program that calculates and prints the

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

Typical C Program Development Environment 34

Figure 1. 8 Entering, Translating, and Running a High. Level Language Program 35

Figure 1. 8 Entering, Translating, and Running a High. Level Language Program 35

Figure 1. 9 Flow of Information during Program Execution 36

Figure 1. 9 Flow of Information during Program Execution 36

Simple C Program: Program to add two numbers #include <stdio. h> int main() {

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; OUTPUT printf (“Sum is %dn”, Sum); return 0; 39 Input first integer Input second integer 27 Sum is 66 37

End Week 1 – Session 1 Thank You Q & A! 3 8

End Week 1 – Session 1 Thank You Q & A! 3 8