52
EEE 11 Programming Fundamentals Jhoanna Rhodette I. Pedrasa [email protected] Consultation: EEEI 209 (CNL Faculty Room) Tue 8-12 nn, Thur 8-10 am, Thur 1-4pm, Fri 1-2:30 pm

Lec00 Intro

Embed Size (px)

Citation preview

Page 1: Lec00 Intro

EEE 11

Programming Fundamentals

Jhoanna Rhodette I. [email protected]

Consultation: EEEI 209 (CNL Faculty Room) Tue 8-12 nn, Thur 8-10 am, Thur 1-4pm, Fri 1-2:30 pm

Page 2: Lec00 Intro

EEE 11: Programming Fundamentals

Why are WE here?

Page 3: Lec00 Intro

EEE 11: Programming Fundamentals

Programming is not, by itself, hard.

● Does not require innate capability.● Does not require physical ability.● It does, however, require:

A certain degree of CraftsmanshipPatience and Resolve to stick to a problem

Attention to detail

Page 4: Lec00 Intro

EEE 11: Programming Fundamentals

Attention to Detail

● Details matter● Computers are incredibly stupid!● Computers do EXACTLY what you tell them to do● When you're programming, it helps to be able to ``think'' as

stupidly as the computer does, so that you're in the right frame of mind for specifying everything in minute detail, and not assuming that the right thing will happen unless you tell it to.

Page 5: Lec00 Intro

EEE 11: Programming Fundamentals

Good Memory

Standardfunctions

SyntaxDefined

variables andfunctions

Techniques

Page 6: Lec00 Intro

EEE 11: Programming Fundamentals

Ability to abstract and think on several levels

● Need to compartmentalize tasks: little black

boxes● Solve big problems by solving the little problems● Be aware of the assumptions made

Page 7: Lec00 Intro

EEE 11: Programming Fundamentals

PRACTICE

PRACTICE

PRACTICE

projecteuler.net

You don't learn how to play basketball by watching ESPN.

You don't learn how to play play the piano by

reading a book.

Page 8: Lec00 Intro

EEE 11: Programming Fundamentals

Other tips:● Bring your lecture notes to class● Buy / borrow from the library a C programming

book (any book!)– Kernighan & Richie: The C Programming

Language● Use your time in the laboratory wisely● Have access to a computer outside lab hours.● Have F U N

Page 9: Lec00 Intro

Course OutlineFIRST EXAM

● Introduction ComputersNumber Representation Problem Solving and Algorithms

● C Programming SyntaxVariables and data typesOperators, expressions and statementsControl structures

SECOND EXAM● Modularity

FunctionsStandard Libraries

● Aggregate Data TypesArrays and strings Multi-dimensional ArraysStructures and Unions

Page 10: Lec00 Intro

Course OutlineTHIRD EXAM

● Dynamic Data StructuresMemory and PointersLinked ListsTrees Others

● File I/OSearching and Sorting UNIX/Linux environment

Page 11: Lec00 Intro

Grading System

● Lecture Grade (50%) Laboratory Grade (50%): Exams 45% Machine Problems 30% Exercises, HW, Attendance 5% Machine Exercises 20%

Must pass BOTH

● Final grade92-100 1.0 72 - <76 2.2588 - <92 1.25 68 - <72 2.5084 - <88 1.50 64 - <68 2.7580 - <84 1.75 60 - <64 3.076 - <80 2.0 <60 5.0

Page 12: Lec00 Intro

Textbooks

● C for engineers and scientists, Cheng, 2009● The Joy of C 3/e, Miller & Quilici, 1997● C: How to Program 6/e, Dietel & Dietel, 2010● C by Dissection 4/e, Kelley & Pohl, 2000

● C Programming Language, Kernighan & Ritchie, 1988

... actually, any book in C is better than having no book at all!

Page 13: Lec00 Intro

Class Policies● UVLE will be used extensively in this course.

– It is the student's responsibility to check the email associated with UVLE regularly for updates and course announcements.

– Students are required to enroll themselves in the following course in UVLE:

Course name: EEE 11 : Programming Fundamentals Password: eee11jipedrasa● Students must read and comply with the UP Acceptable

Use Policy (AUP).● No make-up or final exam will be given. Students who

