Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C++ I/O: Streams, Text/Binary, Formatted I/O, Variables, Constants, Study notes of Object Oriented Programming

An overview of c++ i/o operations, including streams, text and binary, cascading input and output operators, reading and writing characters and strings, formatted i/o, and data types such as variables and constants. Topics covered include i/o classes, functions, and flags, manipulators, rules for defining variable names, static, local, instance, and final variables, and constant declaration.

Typology: Study notes

2023/2024

Uploaded on 02/01/2024

kilgaraah
kilgaraah 🇮🇳

1 document

1 / 29

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Session-2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d

Partial preview of the text

Download C++ I/O: Streams, Text/Binary, Formatted I/O, Variables, Constants and more Study notes Object Oriented Programming in PDF only on Docsity!

  • Session-

I/O Operation

Data types

Variable

Static

Constant

Pointer

Type conversion

Topics covered

Stream in C

Text Stream (^) Binary Stream

<< operator –It can use multiple times in the same line.

Its called Cascading

Cout ,Cin can cascaded

For example

cout<<“\n Enter the Marks”;

cin>> ComputerNetworks>>OODP;

Cascading of Input or Output Operators

Formatted I/O

I/O class function and flages

Manipulators

#include<iostream.h> #define PI 3. main() { cout.precision(3); cout.width(10); cout.fill(‘*’); cout<<PI; Output *****3.

Formatted Input and Output Operations

The setf() is a member function of the ios class that is used to

set flags for formatting output.

syntax -cout.setf(flag, bit-field)

Here, flag defined in the ios class specifies how the output

should be formatted and bit-field is a constant (defined in ios )

that identifies the group to which the formatting flag belongs to.

There are two types of setf()—one that takes both flag and bit-

fields and the other that takes only the flag.

Formatting with flags

• C++ has a header file iomanip.h that contains certain

manipulators to format the output

Formatting Output Using Manipulators

Data Types in C++

Variables

Local Variables Instance Variables^ Static Variables^ Constant Variables

Local variable: These are the variables which are declared within the method of a class.

Example: public class Car { public: void display(int m){ // Method int model=m; // Created a local variable model cout<<model; }

Static variables: Static variables are also called as class variables. These variables have only one copy that is shared by all the different objects in a class. Example: public class Car { public static int tyres; // Created a class variable void init(){ tyres=4; } }

Instance variable: These are the variables which are declared in a class but outside a method, constructor or any block. Example: public class Car { private: String color; // Created an instance variable color Car(String c) { color=c; }}

Constant is something that doesn't change. In C language and C++ we use the keyword const to make program elements constant. Example: const int i = 10; void f(const int i) class Test { const int i; };

CONSTANTS

Constants are identifiers whose value does not change. While

variables can change their value at any time, constants can never

change their value.

Constants are used to define fixed values such as Pi or the charge

on an electron so that their value does not get changed in the

program even by mistake.

A constant is an explicit data value specified by the programmer.

The value of the constant is known to the compiler at the compile

time.