PPT c++ Inputs and Outputs
PPT c++ Inputs and Outputs
Course Objectives
2
Course Outcomes
CO Course Outcome
Number
3
Scheme of Evaluation
4
CONTENTS
• Input and output streams
(cin, cout)
5
Input and output streams (cin, cout)
• C++ comes with libraries that provide us with many ways for
performing input and output. In C++ input and output are performed in
the form of a sequence of bytes or more commonly known as streams.
• iostream: iostream stands for standard input-output stream. This header file
contains definitions to objects like cin, cout, cerr etc.
• iomanip: iomanip stands for input output manipulators. The methods
declared in this files are used for manipulating streams. This file contains
definitions of setw, setprecision, etc.
• fstream: This header file mainly describes the file stream. This header file is
used to handle the data being read from a file as input or data being written
into the file as output.
• The two keywords cout and cin in C++ are used very often for printing
outputs and taking inputs respectively. These two are the most basic
methods of taking input and printing output in C++. To use cin and cout in C+
+ one must include the header file iostream in the program.
7
Standard output stream (cout):
• Usually the standard output device is the display screen.
• The C++ cout statement is the instance of the ostream class.
• It is used to produce output on the standard output device which is usually the
display screen.
• The data needed to be displayed on the screen is inserted in the standard output
stream (cout) using the insertion operator(<<).
• Example:
#include <iostream>
using namespace std;
int main()
{
char sample[] = "GeeksforGeeks";
cout << sample << " - A computer science portal for geeks";
return 0;
}
8
Standard input stream (cin):
• Usually the input device in a computer is the keyboard.
• C++ cin statement is the instance of the class istream and is used to read input from the
standard input device which is usually a keyboard.
• The extraction operator(>>) is used along with the object cin for reading inputs.
• The extraction operator extracts the data from the object cin which is entered using the
keyboard.
• Example:
#include <iostream>
using namespace std;
int main()
{
int age;
cout << "Enter your age:";
cin >> age;
cout << "\nYour age is: " << age;
return 0;
}
9
Summary
10
Frequently Asked question
Q1 What is the difference between structure and class?
C++ is an object oriented language that mainly focuses on objects. A class in C++ can be defined as a collection of related
variables and functions encapsulated in a single structure. Instances of the class are termed as objects. A structure in C++
can be referred to as an user defined data type possessing its own operations. Unlike in the C language, they both are quite
similar in C++. The main difference that exists between them is regarding the access modifier; the members of a class are
private by default, whereas members of a struct are public by default.
A class in C++ is just an extension of a structure used in the C language. It is a user defined data type. It actually binds the
data and its related functions in one unit. A structure and a class in C language differs a lot as a structure has limited
functionality and features as compared to a class. On the other hand, structure and class in C++ are quite similar. The main
difference arises due to the fact that by default, all the members of a class are private, whereas by default all the members of
a structure are public.
Structure is also a user defined data type with a certain template. It is generally used for grouping of logically related data
items. After the creation of a structure, the variables pertaining to the type of structure can be defined and used. A structure is
used to represent a record. In C++, a structure can have both data members and functions as classes. Many people find it
difficult to differenciate between a class and a structure. Technically they both are regarded as the same in C++.
11
Q2 What are the various I/O in C++?
Answer: C++ comes with libraries that provide us with many ways for
performing input and output. In C++ input and output are performed in
the form of a sequence of bytes or more commonly known as streams.
12
Assessment Questions:
1. What is size of void in bytes?
(A) 1
(B) 2
(C) 4
(D) 0
https://www.youtube.com/watch?v=qa960QezGDE
14
REFERENCES
TEXT BOOKS
T1 E Balagurusamy., “Object Oriented Programming in C++”, Tata McGraw-Hill.
T2 Robert Lafore, “Object Oriented Programming in C++”, Waite Group.
REFERENCE BOOKS
R1 Herbert Schildt , “C++- The Complete Reference”, Tata McGraw-Hill 2003, New Delhi.
R2 Bjarne Stroustrup: “The C++ Programming Language” (4th Edition). Addison-Wesley.
R3 Ravichandran , “Programming with C++”,Tata McGraw-Hill Education.
R4 Joyce M. Farrell,” Object Oriented Programming Using C++”, Learning.
R5 Programming Languages: Design and Implementation (4th Edition), by Terrence W.
Pratt, Marvin V. Zelkowitz, Pearson.
R6 Programming Language Pragmatics, Third Edition, by Michael L. Scott, Morgan
Kaufmann.
Websites:
1. https://www.tutorialspoint.com/What-is-the-difference-between-cin-and-cout-str
eams-in-cplusplus#:~:text=cin%20is%20an%20object%20of,They%20also%20
use%20different%20operators
.
2. https://www.geeksforgeeks.org/basic-input-output-c/
3. http://www.differencebetween.info/difference-between-class-and-structure-in-cp 15
lusplus
THANK YOU