arrive 30 mins late after the start of the exam will NOT be allowed to take the exam.

Page 14: Lec00 Intro

Class Policies● Attendance will be checked every lecture meeting. A

student found absent more than 20% of the total course time (around 3 lecture/lab meetings) may be given a failing grade.

● Cheating in the exam, machine exercises and machine problems is punishable with a grade of 5.0 and is grounds for suspension/expulsion.

● Avoid talking in class. Keep your phone in silent mode, or turn it off when the class is in session.

● No eating and drinking inside the lecture halls.

Practice ........ practice ....... practice .....

Page 15: Lec00 Intro

EEE 11

Lecture 1:

History of ComputersComputer System

Number Representation

Page 16: Lec00 Intro

EEE 11 16

What is a computer?

● A programmable machine that responds to a specific set of instructions in a well-defined manner and can execute a prerecorded list of instructions (a program)

● Anything that “computes”– e.g. calculator

Page 17: Lec00 Intro

EEE 11 17

History of Computers: Early days● 500 B.C.- Abacus● 1600s - Blaise Pascal and Gottfried Leibniz

mechanical calculators● 1800s - Joseph Jacquard

“programmable” weaving loom - Charles Babbage's analytical engine - punch card system

● 1940 - John Atanasoff's computer using boolean algebra

● 1943 - First electronic computer ENIAC Electronic Numerical Integrator and Computer

● 1951 - John von Neumann architecture: stored-program computers

Page 18: Lec00 Intro

EEE 11 18

Early computers

ENIAC (1946)Babbage Difference Engine(1832)

25k parts, 13,600kg, £17470

17,468 vacuum tubes, 150kW

Page 19: Lec00 Intro

EEE 11 19

History of Computers: Commercialization● 1950s - 1st commercial computer (IBM)● 1957 - Advanced Research Project Agency (ARPA)● 1962 - Space War = 1st computer game● 1964 - IBM System/360 = 1st OS● 1968 - ARPANET at UCLA● 1969 - UNIX OS by AT&T Bell Labs

- UCLA introduces the Internet● 1970 - Intel produces 1st microprocessor

- Mouse is patented● 1972 - Pong by Atari = 1st commercial video game● 1973 - Xerox develops 1st GUI system● 1974 - TCP is published

Page 20: Lec00 Intro

EEE 11 20

History of Computers: Killer Apps● 1975 - Microsoft is established● 1976 - Apple Computers founded; Apple I released● 1977 - Apple II with colored graphics is introduced

- 1st commercial network ARCNET● 1978 - TCP splits to TCP/IP; UDP created

- Apple DOS 3.1 (1st OS of Apple computers) - VisiCalc (early version of spreadsheets)

● 1979 - Wordstar (word processor)● 1981 - IBM personal computers are introduced

using MS-DOS● 1982 - Wordperfect 1.0; Lotus 1-2-3● 1983 - ARPANET standardizes TCP/IP

(birth of the modern internet) - MS Windows

Page 21: Lec00 Intro

EEE 11 21

History of Computers: Modern Internet● 1984 - IBM releases 1st portable computer (30 lbs)

- 1st MUD is released - Appletalk is released

● 1985 - Nintendo Entertainment System (NES)● 1991 - Linux is introduced● 1992 - Windows 3.1● 1993 - DOOM was released

(turning point of 1st person shooter)● 1994 - Netscape was established

- Yahoo search engine● 1995 - Windows 95 and IE 1.0● 1997 - IEEE 802.11 Wifi standard● 1998 - Google is released

Page 22: Lec00 Intro

EEE 11 22

Moore's Law

“The number of transistors on a chip will double every 18 to 24 months”

-Gordon Moore, 1965

Page 23: Lec00 Intro

EEE 11 23

Transistor Counts

Source: Intel

Page 24: Lec00 Intro

EEE 11 24

Intel Xeon 7400 Series (2008)

Intel Xeon 7400 Series (2008)

64-bit processor, 6 cores1.9 billion transistors

2.66 GHz, 130W

Intel 4004 Microprcessor (1971)

4-bit processor, 1 core2,000 transistors

0.06MHz

Page 25: Lec00 Intro

EEE 11 25

