Nothing Special   »   [go: up one dir, main page]

Lec00 Intro

Download as pdf or txt
Download as pdf or txt
You are on page 1of 52

EEE 11

Programming Fundamentals Jhoanna Rhodette I. Pedrasa jipedrasa@up.edu.ph


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

EEE 11: Programming Fundamentals

Why are WE here?

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 Craftsmanship Patience and Resolve to stick to a problem Attention to detail

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.

EEE 11: Programming Fundamentals

Good Memory
Syntax Standard functions Defined variables and functions Techniques

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

EEE 11: Programming Fundamentals

PRACTICE PRACTICE
You don't learn how to play play the piano by reading a book. You don't learn how to play basketball by watching ESPN.

PRACTICE
projecteuler.net

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

Course Outline

FIRST EXAM Introduction

Computers Number Representation Problem Solving and Algorithms

SECOND EXAM Modularity

Functions Standard Libraries

C Programming

Aggregate Data Types

Syntax Variables and data types Operators, expressions and statements Control structures

Arrays and strings Multi-dimensional Arrays Structures and Unions

Course Outline
THIRD EXAM Dynamic Data Structures Memory and Pointers Linked Lists Trees Others File I/O Searching and Sorting UNIX/Linux environment

Grading System

Lecture Grade (50%)

Laboratory Grade (50%):


Machine Problems 30% Machine Exercises 20%

Exams 45% Exercises, HW, Attendance 5%

Must pass BOTH

Final grade
1.0 1.25 1.50 1.75 2.0 72 - <76 68 - <72 64 - <68 60 - <64 <60 2.25 2.50 2.75 3.0 5.0

92-100 88 - <92 84 - <88 80 - <84 76 - <80

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!

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.

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

EEE 11

Lecture 1: History of Computers Computer System Number Representation

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

EEE 11

16

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

EEE 11

17

Early computers

Babbage Difference Engine (1832)


25k parts, 13,600kg, 17470

ENIAC (1946)
17,468 vacuum tubes, 150kW

EEE 11

18

History of Computers: Commercialization


1950s 1957 1962 1964 1968 1969 1970 1972 1973 1974

- 1st commercial computer (IBM) - Advanced Research Project Agency (ARPA) - Space War = 1st computer game st - IBM System/360 = 1 OS - ARPANET at UCLA - UNIX OS by AT&T Bell Labs - UCLA introduces the Internet - Intel produces 1st microprocessor - Mouse is patented - Pong by Atari = 1st commercial video game st - Xerox develops 1 GUI system - TCP is published
19

EEE 11

History of Computers: Killer Apps


1975 1976 1977 1978 1979 1981 1982 1983

EEE 11

- Microsoft is established - Apple Computers founded; Apple I released - Apple II with colored graphics is introduced - 1st commercial network ARCNET - TCP splits to TCP/IP; UDP created - Apple DOS 3.1 (1st OS of Apple computers) - VisiCalc (early version of spreadsheets) - Wordstar (word processor) - IBM personal computers are introduced using MS-DOS - Wordperfect 1.0; Lotus 1-2-3 - ARPANET standardizes TCP/IP (birth of the modern internet) 20 - MS Windows

History of Computers: Modern Internet

1984 1985 1991 1992 1993 1994 1995 1997 1998

- IBM releases 1st portable computer (30 lbs) - 1st MUD is released - Appletalk is released - Nintendo Entertainment System (NES) - Linux is introduced - Windows 3.1 - DOOM was released st (turning point of 1 person shooter) - Netscape was established - Yahoo search engine - Windows 95 and IE 1.0 - IEEE 802.11 Wifi standard - Google is released
21

EEE 11

Moore's Law
The number of transistors on a chip will double every 18 to 24 months -Gordon Moore, 1965

EEE 11

22

Transistor Counts
Source: Intel

EEE 11

23

Intel Xeon 7400 Series (2008)

Intel 4004 Microprcessor (1971)


4-bit processor, 1 core 2,000 transistors 0.06MHz

Intel Xeon 7400 Series (2008)


64-bit processor, 6 cores 1.9 billion transistors 2.66 GHz, 130W

EEE 11

24

Desktop Computer

EEE 11

25

Inside Your PC

EEE 11

26

Basic Functional Units of A Computer


