SlideShare a Scribd company logo
Object Oriented Programming: 13
Input Stream /Extraction Operator
Prof Neeraj Bhargava
Vaibhav Khanna
Department of Computer Science
School of Engineering and Systems Sciences
Maharshi Dayanand Saraswati University Ajmer
2
I/O Streams and Standard I/O Devices
‱ I/O: sequence of bytes (stream of bytes) from
source to destination
– Bytes are usually characters, unless program
requires other types of information
‱ Stream: sequence of characters from source
to destination
‱ Input stream: sequence of characters from an
input device to the computer
‱ Output stream: sequence of characters from
the computer to an output device
3
I/O Streams and Standard I/O Devices
(continued)
‱ Use iostream header file to extract
(receive) data from keyboard and send output
to the screen
– Contains definitions of two data types:
‱ istream - input stream
‱ ostream - output stream
– Has two variables:
‱ cin - stands for common input
‱ cout - stands for common output
4
I/O Streams and Standard I/O Devices
(continued)
‱ To use cin and cout, the preprocessor
directive#include <iostream> must be
used
‱ Variable declaration is similar to:
– istream cin;
– ostream cout;
‱ Input stream variables: type istream
‱ Output stream variables: type ostream
5
cin and the Extraction Operator >>
‱ The syntax of an input statement using cin
and the extraction operator >> is:
‱ The extraction operator >> is binary
– Left-side operand is an input stream variable
‱ Example: cin
– Right-side operand is a variable
6
cin and the Extraction Operator >>
(continued)
‱ No difference between a single cin with
multiple variables and multiple cin
statements with one variable
‱ When scanning, >> skips all whitespace
– Blanks and certain nonprintable characters
‱ >> distinguishes between character 2 and
number 2 by the right-side operand of >>
– If type char or int (or double), the 2 is
treated as a character or as a number 2
7
cin and the Extraction Operator >>
(continued)
‱ Entering a char value into an int or
double variable causes serious errors, called
input failure
8
cin and the Extraction Operator >>
(continued)
‱ When reading data into a char variable
– >> skips leading whitespace, finds and stores only
the next character
– Reading stops after a single character
‱ To read data into an int or double variable
– >> skips leading whitespace, reads + or - sign (if
any), reads the digits (including decimal)
– Reading stops on whitespace non-digit character
9
cin and the Extraction Operator >>
(continued)
Object oriented programming 13 input stream and devices in cpp
11
Using Predefined Functions in a
Program
‱ Function (subprogram): set of instructions
– When activated, it accomplishes a task
‱ main executes when a program is run
‱ Other functions execute only when called
‱ C++ includes a wealth of functions
– Predefined functions are organized as a collection
of libraries called header files
12
Using Predefined Functions in a
Program (continued)
‱ Header file may contain several functions
‱ To use a predefined function, you need the
name of the appropriate header file
– You also need to know:
‱ Function name
‱ Number of parameters required
‱ Type of each parameter
‱ What the function is going to do
13
Using Predefined Functions in a
Program (continued)
‱ To use pow (power), include cmath
– Two numeric parameters
– Syntax: pow(x,y) = xy
‱ x and y are the arguments or parameters
– In pow(2,3), the parameters are 2 and 3
Object oriented programming 13 input stream and devices in cpp
15
Using Predefined Functions in a
Program (continued)
Sample Run:
Line 1: 2 to the power of 6 = 64
Line 4: 12.5 to the power of 3 = 1953.13
Line 5: Square root of 24 = 4.89898
Line 7: u = 181.019
Line 9: Length of str = 20
16
cin and the get Function
‱ The get function
– Inputs next character (including whitespace)
– Stores in memory location indicated by its
argument
‱ The syntax of cin and the get function:
varChar
– Is a char variable
– Is the argument (parameter) of the function
17
cin and the ignore Function
‱ ignore: discards a portion of the input
‱ The syntax to use the function ignore is:
intExp is an integer expression
chExp is a char expression
‱ If intExp is a value m, the statement says to
ignore the next m characters or all characters until
the character specified by chExp
18
putback and peek Functions
‱ putback function
– Places previous character extracted by the get
function from an input stream back to that stream
‱ peek function
– Returns next character from the input stream
– Does not remove the character from that stream
19
putback and peek Functions
(continued)
‱ The syntax for putback:
– istreamVar: an input stream variable (cin)
– ch is a char variable
‱ The syntax for peek:
– istreamVar: an input stream variable (cin)
– ch is a char variable
20
The Dot Notation Between I/O
Stream Variables and I/O Functions
‱ In the statement
cin.get(ch);
cin and get are two separate identifiers
separated by a dot
‱ Dot separates the input stream variable name
from the member, or function, name
‱ In C++, dot is the member access operator
21
Input Failure
‱ Things can go wrong during execution
‱ If input data does not match corresponding
variables, program may run into problems
‱ Trying to read a letter into an int or double
variable will result in an input failure
‱ If an error occurs when reading data
– Input stream enters the fail state
22
The clear Function
‱ Once in a fail state, all further I/O statements
using that stream are ignored
‱ The program continues to execute with
whatever values are stored in variables
– This causes incorrect results
‱ The clear function restores input stream to
a working state
Assignment
‱ Explain in detail the functioning of Input
Stream Operator
‱ What do you understand by Input Failure and
what is the role of clear function

