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 .

PRACTICE projecteuler.EEE 11: Programming Fundamentals PRACTICE PRACTICE You don't learn how to play play the piano by reading a book.net . You don't learn how to play basketball by watching ESPN.

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

<64 <60 2.25 2.<92 84 .50 1.<68 60 .0 1.<80 .<88 80 .<72 64 .75 2.25 1.<76 68 .75 3.50 2. Attendance 5% Must pass BOTH ● Final grade 1.0 5.0 92-100 88 .Grading System ● Lecture Grade (50%) Laboratory Grade (50%): Machine Problems 30% Machine Exercises 20% Exams 45% Exercises. HW.0 72 .<84 76 .

Cheng. any book in C is better than having no book at all! ● . actually. 1997 C: How to Program 6/e. Kelley & Pohl. Miller & Quilici. Kernighan & Ritchie. 2010 C by Dissection 4/e.. 2000 C Programming Language.. Dietel & Dietel.Textbooks ● ● ● ● C for engineers and scientists. 1988 . 2009 The Joy of C 3/e.

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). .Class Policies ● UVLE will be used extensively in this course. Students who arrive 30 mins late after the start of the exam will NOT be allowed to take the exam. No make-up or final exam will be given.

. Cheating in the exam....... Keep your phone in silent mode.. machine exercises and machine problems is punishable with a grade of 5.. Practice . A student found absent more than 20% of the total course time (around 3 lecture/lab meetings) may be given a failing grade.. practice . practice .Class Policies ● ● ● ● Attendance will be checked every lecture meeting..... . No eating and drinking inside the lecture halls... or turn it off when the class is in session.0 and is grounds for suspension/expulsion. Avoid talking in class..

EEE 11 Lecture 1: History of Computers Computer System Number Representation .

g.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. calculator EEE 11 16 .

.Abacus 1600s .Joseph Jacquard “programmable” weaving loom .History of Computers: Early days ● ● ● ● ● ● 500 B.John Atanasoff's computer using boolean algebra 1943 .Blaise Pascal and Gottfried Leibniz mechanical calculators 1800s .Charles Babbage's analytical engine .C.punch card system 1940 .John von Neumann architecture: stored-program computers EEE 11 17 .First electronic computer ENIAC Electronic Numerical Integrator and Computer 1951 .

600kg. 150kW EEE 11 18 . £17470 ENIAC (1946) 17.Early computers Babbage Difference Engine (1832) 25k parts. 13.468 vacuum tubes.

1st commercial computer (IBM) .IBM System/360 = 1 OS .UNIX OS by AT&T Bell Labs .TCP is published 19 EEE 11 .UCLA introduces the Internet .Space War = 1st computer game st .Mouse is patented .Intel produces 1st microprocessor .History of Computers: Commercialization ● ● ● ● ● ● 1950s 1957 1962 1964 1968 1969 1970 1972 1973 1974 ● ● ● ● .ARPANET at UCLA .Advanced Research Project Agency (ARPA) .Pong by Atari = 1st commercial video game st .Xerox develops 1 GUI system .

1st commercial network ARCNET .IBM personal computers are introduced using MS-DOS . UDP created . Lotus 1-2-3 .Microsoft is established .0.Apple DOS 3.VisiCalc (early version of spreadsheets) .MS Windows .Apple Computers founded.Wordstar (word processor) .Apple II with colored graphics is introduced .1 (1st OS of Apple computers) .History of Computers: Killer Apps ● ● ● 1975 1976 1977 1978 1979 1981 1982 1983 ● ● ● ● ● EEE 11 .ARPANET standardizes TCP/IP (birth of the modern internet) 20 . Apple I released .Wordperfect 1.TCP splits to TCP/IP.

0 .Google is released 21 EEE 11 .Nintendo Entertainment System (NES) .Windows 3.Appletalk is released .History of Computers: Modern Internet ● 1984 1985 1991 1992 1993 1994 1995 1997 1998 ● ● ● ● ● ● ● ● .11 Wifi standard .IBM releases 1st portable computer (30 lbs) .IEEE 802.1st MUD is released .Yahoo search engine .Linux is introduced .Netscape was established .Windows 95 and IE 1.1 .DOOM was released st (turning point of 1 person shooter) .

