Presentation is loading. Please wait.

Presentation is loading. Please wait.

Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.

Similar presentations


Presentation on theme: "Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming."— Presentation transcript:

1 Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming  Reading: 1.1-1.4  Exercises: p. 23 #1-6, 9-11, 20

2 Wednesday, 9/4/02, Slide #2 2 Hardware Components of a Computer Central Processing Unit Internal Memory: RAM and ROM Input devices Keyboard Mouse DVD Output devices Monitor Printer Speakers Combination Input/Output devices Modem External memory Hard disk CD-R, CD-RW Zip disk

3 Wednesday, 9/4/02, Slide #3 3 Computer Terminology  Staples advertisement, 8/30/02, $1500 computer:  1.6 GHz processor (CPU)  Gigahertz = billions (10 9 ) of cycles (operations) per second  256MB RAM (“Random Access Memory”)  Volatile memory: Lost when computer turned off  1 Byte = 8 bits = 8 zeros and ones  Megabyte = millions of bytes  30 GB Hard Drive: Non-volatile, auxiliary memory  Modem, DVD, CD-RW, Monitor

4 Wednesday, 9/4/02, Slide #4 4 Computers and Programs  The job of the CPU is to execute programs  A program is a sequence of instructions  The language understood by the CPU is machine language -- written in 0’s and 1’s  Very “low-level” simple commands: load, store, add  Assembly language: simple translation of machine language using letters

5 Wednesday, 9/4/02, Slide #5 5 High-level languages and compilers  C++ is a “high-level” language: commands to do complex tasks, written in language close to English (also: Java, Pascal, BASIC, etc.)  Compiler: a program that translates high-level language to machine language  Program Development Environment (PDE): a multi-part system containing editor, compiler, linker, etc. to aid in high-level program development and testing: MS Visual C++

6 Wednesday, 9/4/02, Slide #6 6 Structure of a simple C++ program  Top section contains preprocessor directives, definitions, declarations  “main()” function contains (in brackets) sequence of instructions to be executed #include using namespace std; void main() { cout << ”Hello.”; }

7 Wednesday, 9/4/02, Slide #7 7 Program Style and Statements  Program style: Use of spacing, indentation, comments, meaningful names to help readability  All useless for compiler but useful for programmer  Some types of program statements:  Output (only one in this example)  Input  Assignment  Condition or Selection  Loop or Repetition

8 Wednesday, 9/4/02, Slide #8 8 The C++ output statement  cout << “Hello.”;  cout is the name of the “output stream object”, namely the monitor screen  << is the “insertion operator”: It instructs the computer to put the value to its right into the output stream object on the left  “Hello.” is a value, in this case a string constant  ; (semicolon) indicates the end of the statement  Another example:  cout << 1 << “ + “ << 2 << “ = “ << 3 << endl;

9 Wednesday, 9/4/02, Slide #9 9 Variables for C++ Input  To perform input: getting a value from an input device into memory, we first must reserve and name a memory location of the correct type (number, string, etc.)  Some simple C++ variable types: float, int, double, char, string  A float variable is used for general numbers that may have fractional parts (3.14, -2.7E9)

10 Wednesday, 9/4/02, Slide #10 10 The float variable declaration statement  float Name; or  float Name1, Name2, …, Namek;  float is a reserved word (key word), i.e. a word with meaning in the C++ language  The name is chosen by the programmer:  Must not be a reserved word!  Must begin with a letter  May use only letters, numbers, and underscores (_)

11 Wednesday, 9/4/02, Slide #11 11 The C++ input statement  cin >> Variable_Name;  cin is the name of the “input stream object”, namely the keyboard  >> is the “extraction operator”: It instructs the computer to take the next value in the input stream and store it in the memory location represented by the variable name  Example: float Num1, Num2; cin >> Num1 >> Num2; cout << “Sum = “ << Num1 + Num2;

12 Wednesday, 9/4/02, Slide #12 12 Variables vs. objects, an exercise  By a C++ variable we mean a named location in memory to store a particular type of data  By a C++ object we mean a variable together with operations that make sense for that type of variable  For float objects, we have arithmetic operations, input, output operations, etc.  Exercise: Write a complete program that inputs miles driven and gallons of gas bought, and computes miles per gallon


Download ppt "Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming."

Similar presentations


Ads by Google