More Related Content

What's hot (17)

COMPUTER ORGANIZATION NOTES Unit 6
COMPUTER ORGANIZATION NOTES Unit 6COMPUTER ORGANIZATION NOTES Unit 6
COMPUTER ORGANIZATION NOTES Unit 6
Dr.MAYA NAYAK
 
COMPUTER ORGANIZATION NOTES Unit 2
COMPUTER ORGANIZATION NOTES  Unit 2COMPUTER ORGANIZATION NOTES  Unit 2
COMPUTER ORGANIZATION NOTES Unit 2
Dr.MAYA NAYAK
 
Class 2 variables, classes methods...
Class 2   variables, classes methods...Class 2   variables, classes methods...
Class 2 variables, classes methods...
Fernando Loizides
 
Instruction codes
Instruction codesInstruction codes
Instruction codes
jyoti_lakhani
 
Ch 8
Ch 8Ch 8
Ch 8
Nitesh Singh
 
Sequential and combinational alu
Sequential and combinational alu Sequential and combinational alu
Sequential and combinational alu
Piyush Rochwani
 
RTL-Design for beginners
RTL-Design  for beginnersRTL-Design  for beginners
RTL-Design for beginners
Dr.YNM
 
Computer Architecture - Data Path & Pipeline Hazards
Computer Architecture - Data Path & Pipeline HazardsComputer Architecture - Data Path & Pipeline Hazards
Computer Architecture - Data Path & Pipeline Hazards
Thyagharajan K.K.
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
Kamal Acharya
 
Lesson 5 .1 selection structure
Lesson 5 .1 selection structureLesson 5 .1 selection structure
Lesson 5 .1 selection structure
MLG College of Learning, Inc
 
Lesson 3.2 data types for memory location
Lesson 3.2 data types for memory locationLesson 3.2 data types for memory location
Lesson 3.2 data types for memory location
MLG College of Learning, Inc
 
Combinational Circuits & Sequential Circuits
Combinational Circuits & Sequential CircuitsCombinational Circuits & Sequential Circuits
Combinational Circuits & Sequential Circuits
gourav kottawar
 
Java 8
Java 8Java 8
Java 8
AbhimanuHandoo
 
Lecture 3 instruction set
Lecture 3  instruction setLecture 3  instruction set
Lecture 3 instruction set
Pradeep Kumar TS
 
Ece 465 project_1_report_vishesh_shravan
Ece 465 project_1_report_vishesh_shravanEce 465 project_1_report_vishesh_shravan
Ece 465 project_1_report_vishesh_shravan
Vishesh Chanana
 
Bitstuffing
BitstuffingBitstuffing
Bitstuffing
Vishal Kr
 
C basics
C basicsC basics
C basics
sridevi5983
 
