CS201- Introduction to Programming- Lecture 22

Post on 18-Dec-2014

15 views 0 download

Tags:

description

Virtual University Course CS201- Introduction to Programming Lecture No 22 Instructor's Name: Dr. Naveed A. Malik Course Email: cs201@vu.edu.pk

transcript

Introduction to ProgrammingIntroduction to Programming

Lecture 22Lecture 22

ReviewReview

Bit wise Manipulation Bit wise Manipulation

andand

Assignment OperatorAssignment Operator

a = a + 1 ;a = a + 1 ;

a += 1 ;a += 1 ;

Bit Manipulation Bit Manipulation OperatorsOperators

&=&= Bitwise AND Assignment OperatorBitwise AND Assignment Operator

|= |= Bitwise OR Assignment OperatorBitwise OR Assignment Operator

^=^= Bitwise Exclusive OR Assignment Bitwise Exclusive OR Assignment

OperatorOperator

Assignment Assignment OperatorOperator

a &= b ;a &= b ;

Same asSame as

a = a & b ;a = a & b ;

Assignment Assignment OperatorOperator

a |= b ;a |= b ;

Same asSame as

a = a | b ;a = a | b ;

Assignment Assignment OperatorOperator

a ^= b ;a ^= b ;

Same asSame as

a = a ^ b ;a = a ^ b ;

Design RecipesDesign Recipes AnalyzeAnalyze a problem statement, a problem statement,

typically expressed as a word problemtypically expressed as a word problem Express its Express its essenceessence, abstractly and , abstractly and

with with examplesexamples FormulateFormulate statementsstatements and and

commentscomments in a in a precise languageprecise language EvaluateEvaluate and and reviserevise the activities in the activities in

the light of checks and tests.the light of checks and tests. PAY ATTENTION TO DETAILPAY ATTENTION TO DETAIL

VariablesVariables

Symbolic Symbolic NamesNames

xx

ii

BasicPayBasicPay

HouseRentHouseRent

Data typesData types Whole numbers: Whole numbers:

– int, short, long, unsigned int, short, long, unsigned Real Numbers (with decimal points)Real Numbers (with decimal points)

– float, doublefloat, double Character dataCharacter data

– charchar

int = 4 bytesint = 4 bytes

char = 1 bytechar = 1 byte

ASCII TableASCII Table

ArraysArraysCollection of same data Collection of same data

typestypes

Arithmetic Arithmetic OperatorsOperators

PlusPlus ++MinusMinus --MultiplyMultiply **DivideDivide / / ModulusModulus %%

Modulus OperatorModulus Operator

a % b ;a % b ;7 % 2 = 1 ;7 % 2 = 1 ;

100 % 20 = 0 ;100 % 20 = 0 ;

Compound Compound Arithmetic Arithmetic OperatorsOperators

+=+=

-=-=

*=*=

/=/=

%=%=

Compound Compound Arithmetic Arithmetic OperatorsOperators

a = a + b ;a = a + b ;

a += b ;a += b ;

Logical Logical OperatorsOperators

ANDAND &&&&

OROR ||||

Comparison Comparison OperatorsOperatorsa < b ;a < b ;

a <= b ;a <= b ;

a == b ;a == b ;

a >= b ;a >= b ;

a > b ;a > b ;

a = b;a = b;

if ( a = b )if ( a = b )

//Wrong//Wrong //Logical Error//Logical Error

a > b ;a > b ;

a >= b ;a >= b ;

Bit wise Bit wise OperatorsOperators

Bit wise AND Bit wise AND & (Binary)& (Binary)

Bit wise ORBit wise OR || (Binary)(Binary)

Bit wise Exclusive ORBit wise Exclusive OR ^ ^ (Binary)(Binary)

NOTNOT ~~ (unary)(unary)

Sequential Sequential ConstructConstruct

Decision ConstructDecision Construct Loop ConstructLoop Construct

If-statementIf-statementif ( condition ) if ( condition )

{{

statement ( s ) ; statement ( s ) ;

}}

If-else If-else if ( condition )if ( condition ){{

statement ( s ) ;statement ( s ) ;}}elseelse{{

statement ( s ) ;statement ( s ) ;

}}

if ( a > b && c < if ( a > b && c < d )d )

Nested if Nested if statementsstatements

if ( condition )if ( condition ){{

statement ( s ) ;statement ( s ) ;

if ( condition )if ( condition ){{

statement ( s ) ;statement ( s ) ;}}statement ( s ) ;statement ( s ) ;

}}

While LoopsWhile Loops

while ( a > b )while ( a > b )

{{

statement ( s ) ;statement ( s ) ;

}}

While LoopsWhile Loops

While loop executes While loop executes

zero or more timeszero or more times

Do - whileDo - whiledo do

{{

statement ( s ) ;statement ( s ) ;

}}

while ( condition ) ;while ( condition ) ;

Do - whileDo - whileDo-while loop Do-while loop

executes executes

one or more one or more timestimes

For LoopsFor Loops

for ( i = 0 ; i < 10 ; i ++ ; )for ( i = 0 ; i < 10 ; i ++ ; )

{{

statement ( s ) ;statement ( s ) ;

}}

i = i + 1 ;i = i + 1 ; i += 1 ;i += 1 ; i ++ ;i ++ ;

Switch StatementSwitch Statement

break ;break ; continue ;continue ;

FunctionsFunctions

Call by valueCall by value Call by referenceCall by reference

ArraysArrays

ArraysArraysint a [ 10 ] ;int a [ 10 ] ;

a [ 0 ] ;a [ 0 ] ;::

a [ 9 ] ;a [ 9 ] ;

PointersPointers

PointersPointers

Memory address of a Memory address of a variable is stored variable is stored inside a pointerinside a pointer

Files and their Files and their

Input / Output Input / Output systemssystems