Presentation is loading. Please wait.

Presentation is loading. Please wait.

2. Second Step for Learning C++ Programming • Data Type • Char • Float

Similar presentations


Presentation on theme: "2. Second Step for Learning C++ Programming • Data Type • Char • Float"— Presentation transcript:

1 2. Second Step for Learning C++ Programming • Data Type • Char • Float
• Double • #define • Comments

2 [Practice 01 Hello World]

3 [Explain 01 Hello World]

4 [Practice 02 Basic C++ Programming]

5 [Explain 02 Basic C++ Programming]
a Preprocessor directive function header start of function body make definitions visible message insert a new line more output terminate main() end of function body

6 [Practice 03 comments]

7 [Practice 04 #define]

8 [Explain 04 #define]

9 Const You can add the const modifier to the declaration of a variable to tell the compiler that the value cannot be changed: const double factor = 5.0/9.0; const double offset = 32.0; celcius = (fahr - offset)*factor; 09/2014

10 What if you try to change a const?
The compiler will complain if your code tries to modify a const variable: const foo = 100; foo = 21; Error: l-value specifies const object 09/2014

11 Const Why use const? 1. const tells the compiler that a variable should never be changed. 2. Typesafe (partial) replacement for #define in C++ 3. May be used for increasing code quality 09/2014

12 Mathematical expressions have numeric values when evaluated.
Math Expressions Mathematical expressions have numeric values when evaluated. Some examples: 1+2 (fahr - 32)*(5/9) 1*(2*(3*(4*5))) 09/2014

13 [Practice 05 Math Operator Rules]

14 [Explain 05 Math Operator Rules]

15 [Practice 06 Addition of integers]

16 [Explain 06 Addition of integers]

17 a single byte, capable of holding one character
Basic Data Types in C++ char a single byte, capable of holding one character int an integer, typically reflecting the natural size of integer on the host machine float single precision floating-point double double precision floating-point bool a boolean value (true or false) 09/2014

18 Keyword auto enum restrict unsigned break extern return void case
float short volatile char for signed while const goto sizeof _bool continue if static _Complex default inline struct _Imaginary do int switch double long typedef else register union

19 Simple Variables Name in C++
Ο int poodle; //valid Ο int Poodle; //valid and distinct from poodle Ο int POODLE; //valid and even more distinct Χ Int terrier; //invalid – has to be int, not Int Ο int my_stars3; //valid Ο int _Mystars3; //valid – starts with underscore Χ int 4ever; //invalid because starts with a digit Χ int double; //invalid – double is a c++ keyword Ο int begin; //valid – begin is a Pascal keyword Ο int __fools; //valid – starts with two underscores Ο int the_very_best_variable_i_can_be_version_112; //valid Χ int apple-4; //invalid – no hyphens allowed

20 [Practice 07 Data Type]

21 [Explain 07 Data Type]

22 ASCII CODE

23 [Practice 08 char]

24 [Explain 08 char]

25 [Practice 09 float]

26 [Explain 09 float]

27 Repetition Control Structures
3. Third step for Learning C++ Programming ㅎㅎ logical operator if if else switch while do while for Repetition Control Structures

28 && Operator (logical AND opterator)
&& is a boolean operator, so the value of an expression is true or false. ( cond1 && cond2 ) is true only if both cond1 and cond2 are true. 09/2014

29 || Operator (logical OR operator)
|| is a boolean operator, so the value of an expression is true or false. ( cond1 || cond2 ) is true if either of cond1 or cond2 is true. 09/2014

30 The ! operator (logical NOT operator)
The ! operator is a unary boolean operator unary means it has only 1 operand. ! negates it's operand. ! means "not". (! condition) is true only when condition is false 09/2014

31 [ Practice 01 logical operator ]

32 [ Explain 01 logical operator ]

33 if (condition ) action;
if structure The if control structure allows us to state that an action (sequence of statements) should happen only when some condition is true: if (condition ) action; 09/2014

34 [ Practice 02 if ]

35 [ Explain 02 if ]

36 if else structure The if else control structure allows you to specify an alternative action: if ( condition ) action if true else action if false 09/2014

37 [ Practice 03 if else ]

38 [ Explain 03 if else ]

39 switch statement Syntax switch (expression) { case const-expr : statements; break; case const-expr : statements; break; … default statements; break; } 09/2014

40 [ Practice 04 switch ]

41 [ Explain 04 switch ] 0 ≦ code ≦ 4

42 while Control Structure
The while control structure supports repetition - the same statement (or compound statement) is repeated until the condition is false. while (condition) do something; the inside is called the "body of the loop" 09/2014

43 [ Practice 05 while ]

44 [ Explain 05 while ]

45 do while The do while control structure also provides repetition, this time the condition is at the bottom of the loop. the body is always executed at least once do somestuff ; while ( condition ); 09/2014

46 [ Practice 06 do while ]

47 [ Explain 06 do while ]

48 You can write any for loop as a while (and any while as a for).
for loops The for control structure is often used for loops that involve counting. You can write any for loop as a while (and any while as a for). for (initialization; condition; update) do something; 09/2014

49 [ Practice 01]

50


Download ppt "2. Second Step for Learning C++ Programming • Data Type • Char • Float"

Similar presentations


Ads by Google