COMPUTER ORGANIZATION NOTES Unit 6
COMPUTER ORGANIZATION NOTES Unit 6COMPUTER ORGANIZATION NOTES Unit 6
COMPUTER ORGANIZATION NOTES Unit 6
Dr.MAYA NAYAK
 
COMPUTER ORGANIZATION NOTES Unit 2
COMPUTER ORGANIZATION NOTES  Unit 2COMPUTER ORGANIZATION NOTES  Unit 2
COMPUTER ORGANIZATION NOTES Unit 2
Dr.MAYA NAYAK
 
Class 2 variables, classes methods...
Class 2   variables, classes methods...Class 2   variables, classes methods...
Class 2 variables, classes methods...
Fernando Loizides
 
Instruction codes
Instruction codesInstruction codes
Instruction codes
jyoti_lakhani
 
Sequential and combinational alu
Sequential and combinational alu Sequential and combinational alu
Sequential and combinational alu
Piyush Rochwani
 
RTL-Design for beginners
RTL-Design  for beginnersRTL-Design  for beginners
RTL-Design for beginners
Dr.YNM
 
Computer Architecture - Data Path & Pipeline Hazards
Computer Architecture - Data Path & Pipeline HazardsComputer Architecture - Data Path & Pipeline Hazards
Computer Architecture - Data Path & Pipeline Hazards
Thyagharajan K.K.
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
Kamal Acharya
 
Combinational Circuits & Sequential Circuits
Combinational Circuits & Sequential CircuitsCombinational Circuits & Sequential Circuits
Combinational Circuits & Sequential Circuits
gourav kottawar
 
Lecture 3 instruction set
Lecture 3  instruction setLecture 3  instruction set
Lecture 3 instruction set
Pradeep Kumar TS
 
Ece 465 project_1_report_vishesh_shravan
Ece 465 project_1_report_vishesh_shravanEce 465 project_1_report_vishesh_shravan
Ece 465 project_1_report_vishesh_shravan
Vishesh Chanana
 
Bitstuffing
BitstuffingBitstuffing
Bitstuffing
Vishal Kr
 

Similar to Object oriented programming 13 input stream and devices in cpp (20)

C++ Ch3
C++ Ch3C++ Ch3
C++ Ch3
Venkateswarlu Vuggam
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
Online
 
L4.pdf
L4.pdfL4.pdf
L4.pdf
mohammedaqeel37
 
C++ ch2
C++ ch2C++ ch2
C++ ch2
Venkateswarlu Vuggam
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptx
DeepasCSE
 
Input and Output
Input and OutputInput and Output
Input and Output
Jason J Pulikkottil
 
Chapter 3 malik
Chapter 3 malikChapter 3 malik
Chapter 3 malik
Oshal Shah
 
Chapter 3 malik
Chapter 3 malikChapter 3 malik
Chapter 3 malik
Oshal Shah
 
Chapter 3 malik
Chapter 3 malikChapter 3 malik
Chapter 3 malik
Oshal Shah
 
COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
Managing console input and output
Managing console input and outputManaging console input and output
Managing console input and output
gourav kottawar
 
Computer Organisation and Architecture (COA)
Computer Organisation and Architecture (COA)Computer Organisation and Architecture (COA)
Computer Organisation and Architecture (COA)
SwapnitaSrivastava1
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
input/output function presentation.pptx.
input/output function presentation.pptx.input/output function presentation.pptx.
input/output function presentation.pptx.
antisha0803
 
Chap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxChap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptx
Ronaldo Aditya
 
Computer programming and utilization
Computer programming and utilizationComputer programming and utilization
Computer programming and utilization
Digvijaysinh Gohil
 
programming week 2.ppt
programming week 2.pptprogramming week 2.ppt
programming week 2.ppt
FatimaZafar68
 
Object oriented programming 12 programming steps in cpp and example
Object oriented programming 12 programming steps in cpp and exampleObject oriented programming 12 programming steps in cpp and example
Object oriented programming 12 programming steps in cpp and example
Vaibhav Khanna
 
