cs201- introduction to programming- lecture 35
DESCRIPTION
Virtual University Course CS201- Introduction to Programming Lecture No 35 Instructor's Name: Dr. Naveed A. Malik Course Email: [email protected]TRANSCRIPT
![Page 1: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/1.jpg)
Introduction to Introduction to ProgrammingProgramming
Lecture 35Lecture 35
![Page 2: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/2.jpg)
Input/Output Input/Output Streams Streams
![Page 3: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/3.jpg)
File File Input/OutputInput/Output
![Page 4: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/4.jpg)
StreaStreamm
![Page 5: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/5.jpg)
scanf ( ) ;scanf ( ) ;printf ( ) ;printf ( ) ;
![Page 6: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/6.jpg)
StreamStream
Stream is an ordered Stream is an ordered
sequence of bytessequence of bytes
![Page 7: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/7.jpg)
Stream Stream Input/OutputInput/Output
![Page 8: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/8.jpg)
Input stream objectInput stream object
cincin
Output stream Output stream objectobject
coutcout
![Page 9: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/9.jpg)
>>>>
<<<<
Stream Operators
![Page 10: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/10.jpg)
int i ;int i ;
char c ;char c ;
cin >> i ;cin >> i ;
cin >> c ;cin >> c ;
ExampleExample
![Page 11: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/11.jpg)
Every stream Every stream has:has:– A sourceA source– A destination A destination
![Page 12: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/12.jpg)
State State
![Page 13: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/13.jpg)
int i , j ;int i , j ;
cin >> i >> j ;cin >> i >> j ;
cout << i / j ;cout << i / j ;
ExampleExample
![Page 14: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/14.jpg)
Formatted Formatted Input / OutputInput / Output
![Page 15: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/15.jpg)
Member FunctionsMember Functions
![Page 16: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/16.jpg)
cin.get ( ) ;cin.get ( ) ;
![Page 17: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/17.jpg)
c = cin.get ( ) ;c = cin.get ( ) ;cin.get ( char cin.get ( char c ) ;c ) ;
![Page 18: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/18.jpg)
cin.read ( char * buffer , streamsize n cin.read ( char * buffer , streamsize n ))
More than one character is read
Integer type to express counts in streams
![Page 19: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/19.jpg)
<<<<
![Page 20: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/20.jpg)
cout.put (char cout.put (char c ) ;c ) ;
![Page 21: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/21.jpg)
#include #include <iostream.h><iostream.h>
![Page 22: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/22.jpg)
iomanip.hiomanip.h
![Page 23: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/23.jpg)
cerrcerrclogclog
![Page 24: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/24.jpg)
Buffered Buffered Input/OutputInput/Output
![Page 25: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/25.jpg)
BufferBuffer
![Page 26: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/26.jpg)
flushflush
![Page 27: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/27.jpg)
““\n”\n”
![Page 28: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/28.jpg)
cout << endl cout << endl ;;
![Page 29: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/29.jpg)
cauxcauxcprncprn
![Page 30: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/30.jpg)
cout << “The value of the first cout << “The value of the first
integer is” << i ; integer is” << i ;
![Page 31: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/31.jpg)
Stream Stream Insertion Insertion OperatorOperator
![Page 32: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/32.jpg)
ostream & ostream :: operator << ( char * ostream & ostream :: operator << ( char * text )text )
![Page 33: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/33.jpg)
Stream Stream Extraction Extraction
OperatorOperator
![Page 34: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/34.jpg)
int i , j ;int i , j ;
cin >> i >> cin >> i >> j ;j ;
ExampleExample
![Page 35: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/35.jpg)
cin.getline ( char * buffer , int buff_size , char delimiter = ‘\cin.getline ( char * buffer , int buff_size , char delimiter = ‘\n’ )n’ )
100
![Page 36: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/36.jpg)
cin.unget cin.unget ( ) ;( ) ;cin.peek ( ) ;cin.peek ( ) ;
![Page 37: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/37.jpg)
cout.put ( char ch ) ;cout.put ( char ch ) ;cout.write ( char * str , int n cout.write ( char * str , int n ) ;) ;
![Page 38: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/38.jpg)
char name [ 60 ] ;char name [ 60 ] ;
cin >> name ;cin >> name ;
cout << name ;cout << name ;
ExampleExample
![Page 39: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/39.jpg)
char name1 [ 30 ] , name2 [ 30 ] ;char name1 [ 30 ] , name2 [ 30 ] ;cin >> name1 >> name2 ;cin >> name1 >> name2 ;
ExampleExample
![Page 40: CS201- Introduction to Programming- Lecture 35](https://reader033.vdocuments.net/reader033/viewer/2022061211/5492e74cb4795900548b45f0/html5/thumbnails/40.jpg)
We learnt We learnt Input / Output StreamInput / Output Stream
cin , cout , cerr , clogcin , cout , cerr , clog How to create our own objectHow to create our own object Overload Stream OperatorsOverload Stream Operators
In Today’s In Today’s Lecture Lecture