Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 1 Lecture Material Penn State University CMPSC 201 – C++ Programming for Engineers Original class notes from Dough Hogan,

Similar presentations


Presentation on theme: "Week 1 Lecture Material Penn State University CMPSC 201 – C++ Programming for Engineers Original class notes from Dough Hogan,"— Presentation transcript:

1 Week 1 Lecture Material Penn State University CMPSC 201 – C++ Programming for Engineers Original class notes from Dough Hogan, http://www.personal.psu.edu/djh300/index.htm Computer Science Theory & Introduction

2 Hardware vs. Software Hardware : physical components of a computer system essentially, things you can touch input, output, storage devices Software : A collection of computer programs and its related data that provides the instructions telling a computer what to do! In contrast to hardware, software "cannot be touched“! 0s and 1s : Owing to its straightforward implementation in digital electronic circuitry using logic gates, the binary system is used internally by all modern computers.

3 Hardware vs. Software Application Software System Software Hardware

4 Components of a Computer Central processing unit (CPU) Memory Input devices Output devices Storage devices

5 Central Processing Unit (CPU) Basic job: handle processing of instructions What’s an instruction? Two parts: Control Unit (CU) Arithmetic and Logic Unit (ALU)

6 The ALU Built up from digital logic gates AND OR NOT most primitive level

7 Memory Holds programs that are currently running and the data being used by those programs. Two categories: Read-only memory (ROM) can only read data Random-access memory (RAM) can read and write information primary storage - computer’s main memory volatile

8 Sequential Access vs. Random Access Sequential Access: must access each location in memory in order Random Access: can access memory locations using addresses, in any order Speed implications? Track 1 Track 2

9 Memory: sizes base unit: 1 bit = binary digit, 0 or 1 8 bits = 1 byte (B) 1000 bytes ≈ 1 kilobyte (KB) 1000 KB ≈ 1,000,000 B ≈ 1 megabyte (MB) 1000 MB ≈ 1,000,000,000 B ≈ 1 gigabyte (GB)

10 Storage Devices Floppy disk 3.5 inches, 1.44 MB Hard disk typically sizes in GB Compact disc (CD) 650-700 MB CD-ROM: read-only memory CD-R: recordable CD-RW: rewritable

11 More Storage Devices Digital Versitale/Video Disc (DVD) 4.7 GB Flash drives varies Zip disks and tape drives varies

12 Input Devices mouse keyboard scanner camera microphone

13 Output Devices monitor cathode ray tube (CRT) liquid crystal display (LCD) printer speakers

14 Software Overview System software Controls basic operations of computer The operating system manages memory, files, application software File management tasks – deleting, etc.

15 Software Overview Application software Not essential to system running Enables you to perform specific tasks Ex: Office software Web browsers Media players Games

16 Algorithms and Languages

17 Algorithms An algorithm is a set of instructions to solve a problem. Think recipes! Many algorithms may solve the same problem! How do we choose between them? The answer is that: Different Algorithms differ in the time and the space they take to run! we choose the most efficient algorithm according to our resources! (space and time) Example: You may have a lot of memory and your only concern is how fast the program runs, or the other way around.

18 Programming Paradigms/Models Procedural Programming: specify steps to solve problem, use procedures to implement those steps Procedures are called methods in C++ Object-Oriented Programming (OOP): create objects to model real-world entities. e.g. an employee object As in real world each object has its own Information: (represented by data types) Behaviors: (implemented by methods/procedures) Objects can interact, as they do in real world Event-Driven Programming: create methods that respond to events like mouse clicks, key presses, etc. Others: Functional, logic, etc.

19 Compiling Process Source Code (C++) Object Code Executable Program Object Code from Libraries compilerlinker Compiler is a software that transforms a source code written in one programming language into a program in another language (usually machine language, a language than can be executed by CPU) Code in machine language

20 linker :A program that takes two or more object files generated by a compiler and combines them into a single executable program. Source Code (C++) Object Code Executable Program Object Code from Libraries compilerlinker

21 Library has been complied before!, it won’t need to be compiled every time. Object Code from Libraries Source Code of library (C++) compiler