1965 EEE 11 22 .Moore's Law “The number of transistors on a chip will double every 18 to 24 months” -Gordon Moore.

Transistor Counts Source: Intel EEE 11 23 .

9 billion transistors 2.000 transistors 0.Intel Xeon 7400 Series (2008) Intel 4004 Microprcessor (1971) 4-bit processor.66 GHz. 130W EEE 11 24 . 6 cores 1. 1 core 2.06MHz Intel Xeon 7400 Series (2008) 64-bit processor.

Desktop Computer EEE 11 25 .

Inside Your PC EEE 11 26 .

-. low capacity ● RAM Secondary storage ● Non-volatile ● Cheap.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. high capacity ● Generally slower coordinator 27 .

disk drives. boards.Hardware vs Software ● Hardware – – Refers to objects that you can actually touch disks. keyboards. but it has no substance EEE 11 28 . printers. and symbols. and chips ● Software – – Untouchable / intangible component of a computer exists as ideas. concepts. display screens.

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 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 32 ● EEE 11 .

C. BASIC. C# – Object-Oriented – ● Fourth generation programming languages (4GL) – closer to human languages – require fewer commands to perform a given task 33 EEE 11 . Pascal. Ada. C++. Python. FORTRAN.Programming Languages: The Four Generations ● Third generation programming languages (3GL) – use of compilers and interpreters to translate statements into machine language – Procedure-oriented – COBOL. Prolog Java. LISP.

Number Representation ● Computers can only process numbers Real-world data are normally mapped to numerical values – ● e. Colors are in RGB values of 0-255 each ● Use of appropriate number systems to make representations simpler EEE 11 34 .g.

1 … 9) 35 6 has a weight of r2=102 EEE 11 .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.

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 .

25 10 37 EEE 11 .Example using binary (base 2) 1 1 0 1 1 .25 x 2-1 = 0 x 20 = 1 x 21 = 2 x 22 = 0 x 23 = 8 x 24 = 16 Answer = 27. 0 12 = ( ? )10 x 2-2 = 0.

1 78 = ( ? )10 x 8-2 = 0.234 10 EEE 11 38 .109 x 8-1 = 0.Example using octal (base 8) 1 2 5 0 6 .125 x 80 = 6 x 81 = 0 x 82 = 320 x 83 = 1024 x 84 = 4096 Answer = 5446.

4. 12.Hexadecimal (Base 16 ) ● Digits include 0. 14. 13.g. 8. 11. 10. ABC16 = 10x162 + 11x161 + 12x160 = 2. 3. 15 Use A = 10 B = 11 C = 12 D = 13 E = 14 F = 15 e. 5. 1. 6. 7. 9.748 39 ● ● EEE 11 . 2.

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 .

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 . B=1. K=1310 = 011012 (A=0.g.D=0. C=1.Simplified Derivation ● Let K = value in Decimal – Let this equal to ABCDE in binary e..

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 .

8 2 * .4 = 0.6 2 * .2 = 0. up to 5 bits after the binary point 2 * .7 = 1.4 1 0 1 1 0 Answer: 0.6 = 1.Example 0.710 = ( ? )2 .2 2 * .101102 EEE 11 44 .4 2 * .8 = 1.

ABC. = A + 2-1B + 2-2C .. K=0. = 2-1B + 2-2C ...g... B=0.6410 = 0. C=1) = 2-1A + 2-2B + 2-3C . in binary e...101..Simplified Derivation ● Let K = value in Decimal – Let this equal to 0...2 (A=1. = 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 .

– e.Octal to/from binary ● An octal digit is ALWAYS equal to three (3) binary digits.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 .

= 101 010 111 100 2 = 5 2 7 48 = 5274 8 ● 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 ..

Credits The Center for Programmers and Users.edu/efmd/161algor.com Flowchart examples from: http://www.iastate.webopedia.eng.wikipedia.howstuffworks.htm#examples Additional reading: http://en. Fundamentals of Programming Hand-out 1 http://www.org/wiki/Computer EEE 11 52 .com Definitions from: http://www.