Keyboard Mouse Touchscreen Input Memory Monitor Printer Output I/O

Arithmetic and Logic

+,-,/,* compare

EEE 11

Control Primary storage Main memory Volatile Processor Fast expensive, low capacity RAM Secondary storage Non-volatile Cheap, high capacity Generally slower

coordinator

27

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

EEE 11

28

So how does hardware relate to software?

An analogy (Computer Book)


Computer Hardware Software

Book pages and the ink paragraphs & overall theme

A computer without software is like a book full of blank pages Software to makes the computer useful
EEE 11 29

Creating / Building a software


Ideas
Source Source Source Codes Codes Codes Source codes follow a language that is understood by the system

Interpreter

Object files

Linker

Binaries / Executable

Compiler Library EEE 11 30

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

EEE 11

31

Programming Languages: The Four Generations

First generation: machine language form directly understandable by the computers processor (series of 1s & 0s) processor dependent Second generation: assembly language mnemonic system to represent the machine language instructions an assembly process translated the encoded instructions into machine language
32

EEE 11

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 Java, C++, Python, C#

Object-Oriented

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

EEE 11

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

EEE 11

34

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 If radix point is here

Example: 678.91

(r =10 elements are 0, 1 9)


35

6 has a weight of r2=102 EEE 11

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 ABCDEr is A r4 + B r3 + C r2 + D r1 + E r0

EEE 11

36

Example using binary (base 2)


1 1 0 1 1 . 0 12 = ( ? )10 x 2-2 = 0.25 x 2-1 = 0 x 20 = 1 x 21 = 2 x 22 = 0 x 23 = 8 x 24 = 16 Answer = 27.25 10
37

EEE 11

Example using octal (base 8)


1 2 5 0 6 . 1 78 = ( ? )10 x 8-2 = 0.109 x 8-1 = 0.125 x 80 = 6 x 81 = 0 x 82 = 320 x 83 = 1024 x 84 = 4096 Answer = 5446.234 10
EEE 11 38

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
39

EEE 11

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

EEE 11

40

Examples
7710 = ( ? )2 2 /77 2 /38 1 2 /19 0 2 /9 1 2 /4 1 2 /2 0 1 0 ANS: 10011012 5610 = ( ? )2 2 /56 2 /28 0 2 /14 0 2 /7 0 2 /3 1 2 /1 1 0 1 ANS: 1110002

EEE 11

41

Simplified Derivation

Let K = value in Decimal

Let this equal to ABCDE in binary e.g. K=1310 = 011012 (A=0, B=1, C=1,D=0,E=1) = 24A + 23B + 22C +21D+20E = 23A + 22B + 21C +20D remainder E = 23A + 22B + 21C +20D = 22 A + 21 B + 2 0 C remainder D
42

K K/2 L L/2 ...


EEE 11

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

EEE 11

43

Example
0.710 = ( ? )2 , up to 5 bits after the binary point 2 * .7 = 1.4 2 * .4 = 0.8 2 * .8 = 1.6 2 * .6 = 1.2 2 * .2 = 0.4 1 0 1 1 0

Answer: 0.101102

EEE 11

44

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) = 2-1A + 2-2B + 2-3C ... = A + 2-1B + 2-2C ... = 2-1B + 2-2C ... = B + 2-1C

K 2K L 2L ...
EEE 11

A = whole # B = whole #
45

Mixed numbers?

Handle fractional and whole part separately then add

EEE 11

46

Octal to/from binary

An octal digit is ALWAYS equal to three (3) binary digits,

e.g. 58 = 1012

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

EEE 11

47

Example
1 2 5 0 6 1 78 = ( ? )2 111 001 110 000 101 010 001 001 010 101 000 110 001 111 2
48

= = = = = = = Answer =
EEE 11

Hexadecimal to/from binary

A hexadecimal digit is equal to four (4) binary digits


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

EEE 11

Example
E 2 5A 6 1 716 = ( ? )2 = 0111 = 0001 = 0110 = 1010 = 0101 = 0010 = 1110 Answer = 1110 0010 0101 1010 0110 0001 0111 2
EEE 11 50

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 48 = 5274 8

EEE 11

51

Credits

The Center for Programmers and Users. Fundamentals of Programming Hand-out 1 http://www.howstuffworks.com Definitions 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
EEE 11 52

You might also like