Input and output in c++
Input and output in c++Input and output in c++
Input and output in c++
Asaye Dilbo
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
Online
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptx
DeepasCSE
 
Chapter 3 malik
Chapter 3 malikChapter 3 malik
Chapter 3 malik
Oshal Shah
 
Chapter 3 malik
Chapter 3 malikChapter 3 malik
Chapter 3 malik
Oshal Shah
 
Chapter 3 malik
Chapter 3 malikChapter 3 malik
Chapter 3 malik
Oshal Shah
 
COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
Managing console input and output
Managing console input and outputManaging console input and output
Managing console input and output
gourav kottawar
 
Computer Organisation and Architecture (COA)
Computer Organisation and Architecture (COA)Computer Organisation and Architecture (COA)
Computer Organisation and Architecture (COA)
SwapnitaSrivastava1
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
input/output function presentation.pptx.
input/output function presentation.pptx.input/output function presentation.pptx.
input/output function presentation.pptx.
antisha0803
 
Chap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxChap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptx
Ronaldo Aditya
 
Computer programming and utilization
Computer programming and utilizationComputer programming and utilization
Computer programming and utilization
Digvijaysinh Gohil
 
programming week 2.ppt
programming week 2.pptprogramming week 2.ppt
programming week 2.ppt
FatimaZafar68
 
Object oriented programming 12 programming steps in cpp and example
Object oriented programming 12 programming steps in cpp and exampleObject oriented programming 12 programming steps in cpp and example
Object oriented programming 12 programming steps in cpp and example
Vaibhav Khanna
 
Input and output in c++
Input and output in c++Input and output in c++
Input and output in c++
Asaye Dilbo
 
Ad

More from Vaibhav Khanna (20)

Information and network security 47 authentication applications
Information and network security 47 authentication applicationsInformation and network security 47 authentication applications
Information and network security 47 authentication applications
Vaibhav Khanna
 
Information and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithmInformation and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithm
Vaibhav Khanna
 
Information and network security 45 digital signature standard
Information and network security 45 digital signature standardInformation and network security 45 digital signature standard
Information and network security 45 digital signature standard
Vaibhav Khanna
 
Information and network security 44 direct digital signatures
Information and network security 44 direct digital signaturesInformation and network security 44 direct digital signatures
Information and network security 44 direct digital signatures
Vaibhav Khanna
 
Information and network security 43 digital signatures
Information and network security 43 digital signaturesInformation and network security 43 digital signatures
Information and network security 43 digital signatures
Vaibhav Khanna
 
Information and network security 42 security of message authentication code
Information and network security 42 security of message authentication codeInformation and network security 42 security of message authentication code
Information and network security 42 security of message authentication code
Vaibhav Khanna
 
Information and network security 41 message authentication code
Information and network security 41 message authentication codeInformation and network security 41 message authentication code
Information and network security 41 message authentication code
Vaibhav Khanna
 
Information and network security 40 sha3 secure hash algorithm
Information and network security 40 sha3 secure hash algorithmInformation and network security 40 sha3 secure hash algorithm
Information and network security 40 sha3 secure hash algorithm
Vaibhav Khanna
 
Information and network security 39 secure hash algorithm
Information and network security 39 secure hash algorithmInformation and network security 39 secure hash algorithm
Information and network security 39 secure hash algorithm
Vaibhav Khanna
 
Information and network security 38 birthday attacks and security of hash fun...
Information and network security 38 birthday attacks and security of hash fun...Information and network security 38 birthday attacks and security of hash fun...
Information and network security 38 birthday attacks and security of hash fun...
Vaibhav Khanna
 
Information and network security 37 hash functions and message authentication
Information and network security 37 hash functions and message authenticationInformation and network security 37 hash functions and message authentication
Information and network security 37 hash functions and message authentication
Vaibhav Khanna
 
Information and network security 35 the chinese remainder theorem
Information and network security 35 the chinese remainder theoremInformation and network security 35 the chinese remainder theorem
Information and network security 35 the chinese remainder theorem
Vaibhav Khanna
 