Desktop Computer

Page 26: Lec00 Intro

EEE 11 26

Inside Your PC

Page 27: Lec00 Intro

EEE 11 27

Basic Functional Units of A Computer

Input

Output

Memory

Arithmetic and Logic

Control

I/O Processor

KeyboardMouseTouch-screen

MonitorPrinter

● Primary storage● Main memory● Volatile● Fast● expensive, low capacity● RAM

● Secondary storage● Non-volatile● Cheap, high capacity● Generally slower

+,-,/,*compare

coordinator

Page 28: Lec00 Intro

EEE 11 28

Hardware vs Software

● Hardware – Refers to objects that you can actually touch– disks, disk drives, display screens, keyboards,

printers, boards, and chips

● Software – Untouchable / intangible component of a computer– exists as ideas, concepts, and symbols, but it has no

substance

Page 29: Lec00 Intro

EEE 11 29

So how does hardware relate to software?

● An analogy (Computer ↔ Book) Computer Book– Hardware pages and the ink– Software paragraphs & overall theme

A computer without software is like a book full of blank pages

Software to makes the computer useful

Page 30: Lec00 Intro

EEE 11 30

Creating / Building a software

IdeasSourceCodes

Interpreter

Linker

Compiler

Binaries / Executable

Library

Objectfiles

SourceCodes

SourceCodes

Source codes follow a “language”that is understood by the system

Page 31: Lec00 Intro

EEE 11 31

Compilers vs Interpreters

● Compiler – looks at the entire piece of source code– collects and reorganize the instructions to increase

efficiency (if possible)

● Interpreter– analyzes and executes each line of source code– Checks validity of the code

Page 32: Lec00 Intro

EEE 11 32

Programming Languages:The Four Generations

● First generation: machine language– form directly understandable by the computer’s

processor (series of 1’s & 0’s)– processor dependent

● Second generation: assembly language– mnemonic system to represent the machine

language instructions– an assembly process translated the encoded

instructions into machine language

Page 33: Lec00 Intro

EEE 11 33

Programming Languages:The Four Generations

● Third generation programming languages (3GL)– use of compilers and interpreters to translate

statements into machine language– Procedure-oriented

– COBOL, FORTRAN, C, BASIC, Pascal, Ada, LISP, Prolog– Object-Oriented

– Java, C++, Python, C#

● Fourth generation programming languages (4GL)– closer to human languages– require fewer commands to perform a given task

Page 34: Lec00 Intro

EEE 11 34

Number Representation

● Computers can only process numbers

● Real-world data are normally mapped to numerical values

– e.g. Colors are in RGB values of 0-255 each

● Use of appropriate number systems to make representations simpler

Page 35: Lec00 Intro

EEE 11 35

Positional Number Systems● Each digit is assigned a weight dependent on its

position relative to a radix point

● Set of symbols consisting of r elements are used to represent each digit

– r is also known as radix or base

● Example: 6 7 8 . 9 1 (r =10 elements are 0, 1 … 9) 6 has a weight of r2=102

If radix point is here

Page 36: Lec00 Intro

EEE 11 36

Conversion to Decimal

● Multiply each binary digit by its weight, then add all the products

● Mathematical representation: Let ABCDE be a 5-digit number in base r then the value of ABCDE

r is

A r4 + B r3 + C r2 + D r1 + E r0

Page 37: Lec00 Intro

EEE 11 37

Example using binary (base 2)

1 1 0 1 1 . 0 12 = ( ? )10

x 2-2 = 0.25x 2-1 = 0x 20 = 1x 21 = 2x 22 = 0x 23 = 8x 24 = 16

Answer = 27.25 10

Page 38: Lec00 Intro

EEE 11 38

Example using octal (base 8)

1 2 5 0 6 . 1 78 = ( ? )10

x 8-2 = 0.109x 8-1 = 0.125x 80 = 6x 81 = 0x 82 = 320x 83 = 1024x 84 = 4096

Answer = 5446.234 10

Page 39: Lec00 Intro

EEE 11 39

Hexadecimal (Base 16 )● Digits include

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15

● Use A = 10 B = 11 C = 12 D = 13 E = 14 F = 15

● e.g. ABC16