22 Compiled vs. Interpreted Languages Interpreted Language Requires software called an interpreter to run the code Code is checked for errors as it runs (if erroneous code: does the best it can…) Examples: HTML, JavaScript, PHP Compiled Language Requires software called a compiler to translate the program into (usually) an executable program with machine language Syntax errors will be found during compilation code will be syntax-error free while executing (running) Examples: C, C++, Pascal, FORTRAN, BASIC

23 Errors Syntax Errors Much like using incorrect punctuation or grammar in English Compiler reports syntax errors; program won’t run until they’re resolved Logic Errors Program doesn’t solve the problem correctly It May be correct syntactically, but it is not doing what is supposed to do (according to specification of program)! Runtime Errors Errors that occur while the program is running, e.g. problems accessing memory, divide by zero

24 Abstraction Abstraction is a fundamental concept to CS Principle of ignoring details, so that by focusing on more general concepts we are able to use complex devices Focusing on the WHAT, rather than HOW Example: Abstract of a paper! Example: Your report template!

25 Levels of Abstraction 0. Digital Logic 1. Machine Language A system of instructions, that are executable directly by the CPU. Every CPU has an instruction set architecture (ISA) of its own! 2. Operating System 3. Low-Level Language Low refers to small or no amount of abstraction from machine language. e.g. Assembly language 4. High-Level Language High refers to strong abstraction from the details of the CPU design Uses natural language elements, thus it’s easier to understand 5. Application Software

26 Binary Numbers Use two symbols: 0 and 1 to represents numbers Base 2 Compare with decimal number system Uses symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 to represents numbers Base 10 At the lowest level of abstraction, everything in a computer is expressed in binary.

27 Binary Numbers, ctd. 0 1 10 2 11 3 100 4 101 5 110 6 111 7 1000 8 1001 9 1010 10 1011 11 1100 12 1101 13 1110 14 1111 15 10000 16

28 Binary Numbers, ctd. 0 1 10 2 11 3 100 4 101 5 110 6 111 7 1000 8 1001 9 1010 10 1011 11 1100 12 1101 13 1110 14 1111 15 10000 16 1 1 + 1 _____________________ 1 0 0 1 0 0 0 + 1 _____________________ 1 0 0 1

29 Convert Vs. Decimal

30 Other Number Systems Any positive integer could be the base of a number system. (Big topic in number theory.) Others used in computer science: Octal: Base 8 Hexadecimal: Base 16 New symbols A, B, C, D, E, F

31 Example of machine language instructions At the lowest level of abstraction, everything in a computer is expressed in binary. This is an example of an ‘Add’ instruction: 000000 00001 00010 00110 00000 100000 Couple of more examples of machine language instructions: 100011 00011 01000 00000 00001 000100 000010 00000 00000 00000 10000 000000

32 Hello World Example in Assembly Language.model small.stack.data message db "Hello world, I'm learning Assembly !!!", "$".code main proc mov ax,seg message mov ds,ax mov ah,09 lea dx,message int 21h mov ax,4c00h int 21h min endp enad main

33 ASCII Every character on a computer -- letters, digits, symbols, etc. -- is represented by a numeric code behind the scenes. ASCII is a character-encoding scheme based on the ordering of the English alphabet Short for American Standard Code for Information Interchange. Most modern character-encoding schemes are based on ASCII, though they support many more characters than does ASCII. We’ll learn more in lab…

34 Moor’s Law

35 # Transistors on a Processor ProcessorDateNumber of Transistors 400419712,250 800819722,500 808019745,000 8086197829,000 2861982120,000 3861985275,000 486 DX19891,180,000 Pentium19933,100,000 Pentium II19977,500,000 Pentium III199924,000,000 Pentium 4200042,000,000 Data for Intel processors: Data from Section 4.1 of : Yates, Daniel S., and David S. Moore and Daren S. Starnes. The Practice of Statistics. 2nd Ed. New York: Freeman, 2003.

36 A Graphical View Graph from Intel's web site (http://www.intel.com/technology/mooreslaw/index.htm); Retrieved 9/24/2006http://www.intel.com/technology/mooreslaw/index.htm Pay attention to the units on the axes…

37 Moore’s Law Prediction from Gordon Moore of Intel in 1965. Implication: The speed of processors doubles roughly every 12 to 18 months. Can this go on forever?


Download ppt "Week 1 Lecture Material Penn State University CMPSC 201 – C++ Programming for Engineers Original class notes from Dough Hogan,"

Similar presentations


Ads by Google