Скачать презентацию Week 1 Introduction to Computers and Programming Скачать презентацию Week 1 Introduction to Computers and Programming

c2dbbc6c67c0850531b61cb92f5d8fe0.ppt

  • Количество слайдов: 46

Week 1 – Introduction to Computers and Programming Languages (Part 1) Uni. MAP Sem Week 1 – Introduction to Computers and Programming Languages (Part 1) Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 1

General Information Contributes 4 units: 2 hours – lectures 4 hours – labs Main 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. Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 2

Course Outcomes Ability to define and describe programming concepts and principles. Ability to apply 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. Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 3

Overall Evaluation 4 main components: Theoretical Tests (2) => 50% Lab Assignments (5) / Overall Evaluation 4 main components: Theoretical Tests (2) => 50% Lab Assignments (5) / Lab Test => 30% Lab Project => 20% Assignments are assessed individually The two tests are written tests Lab Project : Group of 3 students (max) Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 4

References Deitel & Deitel, Sudin, S. , Ahmad, R. Badlishah, and Yacob, Y. , 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”, Mc. Graw Hill, 2010. Hanly, J. R. and Koffman, E. B. , “C Program Design for Engineers”, 2 nd Ed. , Addison-Wesley, 2001. ISBN : 0321204174 Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 5

Notes This course is NOT about the language per se, it is about problem 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. Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 6

Outline Computer Fundamentals Programming Languages Computer organization and hardware Computer software Machine language Assembly Outline Computer Fundamentals Programming Languages Computer organization and hardware Computer software Machine language Assembly language High-level language Algorithm : pseudo code and flowchart Control Structures Simple C Program Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 7

Computer Fundamentals Computer system is divided into hardware and software. Hardware refers to physical 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 Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 8

Figure 1. 1 The Intel Atom processor chip contains the full circuitry of a 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) Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 9

Figure 1. 2 (a) Notebook Computer (HP Pavilion dv 5©, Courtesy of Hewlett-Packard). (b) Figure 1. 2 (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. ) Uni. MAP Sem II – 09/10 EKT 120: Computer Programming

Figure 1. 3 Components of a Computer Uni. MAP Sem II – 09/10 EKT Figure 1. 3 Components of a Computer Uni. MAP Sem II – 09/10 EKT 120: Computer Programming

Computer Hardware CPU Control Unit Input Device Arithmetic and Logic Unit Register Output Device Computer Hardware CPU Control Unit Input Device Arithmetic and Logic Unit Register Output Device Main Memory Secondary Memory Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 12

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 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 Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 13

Main Memory keeps information from the input unit also keeps processed information until it 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. Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 14

Main Memory Main memory can be further classified into two types: Random Access Memory 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. Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 15

Figure 1. 4 1000 Memory Cells in Main Memory Uni. MAP Sem II – Figure 1. 4 1000 Memory Cells in Main Memory Uni. MAP Sem II – 09/10 EKT 120: Computer Programming

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 E. g. program file, data file, etc E. g. hard disk, diskette, CD Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 17

Figure 1. 5 Secondary Storage Media Uni. MAP Sem II – 09/10 EKT 120: Figure 1. 5 Secondary Storage Media Uni. MAP Sem II – 09/10 EKT 120: Computer Programming

Input/Output Devices Input devices - feed data and programs into computers E. g. keyboard, 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 Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 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 Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 20

Software System software : manages the computer and its peripheral devices (hardware) E. g. Software System software : manages the computer and its peripheral devices (hardware) E. g. Operating system (OS) Text editor Pre-processor Language translator Linker Loader Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 21

Software Application software : performs specific tasks There are two types: Program to solve 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 Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 22

Programming Languages Programming language is divided into three categories: Machine Language Assembly Language High-Level Programming Languages Programming language is divided into three categories: Machine Language Assembly Language High-Level Language Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 23

Machine Language understood by the computer Bunch of 0’s and 1’s Program written in Machine 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 1001 1100 0111 Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 24

Figure 1. 6 Relationship Between a Byte and a Bit Uni. MAP Sem II Figure 1. 6 Relationship Between a Byte and a Bit Uni. MAP Sem II – 09/10 EKT 120: Computer Programming