Information and network security 34 primality
Information and network security 34 primalityInformation and network security 34 primality
Information and network security 34 primality
Vaibhav Khanna
 
Information and network security 33 rsa algorithm
Information and network security 33 rsa algorithmInformation and network security 33 rsa algorithm
Information and network security 33 rsa algorithm
Vaibhav Khanna
 
Information and network security 32 principles of public key cryptosystems
Information and network security 32 principles of public key cryptosystemsInformation and network security 32 principles of public key cryptosystems
Information and network security 32 principles of public key cryptosystems
Vaibhav Khanna
 
Information and network security 31 public key cryptography
Information and network security 31 public key cryptographyInformation and network security 31 public key cryptography
Information and network security 31 public key cryptography
Vaibhav Khanna
 
Information and network security 30 random numbers
Information and network security 30 random numbersInformation and network security 30 random numbers
Information and network security 30 random numbers
Vaibhav Khanna
 
Information and network security 29 international data encryption algorithm
Information and network security 29 international data encryption algorithmInformation and network security 29 international data encryption algorithm
Information and network security 29 international data encryption algorithm
Vaibhav Khanna
 
Information and network security 28 blowfish
Information and network security 28 blowfishInformation and network security 28 blowfish
Information and network security 28 blowfish
Vaibhav Khanna
 
Information and network security 27 triple des
Information and network security 27 triple desInformation and network security 27 triple des
Information and network security 27 triple des
Vaibhav Khanna
 
Information and network security 47 authentication applications
Information and network security 47 authentication applicationsInformation and network security 47 authentication applications
Information and network security 47 authentication applications
Vaibhav Khanna
 
Information and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithmInformation and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithm
Vaibhav Khanna
 
Information and network security 45 digital signature standard
Information and network security 45 digital signature standardInformation and network security 45 digital signature standard
Information and network security 45 digital signature standard
Vaibhav Khanna
 
Information and network security 44 direct digital signatures
Information and network security 44 direct digital signaturesInformation and network security 44 direct digital signatures
Information and network security 44 direct digital signatures
Vaibhav Khanna
 
Information and network security 43 digital signatures
Information and network security 43 digital signaturesInformation and network security 43 digital signatures
Information and network security 43 digital signatures
Vaibhav Khanna
 
Information and network security 42 security of message authentication code
Information and network security 42 security of message authentication codeInformation and network security 42 security of message authentication code
Information and network security 42 security of message authentication code
Vaibhav Khanna
 
Information and network security 41 message authentication code
Information and network security 41 message authentication codeInformation and network security 41 message authentication code
Information and network security 41 message authentication code
Vaibhav Khanna
 
Information and network security 40 sha3 secure hash algorithm
Information and network security 40 sha3 secure hash algorithmInformation and network security 40 sha3 secure hash algorithm
Information and network security 40 sha3 secure hash algorithm
Vaibhav Khanna
 
Information and network security 39 secure hash algorithm
Information and network security 39 secure hash algorithmInformation and network security 39 secure hash algorithm
Information and network security 39 secure hash algorithm
Vaibhav Khanna
 
Information and network security 38 birthday attacks and security of hash fun...
Information and network security 38 birthday attacks and security of hash fun...Information and network security 38 birthday attacks and security of hash fun...
Information and network security 38 birthday attacks and security of hash fun...
Vaibhav Khanna
 
Information and network security 37 hash functions and message authentication
Information and network security 37 hash functions and message authenticationInformation and network security 37 hash functions and message authentication
Information and network security 37 hash functions and message authentication
Vaibhav Khanna
 
Information and network security 35 the chinese remainder theorem
Information and network security 35 the chinese remainder theoremInformation and network security 35 the chinese remainder theorem
Information and network security 35 the chinese remainder theorem
Vaibhav Khanna
 
Information and network security 34 primality
Information and network security 34 primalityInformation and network security 34 primality
Information and network security 34 primality
Vaibhav Khanna
 
Information and network security 33 rsa algorithm
Information and network security 33 rsa algorithmInformation and network security 33 rsa algorithm
Information and network security 33 rsa algorithm
Vaibhav Khanna
 
