Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 1 Introduction CS 1 Part 11. Hardware 1.Central Processing Unit (CPU) 2.Main Memory 3.Secondary Memory / Storage 4.Input Devices 5.Output Devices CS.

Similar presentations


Presentation on theme: "CS 1 Introduction CS 1 Part 11. Hardware 1.Central Processing Unit (CPU) 2.Main Memory 3.Secondary Memory / Storage 4.Input Devices 5.Output Devices CS."— Presentation transcript:

1 CS 1 Introduction CS 1 Part 11

2 Hardware 1.Central Processing Unit (CPU) 2.Main Memory 3.Secondary Memory / Storage 4.Input Devices 5.Output Devices CS 1 Part 12

3 Main Memory It is volatile. Main memory is erased when program terminates or computer is turned off Also called Random Access Memory (RAM) Organized as follows: – bit: smallest piece of memory. Has values 0 (off, false) or 1 (on, true) – byte: 8 consecutive bits. Bytes have addresses. Addresses are sequential numbers from 0 to the maximum amount of memory in your computer. CS 1 Part 13

4 Memory Organization CS 1 Part 14 In the chart above, the number 149 is stored in the byte with the address 16, and the number 72 is stored at address 23. What these numbers might mean depends upon the program. The concept of the “stored program” computer is this: that the numbers can be machine instructions.

5 Secondary Storage Non-volatile: data retained when program is not running or computer is turned off Comes in a variety of media: – magnetic: floppy disk, hard drive – optical: CD-ROM, DVD – Flash drives, connected to the USB port – Solid-state drives instead of rotating disks CS 1 Part 15

6 Machine Instructions The C++ compiler translates your program, which is relatively easy for you to read, into binary numbers which are the instructions and data the computer understands. CS 1 Part 16

7 Binary (base 2) Inside a computer, the contents of memory cells can be either on or off, or zero or 1. Place value: in base 10 you have units, 10s, 100s, 1000s, etc. In binary: units, 2s, 4s, 8s, 16s, 32s, etc. Powers of 2 vs. powers of 10. Count in binary on your fingers. Thus there are 10 kinds of people: those who understand binary and those who don’t. CS 1 Part 17

8 Binary Addition Add: 0 0 1 1 0 1 0 1 0 0 1 0 1 1 0 1 --------------- 0 1 1 0 0 0 1 0 Four rules: 0+0=0 1+0=1 1+1=0 carry 1 1+1+1 = 1 carry 1 CS 1 Part 18

9 Base 8 and Base 16 It’s easy to convert between base 2 and either base 8 (octal) or base 16 (hexadecimal) by just grouping digits. Convert 11000111 to hex: Groups of 4 because 2^4 th =16 1100=12 10 = C 16 ; 0111=7 10 CS 1 Part 19

10 Binary to Base 10 Place values: 128 64 32 16 8 4 2 1 0 0 1 1 0 1 0 1 So in the example we have: CS 1 Part 110 0x128=00x8=0 1x32=321x4=4 0x64=00x2=0 1x16=161x1=1 Add 32+16+4+1=53

11 Elements of a Program Common elements in programming languages: – Key Words – Programmer-Defined Identifiers – Operators – Punctuation – Syntax CS 1 Part 111

12 Keywords Also known as reserved words Have a special meaning in C++ Can not be used for any other purpose CS 1 Part 112

13 Identifiers Names made up by the programmer Not part of the C++ language Used to represent various things: variables (memory locations), functions, etc. CS 1 Part 113

14 Operators and Precedence Used to perform operations on data Many types of operators: – Arithmetic – * (multiply), / (divide), + (add), - (subtract) – Assignment – ex: = the equal sign – Comparison: == CS 1 Part 114

15 Punctuation Use semicolon to end statements (not every line is a statement) Use comma to separate items in a list. CS 1 Part 115

16 Grouping Parentheses alter the order of operations in an expression, and enclose function arguments. Braces {} group statements together. Brackets [] are used for array references. CS 1 Part 116

17 Language Syntax Syntax refers to the way the elements of a language are put together. For example, in English the verb form doesn’t usually tell you the subject, while in Spanish it does. Programming language syntax is the way program statements are constructed. Semantics refers to what the statements “mean.” CS 1 Part 117

18 Variables A variable is a named storage location in the computer’s memory for holding a piece of data. The contents can be changed by a program. CS 1 Part 118

19 Variable Declaration To create a variable in a program you must write a variable definition (also called a variable declaration) You supply a name and the data type. Examples: – int hours; – double pay; – char answer; CS 1 Part 119

20 What Programs Do Reduced to simplest terms, a program: Takes some form of input Does some processing to it Creates some kind of output CS 1 Part 120

21 Three Basic Constructs Execution in sequence Making a decision Looping CS 1 Part 121

22 Creating a Program 1.Define clearly and precisely what the program is to do. 2.Use various tools to create a model of the program. 3.Check your model for errors. 4.Write code that reflects the model. 5.Compile the code, which checks for syntax errors. 6.Correct any errors you find and go back to step 5 if there are any. 7.Run the program with test data and determine whether the results are correct. 8.If the results are not what you wanted, make changes and go back to step 7. 9.Validate the results. CS 1 Part 122

23 Two Programming Paradigms Procedural programming focuses on the process. The program generally executes from start to finish in a linear way. Object-oriented programs focus on objects, which have both data and methods that act on the data. While an object-oriented program can be procedural, most respond to messages from external events. CS 1 Part 123


Download ppt "CS 1 Introduction CS 1 Part 11. Hardware 1.Central Processing Unit (CPU) 2.Main Memory 3.Secondary Memory / Storage 4.Input Devices 5.Output Devices CS."

Similar presentations


Ads by Google