1 CIS Jan-06
2 Overview Evolution of C++ Programming Style Syntax & Semantics Comments & White Space Data Types Variables & Declarations cout Operators –Arithmetic –Relational –Logical cin Constants
3 Evolution of C++ BCLP (Basic Cambridge Programming Language) –Early 1960s; Martin Richards B –1970; Ken Thompson C –Early 1970s; Dennis Ritchie C++ –1979; Bjarne Stroustrup
4 Programming Style Names Comments Modularity
5 Syntax & Semantics Syntax Ex. “Sue kicked the ball” Semantics + - = [ ] ( )
6 Comments & White Space Comments //One line comment /*Starts comment Block comments – may be several lines long */Ends comment White Space –Space, tab, Statement
7 Data Types Integers ex Floating Point Numbers ex Characters ex.‘a’‘4’‘&’‘A’ Booleans
8 Variables & Declarations Variable Names Declaration Assignment
9 cout #include using namespace std; << “string” \n
10 cout, continued Cout << “Here is\na sample\noutput;” Result: Here is a sample output
11 cout, continued cout << “The answer is” << result; cout << x << y << z;
12 cout, continued a = 23; b = 34; x = 3.945; cout << a << ‘\n’ << b << ‘\n’ << x << ‘\n’; cout << a << b << x; Results:
13 Operators Arithmetic Operators * / % + - Increment & Decrement Relational & Logical Operators > >= < <= != == && ||
14 Arithmetic Operators */%+-*/%+- (Left to Right Precedence)
15 Integer Division 9 / 2 = 4;9 % 2 = 1; 17 / 5 = 3;17 % 3 = 2; 15 / 2 = 7;14 % 2 = 0;
16 Examples a1 = * 6 / 2 -1; a2 = 2 % * 2 -2 / 2; a3 = ( 3 * 9 * ( 3 + (9 * 3 / 3 ) ) );
17 Increment & Decrement Prefix Postfix
18 Increment & Decrement a = 7; b = ++a; b = 8 AND a = 8 a = 7; b = a++; b = 7 and a = 8 a = 7; --a;a--; a = 6
19 Relational Operators Goal: Compare conditions Relational Expression: operand operator operand Operators: greater than = greater than or equal to == equal to!= not equal to
20 Logical Operators Goal: Create more complex conditions Relational Expression: operand operator operand Operators: &&and ||or !not
21 Evaluating Logical Operators Value:10 Interpreted As:TrueFalse Example: ABA && BA || B
22 Relational & Logical Operators Goal: Create more complex comparisons Examples: ( age > 40 ) && ( height > 70 ) ( age > 40 ) || ( height > 70 ) || ( weight > 150 ) ! ( ( age > 40 ) && ( height > 70 ) )
23 Order of Operations () ++-- */% +- <> = ==!= && || =
24 Examples x < y – 3 a = b != c (a = b) != c while (x 5)
25 cin #include using namespace std; >> Examples: cin >> x; cin >> x >> y >> z;Input: xyzxyz 13264
26 Cin, continued char ch1, ch2, ch3; cin >> ch1 << ch2 << ch3;Input: a bc ch1ch2ch3 abcabc
27 cin, continued int a; float x, y; cin >> x >> a >> y; Input: xay
28 Constants Cannot change UPPERCASE Type Form:const type NAME = value;
29 Constants, continued const float PI = ; const int STUDENTS = 31; const char INITIAL = ‘x’; //later in program: answer = PI * radius * radius; totalTests = 3 * STUDENTS;