+ All Categories
Home > Education > CS201- Introduction to Programming- Lecture 22

CS201- Introduction to Programming- Lecture 22

Date post: 18-Dec-2014
Category:
Upload: bilal-ahmed
View: 15 times
Download: 0 times
Share this document with a friend
Description:
Virtual University Course CS201- Introduction to Programming Lecture No 22 Instructor's Name: Dr. Naveed A. Malik Course Email: [email protected]
Popular Tags:
45
Introduction to Programmin Introduction to Programming Lecture 22 Lecture 22 Review Review
Transcript
Page 1: CS201- Introduction to Programming- Lecture 22

Introduction to ProgrammingIntroduction to Programming

Lecture 22Lecture 22

ReviewReview

Page 2: CS201- Introduction to Programming- Lecture 22

Bit wise Manipulation Bit wise Manipulation

andand

Assignment OperatorAssignment Operator

Page 3: CS201- Introduction to Programming- Lecture 22

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

a += 1 ;a += 1 ;

Page 4: CS201- Introduction to Programming- Lecture 22

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

Page 5: CS201- Introduction to Programming- Lecture 22

Assignment Assignment OperatorOperator

a &= b ;a &= b ;

Same asSame as

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

Page 6: CS201- Introduction to Programming- Lecture 22

Assignment Assignment OperatorOperator

a |= b ;a |= b ;

Same asSame as

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

Page 7: CS201- Introduction to Programming- Lecture 22

Assignment Assignment OperatorOperator

a ^= b ;a ^= b ;

Same asSame as

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

Page 8: CS201- Introduction to Programming- Lecture 22

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

Page 9: CS201- Introduction to Programming- Lecture 22

VariablesVariables

Page 10: CS201- Introduction to Programming- Lecture 22

Symbolic Symbolic NamesNames

xx

ii

BasicPayBasicPay

HouseRentHouseRent

Page 11: CS201- Introduction to Programming- Lecture 22

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

Page 12: CS201- Introduction to Programming- Lecture 22

int = 4 bytesint = 4 bytes

char = 1 bytechar = 1 byte

Page 13: CS201- Introduction to Programming- Lecture 22

ASCII TableASCII Table

Page 14: CS201- Introduction to Programming- Lecture 22

ArraysArraysCollection of same data Collection of same data

typestypes

Page 15: CS201- Introduction to Programming- Lecture 22

Arithmetic Arithmetic OperatorsOperators

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

Page 16: CS201- Introduction to Programming- Lecture 22

Modulus OperatorModulus Operator

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

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

Page 17: CS201- Introduction to Programming- Lecture 22

Compound Compound Arithmetic Arithmetic OperatorsOperators

+=+=

-=-=

*=*=

/=/=

%=%=

Page 18: CS201- Introduction to Programming- Lecture 22

Compound Compound Arithmetic Arithmetic OperatorsOperators

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

a += b ;a += b ;

Page 19: CS201- Introduction to Programming- Lecture 22

Logical Logical OperatorsOperators

ANDAND &&&&

OROR ||||

Page 20: CS201- Introduction to Programming- Lecture 22

Comparison Comparison OperatorsOperatorsa < b ;a < b ;

a <= b ;a <= b ;

a == b ;a == b ;

a >= b ;a >= b ;

a > b ;a > b ;

Page 21: CS201- Introduction to Programming- Lecture 22

a = b;a = b;

Page 22: CS201- Introduction to Programming- Lecture 22

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

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

Page 23: CS201- Introduction to Programming- Lecture 22

a > b ;a > b ;

a >= b ;a >= b ;

Page 24: CS201- Introduction to Programming- Lecture 22

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)

Page 25: CS201- Introduction to Programming- Lecture 22

Sequential Sequential ConstructConstruct

Decision ConstructDecision Construct Loop ConstructLoop Construct

Page 26: CS201- Introduction to Programming- Lecture 22

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

{{

statement ( s ) ; statement ( s ) ;

}}

Page 27: CS201- Introduction to Programming- Lecture 22

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

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

statement ( s ) ;statement ( s ) ;

}}

Page 28: CS201- Introduction to Programming- Lecture 22

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

Page 29: CS201- Introduction to Programming- Lecture 22

Nested if Nested if statementsstatements

Page 30: CS201- Introduction to Programming- Lecture 22

if ( condition )if ( condition ){{

statement ( s ) ;statement ( s ) ;

if ( condition )if ( condition ){{

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

}}

Page 31: CS201- Introduction to Programming- Lecture 22

While LoopsWhile Loops

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

{{

statement ( s ) ;statement ( s ) ;

}}

Page 32: CS201- Introduction to Programming- Lecture 22

While LoopsWhile Loops

While loop executes While loop executes

zero or more timeszero or more times

Page 33: CS201- Introduction to Programming- Lecture 22

Do - whileDo - whiledo do

{{

statement ( s ) ;statement ( s ) ;

}}

while ( condition ) ;while ( condition ) ;

Page 34: CS201- Introduction to Programming- Lecture 22

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

executes executes

one or more one or more timestimes

Page 35: CS201- Introduction to Programming- Lecture 22

For LoopsFor Loops

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

{{

statement ( s ) ;statement ( s ) ;

}}

Page 36: CS201- Introduction to Programming- Lecture 22

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

Page 37: CS201- Introduction to Programming- Lecture 22

Switch StatementSwitch Statement

Page 38: CS201- Introduction to Programming- Lecture 22

break ;break ; continue ;continue ;

Page 39: CS201- Introduction to Programming- Lecture 22

FunctionsFunctions

Page 40: CS201- Introduction to Programming- Lecture 22

Call by valueCall by value Call by referenceCall by reference

Page 41: CS201- Introduction to Programming- Lecture 22

ArraysArrays

Page 42: CS201- Introduction to Programming- Lecture 22

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

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

a [ 9 ] ;a [ 9 ] ;

Page 43: CS201- Introduction to Programming- Lecture 22

PointersPointers

Page 44: CS201- Introduction to Programming- Lecture 22

PointersPointers

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

Page 45: CS201- Introduction to Programming- Lecture 22

Files and their Files and their

Input / Output Input / Output systemssystems


Recommended