This document discusses console I/O operations in C++. It covers C++ stream classes that implement input and output operations, unformatted I/O using operators and functions, and formatted I/O using stream manipulators and member functions. The key stream classes are istream for input and ostream for output. Unformatted I/O uses operators like >> and << while formatted I/O uses width(), precision(), and fill() functions as well as custom manipulators.
Constructors are special class functions which performs initialization of every object. The Compiler calls the Constructor whenever an object is created. Destructor on the other hand is used to destroy the class object.
Everything about OOPs (Object-oriented programming) in this slide we cover the all details about object-oriented programming using C++. we also discussed why C++ is called a subset of C.
Constructors, Destructors, call in parameterized Constructor, Multiple constructor in a class, Explicit/implicit call, Copy constructor, Dynamic Constructors and call in parameterized Constructor
Constructors are special class functions which performs initialization of every object. The Compiler calls the Constructor whenever an object is created. Destructor on the other hand is used to destroy the class object.
Everything about OOPs (Object-oriented programming) in this slide we cover the all details about object-oriented programming using C++. we also discussed why C++ is called a subset of C.
Constructors, Destructors, call in parameterized Constructor, Multiple constructor in a class, Explicit/implicit call, Copy constructor, Dynamic Constructors and call in parameterized Constructor
This Powerpoint presentation covers following topics of C Plus Plus:
Features of OOP
Classes in C++
Objects & Creating the Objects
Constructors & Destructors
Friend Functions & Classes
Static data members & functions
This is an overview of C++ (based on 1999 / 2003 standard) and its use in Object Oriented Programming. The presentation assumes that the audience knows C programming.
INTRODUCTION
COMPARISON BETWEEN NORMAL FUNCTION AND INLINE FUNCTION
PROS AND CONS
WHY WHEN AND HOW TO USED?
GENERAL STRUCTURE OF INLINE FUNCTION
EXAMPLE WITH PROGRAM CODE
Command-line arguments are given after the name of the program in command-line shell of Operating Systems.
To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.
This Powerpoint presentation covers following topics of C Plus Plus:
Features of OOP
Classes in C++
Objects & Creating the Objects
Constructors & Destructors
Friend Functions & Classes
Static data members & functions
This is an overview of C++ (based on 1999 / 2003 standard) and its use in Object Oriented Programming. The presentation assumes that the audience knows C programming.
INTRODUCTION
COMPARISON BETWEEN NORMAL FUNCTION AND INLINE FUNCTION
PROS AND CONS
WHY WHEN AND HOW TO USED?
GENERAL STRUCTURE OF INLINE FUNCTION
EXAMPLE WITH PROGRAM CODE
Command-line arguments are given after the name of the program in command-line shell of Operating Systems.
To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.
This is an intermediate conversion course for C++, suitable for second year computing students who may have learned Java or another language in first year.
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
The slides from the C++ and OOPS Crash Course conducted for ACM DBIT by Grejo Joby.
Learn the concepts of OOPS and C++ Programming in the shortest time with these notes.
Complete C++ Program Pdf......As because this document does not contain any theory so kindly feel free to ask if have any doubt or problem.
Happy to help. Thanks
File operations refer to the various actions you can perform on files in a computer system. These operations typically include reading from and writing to files, as well as managing and manipulating file-related information. File operations are crucial for tasks like data storage, retrieval, and data processing in software development. Here are some common file operations:
File Creation: Creating a new file involves specifying a file name and, in some cases, a file extension. You can create files in different formats, such as text files, binary files, or specific file types like images or documents.
File Opening and Closing: To work with a file, you need to open it using the appropriate file handle. After you've finished with the file, you should close it to release system resources and ensure data integrity.
Reading from Files: Reading from a file allows you to retrieve data stored in the file. You can read files line by line or in chunks, depending on your needs. Reading can be done in text mode or binary mode, depending on the file's content.
Writing to Files: Writing to a file allows you to save data to the file. You can write text, binary data, or structured data like JSON or XML to files. You can also append data to an existing file or create a new one.
File I/O Modes: Files can be opened in various modes, such as read mode, write mode, append mode, binary mode, and more. These modes specify the intended operations you can perform on the file.
File Manipulation: File operations also include manipulating files, such as renaming, moving, copying, and deleting files. These operations are essential for file management and organization.
File Positioning: You can move the file pointer to a specific location within the file, allowing you to read or write data from a particular position.
Error Handling: Handling errors is crucial in file operations. You need to check for errors and exceptions that may occur during file operations, such as file not found, permission denied, or disk full errors.
Metadata and Attributes: You can access and modify file metadata and attributes, such as file size, timestamps (creation, modification), and file permissions.
Serialization and Deserialization: These operations involve converting complex data structures or objects into a format that can be stored in a file (serialization) and then retrieving and reconstructing the data from the file (deserialization).
File operations are available in various programming languages, and each language may provide its own set of functions and libraries for handling files. Proper file handling and error management are essential to ensure data integrity and security in software applications.
Introduce Brainf*ck, another Turing complete programming language. Then, try to implement the following from scratch: Interpreter, Compiler [x86_64 and ARM], and JIT Compiler.
I prepared these slides for the student of FSC BSC BS Computer science.these slides are very easily understanding the concept of programming in C++.All topics are clear with the help of examples easy in reading the topic and understanding the logic.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
2. Contents
• 10.1 C++ Streams, C++ Stream Classes
• 10.2 Unformatted I/O Operation
• 10.3 Formatted I/O Operation
• 10.4 Managing Output with Manipulators
2By:-Gourav Kottawar
3. Managing Console I/O
Operations
• C++ uses the concept of stream and
stream classes to implement its I/O
operations with the console and disk
files.
• C++ support all of C’s rich set of I/O
functions.
3By:-Gourav Kottawar
4. C ++ Stream
• Stream is an interface supplied by the
I/O system of C++ between the
programmer and the actual device
being accessed.
• It will work with devices like
terminals, disks and tape drives.
• A stream is a sequence of bytes.
• It acts either as a source from which
the input data can be obtained or as a
destination to which the output data
can be sent. 4By:-Gourav Kottawar
5. C ++ Stream
• Input Stream - The source stream that
provides data to the program.
• Output Stream - The destination stream
that receives output from the program.
continue…
Input device
Output device
Program
Input Stream
Output Stream
Extraction from
input stream
Insertion into
output stream
5By:-Gourav Kottawar
6. C ++ Stream
• The data in the input stream can
come from keyboard or any other
storage device.
• The data in the output stream can go to the
screen or any other storage device.
continue…
Input device
Output device
Program
Input Stream
Output Stream
Extraction from
input stream
Insertion into
output stream
6By:-Gourav Kottawar
7. C ++ Stream Classes
• The C++ I/O system contains a
hierarchy of classes that are used to
define various streams to deal with
both the console and disk files.
• These classes are called stream
classes.
• These classes are declared in the
header file iostream. 7By:-Gourav Kottawar
9. C ++ Stream Classes
ios
istream ostreamstreambuf
iostream
istream_withassign iostream_withassign ostream_withassign
continue…
Provides the basic
support for formatted
and unformatted I/O
operations.
Provides the facilities
for formatted and
unformatted input
Provides the
facilities for
formatted output
Provides the facilities
for handling both input
and output streams.
9By:-Gourav Kottawar
10. Unformatted I/O Operations
Overloaded Operators >> and <<
• The objects cin and cout are used for input
and output of data of various types.
• By overloading the operators >> and <<.
• >> operator is overloaded in the istream
class.
• << operator is overloaded in the ostream
class.
• This is used for input data through
keyboard.
10By:-Gourav Kottawar
11. Unformatted I/O Operations
Overloaded Operators >> and <<
cin >> variable1 >> varibale2 ... >> variableN
where variable1, variable2, …, variableN are valid C+
+ variable names.
cout << item1 << item2 << … << itemN
Where item1, item2, …,itemN may be variables or
constants of an basic type.
11By:-Gourav Kottawar
12. Unformatted I/O Operations
put( ) and get( ) Functions
• get( ) and put( ) are member functions of
istream and ostream classes.
• For single character input/output
operations.
• There are two types of get( ) functions:
– get(char*) Assigns the input character to its argument.
– get(void) Returns the input character.
• char c; cin.get(c) c = cin.get( );
– put( ) used to output a line of text, character
by character.
• char c; cout.put(‘x’); cout.put(c);
12By:-Gourav Kottawar
13. #include<iostream.h>
int main()
{
int i =0;
char ch;
cout<<“n Enter data”;
cin.get(ch);
while(ch!=‘n’)
{
cout.put(ch);
i++;
cin.get(ch);
}
cout<<“n Number of characters =“<<I;
}
13By:-Gourav Kottawar
14. #include<iostream.h>
int main()
{
int i =0;
char ch;
cout<<“n Enter data :”;
cin.get(ch);
while(ch!=‘n’)
{
cout.put(ch);
i++;
cin.get(ch);
}
cout<<“n Number of characters =“<<I;
}
Output :
Enter data : Applying thought
Applying thoughts
Number of characters : 17
14By:-Gourav Kottawar
15. Unformatted I/O Operations
getline( ) and write( ) Functions
• getline( ) function reads a whole line of text
that ends with a newline character.
• cin.getline(line, size);
• Reading is terminated as soon as either the
newline character ‘n’ is encountered or
size-1 characters are read.
• write( ) function displays an entire line of
text.
• cout.write(line, size);
• write( ) also used to concatenate strings.
15By:-Gourav Kottawar
16. #include<iostream.h>
int size = 10;
int main()
{
char name[10];
cout<<“n Can I know u r name :”;
cin>>name;
cout<<“Name : “<<name;
cout<<“n Come again :”;
cin.getline(name,size);
cout<<“Name :- “<<name;
}
16By:-Gourav Kottawar
18. Formatted Console I/O
Operations
C++ supports a number of features that
could be used for formatting the output.
These features include:
–ios class functions and flags.
– Manipulators.
– User-defined output functions.
18By:-Gourav Kottawar
19. ios member functions
width( ) to specify the required field size for
displaying an output value.
precision( ) to specify the number of digits to be
displayed after the decimal point of a float value.
fill( ) to specify a character that is used to fill the
unused portion of a field.
setf( ) to specify format flags that can control the
form of output display.
unsetf( ) to clear the flags specified.
19By:-Gourav Kottawar
25. Manipulators
Manipulators are special functions that can
be included in the I/O statement to alter
the format parameters of a stream.
To access manipulators, the file iomanip.h
should be included in the program.
– setw( )
– setprecision( )
– setfill( )
– setiosflags( )
– resetiosflags( )
25By:-Gourav Kottawar
26. width( ) Defining Field Width
To define the width of a field necessary for
the output of an item.
Since it is a member function, we have to use
an object to invoke it.
cout.width(w)
Where w is the field width (number of
columns).
The output will be printed in a field of w
characters wide at the right end of the field.
26By:-Gourav Kottawar
27. width( ) Defining Field Width
The width( ) function can specify the
field width for only one item – item
that follows immediately.
cout.width(5);
cout << 543 << 12 <<“n”;
cout.width(5);
cout << 543;
cout.width(5);
cout << 12 << “n”;
5 4 3 1 2
5 4 3 1 2
The field should be specified
for each item separately.
27By:-Gourav Kottawar
28. precision( ) Setting Precision
• Used to specify the number of digits to be
displayed after the decimal point while printing the
floating-point numbers.
• By default, the floating numbers are printed with six
digits after the decimal point.
• cout.precision(d);
– Where d is the number of digits to the right of the decimal
point.
cout.precision(3);
cout << sqrt(2) << endl;
cout << 3.14159 << endl;
cout <<2.50032 << endl;
1.141 truncated
3.142 rounded
2.5 o trailing zeros
28By:-Gourav Kottawar
29. precision( ) Setting Precision
• Unlike width( ), precision ( ) retains the setting
in effect until it is reset.
• We can also combine the field specification
with the precision setting.
cout.precision(2);
cout.width(5);
cout << 1.2345;
1 . 2 3
29By:-Gourav Kottawar
30. fill( ) Filling and Padding
• When printing values with larger field width
than required by the values, the unused
positions of the field are filled with white
spaces, by default.
• fill( ) function can be used to fill the unused
positions by any desired character.
cout.fill(ch);
where ch represents the character which is
used for filling the unused positions.
cout.fill(‘ * ’);
cout.wdith(10);
cout << 5250 << endl;
* * * * * 5 05 2*
Like precision( ), fill( ) stays
in effect till we change it.
30By:-Gourav Kottawar
31. setf( ) Formatting Flags, Bit-
fields
• When the function width( ) is used, the value
will be printed right-justified in the created
width.
• setf( )function is used to print values in left-
justified.
• cout.setf(arg1, arg2)
eg:
cout.fill(‘ * ’);
cout.setf(ios :: left, ios :: adjustfield);
cout.wdith(10);
cout << “TABLE 1” << endl;
T A B L E * *1 *
arg1 is formatting flags
defined in the class ios and
arg2 is bit field constant in
the ios class.
31By:-Gourav Kottawar
32. setf( ) Formatting Flags,
Bit-fields
• When the function width( ) is used, the value
will be printed right-justified in the created
width.
• setf( )function is used to print values in left-
justified.
• cout.setf(arg1, arg2)
eg:
cout.fill(‘ * ’);
cout.setf(ios :: left, ios :: adjustfield);
cout.wdith(10);
cout << “TABLE 1” << endl;
T A B L E * *1 *
arg1 is formatting flags
defined in the class ios and
arg2 is bit field constant in
the ios class.
The formatting flag
specifies the format action
required for the output.
Bit field specifies the
group to which the
formatting flag belongs.
32By:-Gourav Kottawar
33. Managing Output with Manipulators
• The header file iomanip provides a set of
functions called manipulators which can be
used to manipulate the output formats.
• Some manipulators are more convenient to
use than the member functions and flags of
ios.
• Two or more manipulators can be used as a
chain in one statement.
cout << manip1 << manip2 << maip3 << item;
cout << manip1 << item1 << manip2 << item2;
33By:-Gourav Kottawar
34. Managing Output with Manipulators
• Manipulators and their meanings
cout << setw(5) << setprecision(2) << 1.2345
<< setw(10) << setprecision(4) << sqrt(2);
• We can jointly use the manipulators and the ios
functions in a program.
Manipulators Meaning Equivalent
setw(int w) Set the field width to w width( )
setprecision(int d) Set floating point precision to d precision( )
setfill( int c) Set the fill character to c fill( )
34By:-Gourav Kottawar
35. Manipulators & ios Member
Functions
• The ios member function return the previous
format state which can be used later.
• But the manipulator does not return the
previous format state.
cout.precision(2); // previous state.
int p =cout.precision(4); // current state, p=2.
cout.precision(p); // change to previous state
35By:-Gourav Kottawar
36. Designing Our Own Manipulators
• We can design our own manipulators for
certain special purposes.
ostream & manipulator ( ostream & output)
{
……… (code)
return output;
}
ostream & unit (ostream & output)
{
output << “inches”;
return output;
}
cout << 36 << unit; will produce “36 inches”.
36By:-Gourav Kottawar
37. Designing Our Own Manipulators
We can also create manipulators that could
represent a sequence of operations:
ostream & show (ostream & output)
{
output.setf(ios::showpoint);
output.setf(ios::showpos);
output << setw(10);
return output;
}
This function defines a manipulator called show that turns
on the flags showpoint and showpos declared in the class
ios and sets the field width to 10.
37By:-Gourav Kottawar