Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CIS 230 18-Jan-06. 2 Overview Evolution of C++ Programming Style Syntax & Semantics Comments & White Space Data Types Variables & Declarations cout.

Similar presentations


Presentation on theme: "1 CIS 230 18-Jan-06. 2 Overview Evolution of C++ Programming Style Syntax & Semantics Comments & White Space Data Types Variables & Declarations cout."— Presentation transcript:

1 1 CIS 230 18-Jan-06

2 2 Overview Evolution of C++ Programming Style Syntax & Semantics Comments & White Space Data Types Variables & Declarations cout Operators –Arithmetic –Relational –Logical cin Constants

3 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 4 Programming Style Names Comments Modularity

5 5 Syntax & Semantics Syntax Ex. “Sue kicked the ball” Semantics + - = [ ] ( )

6 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 7 Data Types Integers ex. 15-256+43217 Floating Point Numbers ex.6.5-13.246436.0.97 Characters ex.‘a’‘4’‘&’‘A’ Booleans

8 8 Variables & Declarations Variable Names Declaration Assignment

9 9 cout #include using namespace std; << “string” \n

10 10 cout, continued Cout << “Here is\na sample\noutput;” Result: Here is a sample output

11 11 cout, continued cout << “The answer is” << result; cout << x << y << z;

12 12 cout, continued a = 23; b = 34; x = 3.945; cout << a << ‘\n’ << b << ‘\n’ << x << ‘\n’; cout << a << b << x; Results: 23 34 3.945 23343.945

13 13 Operators Arithmetic Operators * / % + - Increment & Decrement ++ -- Relational & Logical Operators > >= < <= != == && ||

14 14 Arithmetic Operators */%+-*/%+- (Left to Right Precedence)

15 15 Integer Division 9 / 2 = 4;9 % 2 = 1; 17 / 5 = 3;17 % 3 = 2; 15 / 2 = 7;14 % 2 = 0;

16 16 Examples a1 = 7 + 3 * 6 / 2 -1; a2 = 2 % 2 + 2 * 2 -2 / 2; a3 = ( 3 * 9 * ( 3 + (9 * 3 / 3 ) ) );

17 17 Increment & Decrement ++ -- Prefix Postfix

18 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 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 20 Logical Operators Goal: Create more complex conditions Relational Expression: operand operator operand Operators: &&and ||or !not

21 21 Evaluating Logical Operators Value:10 Interpreted As:TrueFalse Example: ABA && BA || B0 01 101

22 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 23 Order of Operations () ++-- */% +- <> = ==!= && || =

24 24 Examples x < y – 3 a = b != c (a = b) != c while (x 5)

25 25 cin #include using namespace std; >> Examples: cin >> x; cin >> x >> y >> z;Input: 13 26 4 xyzxyz 13264

26 26 Cin, continued char ch1, ch2, ch3; cin >> ch1 << ch2 << ch3;Input: a bc ch1ch2ch3 abcabc

27 27 cin, continued int a; float x, y; cin >> x >> a >> y; Input: 17 23.59 4.6 xay 17.23.59

28 28 Constants Cannot change UPPERCASE Type Form:const type NAME = value;

29 29 Constants, continued const float PI = 3.14159; const int STUDENTS = 31; const char INITIAL = ‘x’; //later in program: answer = PI * radius * radius; totalTests = 3 * STUDENTS;


Download ppt "1 CIS 230 18-Jan-06. 2 Overview Evolution of C++ Programming Style Syntax & Semantics Comments & White Space Data Types Variables & Declarations cout."

Similar presentations


Ads by Google