Information and network security 32 principles of public key cryptosystems
Information and network security 32 principles of public key cryptosystemsInformation and network security 32 principles of public key cryptosystems
Information and network security 32 principles of public key cryptosystems
Vaibhav Khanna
 
Information and network security 31 public key cryptography
Information and network security 31 public key cryptographyInformation and network security 31 public key cryptography
Information and network security 31 public key cryptography
Vaibhav Khanna
 
Information and network security 30 random numbers
Information and network security 30 random numbersInformation and network security 30 random numbers
Information and network security 30 random numbers
Vaibhav Khanna
 
Information and network security 29 international data encryption algorithm
Information and network security 29 international data encryption algorithmInformation and network security 29 international data encryption algorithm
Information and network security 29 international data encryption algorithm
Vaibhav Khanna
 
Information and network security 28 blowfish
Information and network security 28 blowfishInformation and network security 28 blowfish
Information and network security 28 blowfish
Vaibhav Khanna
 
Information and network security 27 triple des
Information and network security 27 triple desInformation and network security 27 triple des
Information and network security 27 triple des
Vaibhav Khanna
 
Ad

Recently uploaded (20)

FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
Automating Map Production With FME and Python
Automating Map Production With FME and PythonAutomating Map Production With FME and Python
Automating Map Production With FME and Python
Safe Software
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Simplify Training with an Online Induction Portal for Contractors
Simplify Training with an Online Induction Portal for ContractorsSimplify Training with an Online Induction Portal for Contractors
Simplify Training with an Online Induction Portal for Contractors
SHEQ Network Limited
 
Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...
Rishab Acharya
 
Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
Rebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core FoundationRebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core Foundation
Cadabra Studio
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Design by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First DevelopmentDesign by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First Development
Par-Tec S.p.A.
 
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
SheenBrisals
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Content Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ ProductivityContent Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ Productivity
Alex Vladimirovich
 
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
Nacho Cougil
 
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATIONAI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
miso_uam
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
Automating Map Production With FME and Python
Automating Map Production With FME and PythonAutomating Map Production With FME and Python
Automating Map Production With FME and Python
Safe Software
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Simplify Training with an Online Induction Portal for Contractors
Simplify Training with an Online Induction Portal for ContractorsSimplify Training with an Online Induction Portal for Contractors
Simplify Training with an Online Induction Portal for Contractors
SHEQ Network Limited
 
Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...
Rishab Acharya
 
Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
Rebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core FoundationRebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core Foundation
Cadabra Studio
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Design by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First DevelopmentDesign by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First Development
Par-Tec S.p.A.
 
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
SheenBrisals
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Content Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ ProductivityContent Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ Productivity
Alex Vladimirovich
 
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
Nacho Cougil
 
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATIONAI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
miso_uam
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 

