cs201- introduction to programming- lecture 22
DESCRIPTION
Virtual University Course CS201- Introduction to Programming Lecture No 22 Instructor's Name: Dr. Naveed A. Malik Course Email: [email protected]TRANSCRIPT
![Page 1: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/1.jpg)
Introduction to ProgrammingIntroduction to Programming
Lecture 22Lecture 22
ReviewReview
![Page 2: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/2.jpg)
Bit wise Manipulation Bit wise Manipulation
andand
Assignment OperatorAssignment Operator
![Page 3: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/3.jpg)
a = a + 1 ;a = a + 1 ;
a += 1 ;a += 1 ;
![Page 4: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/4.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/5.jpg)
Assignment Assignment OperatorOperator
a &= b ;a &= b ;
Same asSame as
a = a & b ;a = a & b ;
![Page 6: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/6.jpg)
Assignment Assignment OperatorOperator
a |= b ;a |= b ;
Same asSame as
a = a | b ;a = a | b ;
![Page 7: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/7.jpg)
Assignment Assignment OperatorOperator
a ^= b ;a ^= b ;
Same asSame as
a = a ^ b ;a = a ^ b ;
![Page 8: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/8.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/9.jpg)
VariablesVariables
![Page 10: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/10.jpg)
Symbolic Symbolic NamesNames
xx
ii
BasicPayBasicPay
HouseRentHouseRent
![Page 11: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/11.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/12.jpg)
int = 4 bytesint = 4 bytes
char = 1 bytechar = 1 byte
![Page 13: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/13.jpg)
ASCII TableASCII Table
![Page 14: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/14.jpg)
ArraysArraysCollection of same data Collection of same data
typestypes
![Page 15: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/15.jpg)
Arithmetic Arithmetic OperatorsOperators
PlusPlus ++MinusMinus --MultiplyMultiply **DivideDivide / / ModulusModulus %%
![Page 16: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/16.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/17.jpg)
Compound Compound Arithmetic Arithmetic OperatorsOperators
+=+=
-=-=
*=*=
/=/=
%=%=
![Page 18: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/18.jpg)
Compound Compound Arithmetic Arithmetic OperatorsOperators
a = a + b ;a = a + b ;
a += b ;a += b ;
![Page 19: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/19.jpg)
Logical Logical OperatorsOperators
ANDAND &&&&
OROR ||||
![Page 20: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/20.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/21.jpg)
a = b;a = b;
![Page 22: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/22.jpg)
if ( a = b )if ( a = b )
//Wrong//Wrong //Logical Error//Logical Error
![Page 23: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/23.jpg)
a > b ;a > b ;
a >= b ;a >= b ;
![Page 24: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/24.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/25.jpg)
Sequential Sequential ConstructConstruct
Decision ConstructDecision Construct Loop ConstructLoop Construct
![Page 26: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/26.jpg)
If-statementIf-statementif ( condition ) if ( condition )
{{
statement ( s ) ; statement ( s ) ;
}}
![Page 27: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/27.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/28.jpg)
if ( a > b && c < if ( a > b && c < d )d )
![Page 29: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/29.jpg)
Nested if Nested if statementsstatements
![Page 30: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/30.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/31.jpg)
While LoopsWhile Loops
while ( a > b )while ( a > b )
{{
statement ( s ) ;statement ( s ) ;
}}
![Page 32: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/32.jpg)
While LoopsWhile Loops
While loop executes While loop executes
zero or more timeszero or more times
![Page 33: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/33.jpg)
Do - whileDo - whiledo do
{{
statement ( s ) ;statement ( s ) ;
}}
while ( condition ) ;while ( condition ) ;
![Page 34: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/34.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/35.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/36.jpg)
i = i + 1 ;i = i + 1 ; i += 1 ;i += 1 ; i ++ ;i ++ ;
![Page 37: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/37.jpg)
Switch StatementSwitch Statement
![Page 38: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/38.jpg)
break ;break ; continue ;continue ;
![Page 39: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/39.jpg)
FunctionsFunctions
![Page 40: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/40.jpg)
Call by valueCall by value Call by referenceCall by reference
![Page 41: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/41.jpg)
ArraysArrays
![Page 42: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/42.jpg)
ArraysArraysint a [ 10 ] ;int a [ 10 ] ;
a [ 0 ] ;a [ 0 ] ;::
a [ 9 ] ;a [ 9 ] ;
![Page 43: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/43.jpg)
PointersPointers
![Page 44: CS201- Introduction to Programming- Lecture 22](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/44.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061211/5492e76bb47959610c8b48c3/html5/thumbnails/45.jpg)
Files and their Files and their
Input / Output Input / Output systemssystems