Assembly Language Strings of 0’s and 1’s are replaced into instructions which resemble English 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. LOAD rate MULT hour STOR Uni. MAP Sem II – 09/10 wages EKT 120: Computer Programming 26

Assembly Language Nevertheless, needs language translator called Assembler to change Assembly Language to Machine Assembly Language Nevertheless, needs language translator called Assembler to change Assembly Language to Machine Code for execution purpose still too long and not portable Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 27

High-Level Language Improves weaknesses in Machine Language and Assembly Language Portable Written in one 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 Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 28

Algorithms The solution to any computing problem involves executing series of actions in a 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” Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 29

Algorithms Flowchart: visual-form of an algorithm Begin E. g. Data Process 1 Decision Process Algorithms Flowchart: visual-form of an algorithm Begin E. g. Data Process 1 Decision Process 2 End Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 30

Algorithm-Basic symbols in a flowchart Start/End Process Flow direction Connector Input/Output Decision Uni. MAP Algorithm-Basic symbols in a flowchart Start/End Process Flow direction Connector Input/Output Decision Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 31

Flowchart-(example) Start read num 1, num 2 sum=num 1+num 2 print sum End Uni. Flowchart-(example) Start read num 1, num 2 sum=num 1+num 2 print sum End Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 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. Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 33

Flowchart Begin Pseudo code • • • Begin Input A and B Calculate A Flowchart Begin Pseudo code • • • Begin Input A and B Calculate A + B Print result of SUM End Input A, B Calculate A + B Print SUM End Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 34

Control Structure All programs could be written in terms of three control structures: Sequence Control Structure All programs could be written in terms of three control structures: Sequence structure Selection structure Repetition structure Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 35

Sequence Structure Is a series of steps executed sequentially by default Pseudo code Read Sequence Structure Is a series of steps executed sequentially by default Pseudo code Read num 1, num 2 Calculate total=num 1+num 2 Print total Flowchart Read num 1, num 2 total = num 1+num 2 print total Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 36

Selection Structure Used to choose among alternative courses of action C has three types: Selection Structure Used to choose among alternative courses of action C has three types: if, if. . else, and switch Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 37

The if Selection Structure “if” structure is a single-entry/singleexit structure If student’s grade is The if Selection Structure “if” structure is a single-entry/singleexit structure If student’s grade is greater than or equal to 60 Print “Pass” grade >= 60 true print “Pass” false Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 38

The if. . else Selection Structure Specifies an action to be performed both when The if. . else Selection Structure Specifies an action to be performed both when the condition is true and when it is false If student’s grade is greater than or equal to 60 Print “Pass” else Print “Fail” false grade >= 60 true print “Fail” Uni. MAP Sem II – 09/10 print “Pass” EKT 120: Computer Programming 39

Repetition Structure Specifies a block of one or more statements that are repeatedly executed 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 Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 40

The while Repetition Structure Programmer specifies an action is to be repeated while some The while Repetition Structure Programmer specifies an action is to be repeated while some conditions remain true product <= 1000 false true product = 2 * product While product is less than or equal 1000 calculate product=2 * product Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 41

Basics of a Typical C Program Development Environment Uni. MAP Sem II – 09/10 Basics of a Typical C Program Development Environment Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 42

Figure 1. 7 Entering, Translating, and Running a High-Level Language Program Uni. MAP Sem Figure 1. 7 Entering, Translating, and Running a High-Level Language Program Uni. MAP Sem II – 09/10 EKT 120: Computer Programming

Figure 1. 8 Flow of Information During Program Execution Uni. MAP Sem II – Figure 1. 8 Flow of Information During Program Execution Uni. MAP Sem II – 09/10 EKT 120: Computer Programming

Simple C Program: Program to add two numbers #include <stdio. h> int main(void) { Simple C Program: Program to add two numbers #include int main(void) { int A, B, SUM; printf (“input first integer n”); scanf (“%d”, &A) printf (“input second integer n”); scanf (“%d”, &B) OUTPUT SUM = A + B; Input first integer printf (“Sum is %dn”, SUM); return 0; } 39 Input second integer 27 Sum is 66 Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 45

End Week 1 – Session 1 Q & A! Uni. MAP Sem II – End Week 1 – Session 1 Q & A! Uni. MAP Sem II – 09/10 EKT 120: Computer Programming 46