= 10x162 + 11x161 + 12x160 = 2,748

Page 40: Lec00 Intro

EEE 11 40

Conversion from decimal (Integer portion)

Conversion from Decimal (Integer portion)● Continuously divide the integer portion of the number by r.● Note the remainder after each division● The resulting number are just the remainders from the last to

first (left to right).

Page 41: Lec00 Intro

EEE 11 41

Examples

7710 = ( ? )2

2 /772 /38 12 /19 02 /9 12 /4 12 /2 0 1 0 ANS: 10011012

5610 = ( ? )2

2 /562 /28 02 /14 02 /7 02 /3 12 /1 1 0 1 ANS: 1110002

Page 42: Lec00 Intro

EEE 11 42

Simplified Derivation

● Let K = value in Decimal– Let this equal to ABCDE in binary

e.g. K=1310 = 01101

2 (A=0, B=1, C=1,D=0,E=1)

K = 24A + 23B + 22C +21D+20EK/2 = 23A + 22B + 21C +20D remainder E

L = 23A + 22B + 21C +20DL/2 = 22A + 21B + 20C remainder D...

Page 43: Lec00 Intro

EEE 11 43

Conversion from decimal (fraction portion)

Conversion from Decimal (fraction portion)● Continuously MULTIPLY the fractional portion of the number

by r.● Note the integer portion after each multiplication the remove it

from the number● The resulting number is just the integer parts extracted while

multiplying

Page 44: Lec00 Intro

EEE 11 44

Example

0.710 = ( ? )2 , up to 5 bits after the binary point

2 * .7 = 1.4 12 * .4 = 0.8 02 * .8 = 1.6 12 * .6 = 1.2 12 * .2 = 0.4 0 Answer: 0.101102

Page 45: Lec00 Intro

EEE 11 45

Simplified Derivation

● Let K = value in Decimal– Let this equal to 0.ABC... in binary

e.g. K=0.6410 = 0.101...

2 (A=1, B=0, C=1)

K = 2-1A + 2-2B + 2-3C ...2K = A + 2-1B + 2-2C ... A = whole #

L = 2-1B + 2-2C ...2L = B + 2-1C B = whole #...

Page 46: Lec00 Intro

EEE 11 46

Mixed numbers?

● Handle fractional and whole part separately then add

Page 47: Lec00 Intro

EEE 11 47

Octal to/from binary● An octal digit is ALWAYS equal to three (3)

binary digits, – e.g. 5

8 = 101

2

● Simply replace the octal digit with the corresponding binary digits and vice-versa Octal Binary 0 000 1 001 2 010 3 011 4 100 5 101 6 110 7 111

Page 48: Lec00 Intro

EEE 11 48

Example

1 2 5 0 6 1 78

= ( ? )2

= 111= 001= 110= 000= 101= 010= 001

Answer = 001 010 101 000 110 001 111 2

Page 49: Lec00 Intro

EEE 11 49

Hexadecimal to/from binary● A hexadecimal digit is equal to four (4) binary

digitsHexadecimal Binary Hexadecimal Binary

0 0000 8 1000 1 0001 9 1001 2 0010 A 1010 3 0011 B 1011 4 0100 C 1100 5 0101 D 1101 6 0110 E 1110 7 0111 F 1111

Page 50: Lec00 Intro

EEE 11 50

Example

E 2 5A 6 1 716

= ( ? )2

= 0111= 0001= 0110= 1010= 0101= 0010= 1110

Answer = 1110 0010 0101 1010 0110 0001 0111 2

Page 51: Lec00 Intro

EEE 11 51

Hexadecimal to/from Octal● Expand first to binary then group by 4 or 3

depending on the destination

● e.g. ABC16

= (?)8

= A B C

16

= 1010 1011 1100

2

… regroup by 3's ...

= 101 010 111 100

2

= 5 2 7 4

8

= 5274

8

Page 52: Lec00 Intro

EEE 11 52

Credits

The Center for Programmers and Users. Fundamentals of Programming Hand-out 1

http://www.howstuffworks.comDefinitions from: http://www.webopedia.com

Flowchart examples from:http://www.eng.iastate.edu/efmd/161algor.htm#examples

Additional reading:http://en.wikipedia.org/wiki/Computer