0% found this document useful (0 votes)
29 views16 pages

PPT c++ Inputs and Outputs

The document outlines a course on Basic Data Structures using C++, focusing on input and output streams, specifically the use of 'cin' and 'cout'. It details course objectives, outcomes, and evaluation schemes, while also explaining the differences between structures and classes in C++. Additionally, it provides examples of standard input and output operations in C++ and includes assessment questions and references for further study.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views16 pages

PPT c++ Inputs and Outputs

The document outlines a course on Basic Data Structures using C++, focusing on input and output streams, specifically the use of 'cin' and 'cout'. It details course objectives, outcomes, and evaluation schemes, while also explaining the differences between structures and classes in C++. Additionally, it provides examples of standard input and output operations in C++ and includes assessment questions and references for further study.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

INSTITUTE - UIE

DEPARTMENT- ACADEMIC UNIT-2


Bachelor of Engineering (Computer Science & Engineering)
Subject Name: Basic Data Structure Using C++
Code:23CSH-103

Topic: Input and output streams DISCOVER . LEARN . EMPOWER


Basic Data Structure
Using C++

Course Objectives

• To enable the students to understand various stages and constructs


of C++ programming language.
• To improve their ability to analyze and address variety of problems
in C++.

2
Course Outcomes
CO Course Outcome
Number

CO1 Understand the concepts of object-oriented programming including


programming process and compilation process.
CO2 Apply different techniques to decompose a problem and
programmed a solution with various concepts of object-oriented
programming language.
CO3 Analyse and explain the behaviour of linear data structure
operations using the programming addressed in the course.
CO4 Implement and evaluate the programs using the syntax and
semantics of object-oriented programming.
CO5 Design the solution of real-world problems in order to determine
that the program performs as expected.

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.

• Input Stream: If the direction of flow of bytes is from the device(for


example, Keyboard) to the main memory then this process is called
input.
• Output Stream: If the direction of flow of bytes is opposite, i.e. from
main memory to device( display screen ) then this process is called
output.
6
Header files available in C++ for Input/Output operations are:

• 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

In this lecture we have We have discussed about


discussed about difference various data types in C++
between structure and class.

Moreover we have learnt


about basic i/o in c++

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.

Input Stream: If the direction of flow of bytes is from the device(for


example, Keyboard) to the main memory then this process is called
input.
Output Stream: If the direction of flow of bytes is opposite, i.e. from
main memory to device( display screen ) then this process is called
output

12
Assessment Questions:
1. What is size of void in bytes?
(A) 1
(B) 2
(C) 4
(D) 0

2. What is the size of empty class?


(A) 0
(B) 1
(C) 2
(D) 4

3. Which is not an integer data type?


(A) Single
(B) Byte
(C) Short
(D) Integer
13
Discussion forum.
A deeper dive into Data Types in C++

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

You might also like