1 / 23

CS 1

CS 1. Introduction. Hardware. Central Processing Unit (CPU) Main Memory Secondary Memory / Storage Input Devices Output Devices. Main Memory. It is volatile. Main memory is erased when program terminates or computer is turned off Also called Random Access Memory (RAM)

adelle
Download Presentation

CS 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 1 Introduction CS 1 Part 1

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

  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 1

  4. Memory Organization • 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. CS 1 Part 1

  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 1

  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 1

  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 1

  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 1

  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^4th =16 • 1100=1210 = C16; 0111=710 CS 1 Part 1

  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 1

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

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

  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 1

  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 1

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

  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 1

  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 1

  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 1

  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 1

  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 1

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

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

  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 1

More Related