Object oriented programming 13 input stream and devices in cpp

  • 1. Object Oriented Programming: 13 Input Stream /Extraction Operator Prof Neeraj Bhargava Vaibhav Khanna Department of Computer Science School of Engineering and Systems Sciences Maharshi Dayanand Saraswati University Ajmer
  • 2. 2 I/O Streams and Standard I/O Devices ‱ I/O: sequence of bytes (stream of bytes) from source to destination – Bytes are usually characters, unless program requires other types of information ‱ Stream: sequence of characters from source to destination ‱ Input stream: sequence of characters from an input device to the computer ‱ Output stream: sequence of characters from the computer to an output device
  • 3. 3 I/O Streams and Standard I/O Devices (continued) ‱ Use iostream header file to extract (receive) data from keyboard and send output to the screen – Contains definitions of two data types: ‱ istream - input stream ‱ ostream - output stream – Has two variables: ‱ cin - stands for common input ‱ cout - stands for common output
  • 4. 4 I/O Streams and Standard I/O Devices (continued) ‱ To use cin and cout, the preprocessor directive#include <iostream> must be used ‱ Variable declaration is similar to: – istream cin; – ostream cout; ‱ Input stream variables: type istream ‱ Output stream variables: type ostream
  • 5. 5 cin and the Extraction Operator >> ‱ The syntax of an input statement using cin and the extraction operator >> is: ‱ The extraction operator >> is binary – Left-side operand is an input stream variable ‱ Example: cin – Right-side operand is a variable
  • 6. 6 cin and the Extraction Operator >> (continued) ‱ No difference between a single cin with multiple variables and multiple cin statements with one variable ‱ When scanning, >> skips all whitespace – Blanks and certain nonprintable characters ‱ >> distinguishes between character 2 and number 2 by the right-side operand of >> – If type char or int (or double), the 2 is treated as a character or as a number 2
  • 7. 7 cin and the Extraction Operator >> (continued) ‱ Entering a char value into an int or double variable causes serious errors, called input failure
  • 8. 8 cin and the Extraction Operator >> (continued) ‱ When reading data into a char variable – >> skips leading whitespace, finds and stores only the next character – Reading stops after a single character ‱ To read data into an int or double variable – >> skips leading whitespace, reads + or - sign (if any), reads the digits (including decimal) – Reading stops on whitespace non-digit character
  • 9. 9 cin and the Extraction Operator >> (continued)
  • 11. 11 Using Predefined Functions in a Program ‱ Function (subprogram): set of instructions – When activated, it accomplishes a task ‱ main executes when a program is run ‱ Other functions execute only when called ‱ C++ includes a wealth of functions – Predefined functions are organized as a collection of libraries called header files
  • 12. 12 Using Predefined Functions in a Program (continued) ‱ Header file may contain several functions ‱ To use a predefined function, you need the name of the appropriate header file – You also need to know: ‱ Function name ‱ Number of parameters required ‱ Type of each parameter ‱ What the function is going to do
  • 13. 13 Using Predefined Functions in a Program (continued) ‱ To use pow (power), include cmath – Two numeric parameters – Syntax: pow(x,y) = xy ‱ x and y are the arguments or parameters – In pow(2,3), the parameters are 2 and 3
  • 15. 15 Using Predefined Functions in a Program (continued) Sample Run: Line 1: 2 to the power of 6 = 64 Line 4: 12.5 to the power of 3 = 1953.13 Line 5: Square root of 24 = 4.89898 Line 7: u = 181.019 Line 9: Length of str = 20
  • 16. 16 cin and the get Function ‱ The get function – Inputs next character (including whitespace) – Stores in memory location indicated by its argument ‱ The syntax of cin and the get function: varChar – Is a char variable – Is the argument (parameter) of the function
  • 17. 17 cin and the ignore Function ‱ ignore: discards a portion of the input ‱ The syntax to use the function ignore is: intExp is an integer expression chExp is a char expression ‱ If intExp is a value m, the statement says to ignore the next m characters or all characters until the character specified by chExp
  • 18. 18 putback and peek Functions ‱ putback function – Places previous character extracted by the get function from an input stream back to that stream ‱ peek function – Returns next character from the input stream – Does not remove the character from that stream
  • 19. 19 putback and peek Functions (continued) ‱ The syntax for putback: – istreamVar: an input stream variable (cin) – ch is a char variable ‱ The syntax for peek: – istreamVar: an input stream variable (cin) – ch is a char variable
  • 20. 20 The Dot Notation Between I/O Stream Variables and I/O Functions ‱ In the statement cin.get(ch); cin and get are two separate identifiers separated by a dot ‱ Dot separates the input stream variable name from the member, or function, name ‱ In C++, dot is the member access operator
  • 21. 21 Input Failure ‱ Things can go wrong during execution ‱ If input data does not match corresponding variables, program may run into problems ‱ Trying to read a letter into an int or double variable will result in an input failure ‱ If an error occurs when reading data – Input stream enters the fail state
  • 22. 22 The clear Function ‱ Once in a fail state, all further I/O statements using that stream are ignored ‱ The program continues to execute with whatever values are stored in variables – This causes incorrect results ‱ The clear function restores input stream to a working state
  • 23. Assignment ‱ Explain in detail the functioning of Input Stream Operator ‱ What do you understand by Input Failure and what is the role of clear function