Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.

Similar presentations


Presentation on theme: "Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3."— Presentation transcript:

1 Computer Engineering 1 st Semester Dr. Rabie A. Ramadan http://rabieramadan.org 3

2 2 C++ Names The name of a variable could: Starts with an underscore “_” or a letter, lowercase or uppercase, e.g. _Students, pRice Can include letters, underscore, or digits. Examples are: keyboard, total_grade, _Score_Side1 Cannot include special characters such as !, %, ], or $ Cannot include an empty space Cannot be any of the reserved words Should not be longer than 32 characters (although allowed)

3 3 Reserved Words

4 4 Variables and Their Data Types The amount of memory space necessary to store a variable is also referred to as a data type.

5 5

6 6 Variables and Their Data Types char 8 bits Signed char: -128  +127 Unsigned char 0  255 Escape sequences are characters

7 Escape characters 7

8 Examples 8

9 9 Variables and Their Data Types Integers – 32 bits or 4 bytes Holds numerical data Signed or Unsigned Short integers 16 bits or 2 bytes Signed or Unsigned Long integers To enforce positive numbers 32 bit long

10 10 Example

11 11 Practice -- what is the o/p

12 12 Practice -- what is the o/p

13 13 O/P

14 14 Variables and Their Data Types Floating points Real numbers  ex. 5.5 4 bytes Declared as : float x; Floating number with double precision 8 bytes Declared as : double x; Larger storage 10 bytes Declared as: long double x;

15 Example 15

16 16 Variables and Their Data Types String Group of characters No limit Declared as: string name; getline() function Takes the data from external source and save it into a string variable Ex. getline(cin, name); cin is to notify the compiler that the data is coming from external source Ex. getline( cin, name, ‘?’)  getline( cin, stringName, delimiter ) Saves the data when the delimiter is entered

17 Example 17

18 Example (cont.) 18

19 19 What are constants? const PI = 3.14; #define PI 3.14

20 20 Operators and Operands “Don't cut the tree that shades you.”

21 21 Operators Arithmetic : Unary Operators  sign (+ or -) Algebraic operators + Addition - Subtraction * Multiplication / Division % Reminder ++ Increment -- Decrement += Add to the current content -= subtract from the current content *=, /=,..

22 22 Operators Logical operators o/p true or false ! NOT && AND || OR > greater than < less than >= greater than <= less than == equal

23 23 Operators

24 24 Operators Conditional operator (?) :

25 25 Operators Explicit type casting operator Converts a datum of a given type to another.

26 26 Operator Precedence Operator classificationOperators parentheses( ) postfix operators[] x++ x-- unary operators++x --x +x -x ! creation or castnew (type)x multiplicative* / % additive+ - relational >= <= equality (boolean)= = != logical AND&& logical OR|| assignment=

27 27 Example

28 28 Example

29 29 Example

30 30 Control Statement

31 31 Flow of the Control

32 32 Control Statements Ways for a programmer to control what pieces of the program are to be executed at certain times. branching statements and loops.

33 33 Branching Statement

34 34 Example

35 35 Nesting Branch

36 36

37 37 Switch Statement

38 38 Switch Statement

39 39 Reading Materials Chapters 1, 2 and 3, 5 (till 5.3).


Download ppt "Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3."

Similar presentations


Ads by Google