+ All Categories
Home > Documents > Introduction to Programming Lesson 3. #include #include main ( ) { cout

Introduction to Programming Lesson 3. #include #include main ( ) { cout

Date post: 20-Jan-2018
Category:
Upload: edwin-bradley
View: 231 times
Download: 0 times
Share this document with a friend
Description:
Variable Variable X
21
Introduction to Introduction to Programming Programming Lesson 3 Lesson 3
Transcript
Page 1: Introduction to Programming Lesson 3. #include #include main ( ) { cout

Introduction to Introduction to ProgrammingProgramming

Lesson 3Lesson 3

Page 2: Introduction to Programming Lesson 3. #include #include main ( ) { cout

#include <iostream.h>#include <iostream.h>main ( )main ( ){{

cout << “ Welcome to Virtual University cout << “ Welcome to Virtual University “;“;

}}

Page 3: Introduction to Programming Lesson 3. #include #include main ( ) { cout

VariableVariable

VariableVariable X

Page 4: Introduction to Programming Lesson 3. #include #include main ( ) { cout

VariableVariable Pic of the memoryPic of the memory

2525

1032310323

namenameof the of the variablvariablee

Page 5: Introduction to Programming Lesson 3. #include #include main ( ) { cout

VariableVariableVariable starts withVariable starts with

1.1. CharacterCharacter2.2. Underscore _ Underscore _ (Not (Not

Recommended)Recommended)

Page 6: Introduction to Programming Lesson 3. #include #include main ( ) { cout

VariableVariable Small post boxSmall post box

X

Page 7: Introduction to Programming Lesson 3. #include #include main ( ) { cout

VariableVariableVariable is the name of a Variable is the name of a

location inlocation inthe memorythe memory

e.g. x= 2;e.g. x= 2;

Page 8: Introduction to Programming Lesson 3. #include #include main ( ) { cout

VariableVariableIn a program a variable In a program a variable

has:has:1.1. NameName2.2. TypeType3.3. SizeSize4.4. ValueValue

Page 9: Introduction to Programming Lesson 3. #include #include main ( ) { cout

Assignment Assignment OperatorOperator

==x = 2x = 2

X 2

Page 10: Introduction to Programming Lesson 3. #include #include main ( ) { cout

Assignment Assignment Operator Operator

L.H.S = R.H.S.L.H.S = R.H.S.

X+ 3 = y + 4 X+ 3 = y + 4 WrongWrongZ = x +4Z = x +4x +4 = Z x +4 = Z WrongWrong

Page 11: Introduction to Programming Lesson 3. #include #include main ( ) { cout

X = 10 ; X = 10 ;

X = 30 ;X = 30 ;

X 10

X 30

Page 12: Introduction to Programming Lesson 3. #include #include main ( ) { cout

X = X + 1;X = X + 1;X 10 + 1

= X

11

Page 13: Introduction to Programming Lesson 3. #include #include main ( ) { cout

Data typeData type int i ; -> int i ; ->

Declaration lineDeclaration line

ii

Page 14: Introduction to Programming Lesson 3. #include #include main ( ) { cout

#include <iostream.h>#include <iostream.h>main ( )main ( ){{

int x ;int x ;int y ;int y ;int z ;int z ;x = 10 ;x = 10 ;y = 20 ;y = 20 ;z = x + y ;z = x + y ;

cout << " x = " ;cout << " x = " ;cout << x ;cout << x ;

cout << " y = " ;cout << " y = " ;cout << y ;cout << y ;

cout << " z =x + y = " ;cout << " z =x + y = " ;cout << z ;cout << z ;

}}

Page 15: Introduction to Programming Lesson 3. #include #include main ( ) { cout

int x, y, z ;int x, y, z ;int x; int y; int z int x; int y; int z

;;

Page 16: Introduction to Programming Lesson 3. #include #include main ( ) { cout

Data TypesData Types1.1. intint2.2. shortshort3.3. longlong4.4. floatfloat5.5. doubledouble6.6. charchar

Page 17: Introduction to Programming Lesson 3. #include #include main ( ) { cout

Arithmetic Arithmetic operatorsoperators

PlusPlus ++MinusMinus --MultiplyMultiply **

DivideDivide / / ModulusModulus %%

Page 18: Introduction to Programming Lesson 3. #include #include main ( ) { cout

Arithmetic Arithmetic operatorsoperators

i + ji + jx * yx * ya / ba / ba % ba % b

Page 19: Introduction to Programming Lesson 3. #include #include main ( ) { cout

% = Remainder% = Remainder

5 % 2 = 15 % 2 = 12 % 2 = 02 % 2 = 0

Page 20: Introduction to Programming Lesson 3. #include #include main ( ) { cout

4 / 2 = 24 / 2 = 25 / 2 = ?5 / 2 = ?

Page 21: Introduction to Programming Lesson 3. #include #include main ( ) { cout

PrecedencePrecedence Highest:Highest: ( )( ) Next:Next: * , / , %* , / , % Lowest:Lowest: + , -+ , -


Recommended