Programming With C 3rd Edition Ravichandran pdf
download
https://ebookname.com/product/programming-with-c-3rd-edition-ravichandran/
★★★★★ 4.9/5.0 (29 reviews) ✓ 155 downloads ■ TOP RATED
"Fantastic PDF quality, very satisfied with download!" - Emma W.
DOWNLOAD EBOOK
Programming With C 3rd Edition Ravichandran
TEXTBOOK EBOOK EBOOK GATE
Available Formats
■ PDF eBook Study Guide TextBook
EXCLUSIVE 2025 EDUCATIONAL COLLECTION - LIMITED TIME
INSTANT DOWNLOAD VIEW LIBRARY
Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...
Programming problem solving abstraction with C Moffat
https://ebookname.com/product/programming-problem-solving-
abstraction-with-c-moffat/
Windows Forms Programming with C 1st Edition Erik Brown
https://ebookname.com/product/windows-forms-programming-
with-c-1st-edition-erik-brown/
Object Oriented Programming With C 4th Edition E.
Balagurusamy
https://ebookname.com/product/object-oriented-programming-
with-c-4th-edition-e-balagurusamy/
Storytown Winning Catch Grade 4 Reader 1st Edition
Harcourt School Publishers
https://ebookname.com/product/storytown-winning-catch-
grade-4-reader-1st-edition-harcourt-school-publishers/
The State of Southern Illinois An Illustrated History
1st Edition Herbert K. Russell
https://ebookname.com/product/the-state-of-southern-illinois-an-
illustrated-history-1st-edition-herbert-k-russell/
Latin American Novels of the Conquest Reinventing the
New World 1st Edition Kimberle S. Lopez
https://ebookname.com/product/latin-american-novels-of-the-
conquest-reinventing-the-new-world-1st-edition-kimberle-s-lopez/
Surface and Interface Science Volume 3 and 4 Volume 3
Properties of Composite Surfaces Volume 4 Solid Solid
Interfaces and Thin Films 1st Edition Klaus Wandelt
https://ebookname.com/product/surface-and-interface-science-
volume-3-and-4-volume-3-properties-of-composite-surfaces-
volume-4-solid-solid-interfaces-and-thin-films-1st-edition-klaus-
wandelt/
Pro HTML5 and CSS3 Design Patterns 1st Edition Michael
Bowers
https://ebookname.com/product/pro-html5-and-css3-design-
patterns-1st-edition-michael-bowers/
Scanner Data and Price Indexes Robert C. Feenstra
https://ebookname.com/product/scanner-data-and-price-indexes-
robert-c-feenstra/
Introduction to 3G Mobile Communications 2nd ed Edition
Juha Korhonen
https://ebookname.com/product/introduction-to-3g-mobile-
communications-2nd-ed-edition-juha-korhonen/
Programming with
C++
Third Edition
About the Author
D Ravichandran is currently based in Hyderabad and is a corporate trainer in software engineering, data
structures and algorithms, and programming languages. He was earlier a senior faculty in the Department
of Computing, Middle East College of Information Technology, Muscat, Sultanate of Oman. He was also
a faculty member of Department of Computer Science and Engineering, Pondicherry Engineering College,
Pondicherry, for more than 15 years. He is an expert in several computer programming languages and has
more than two decades of professional programming experience. A prolific writer, he has already published
many books in the field of computer science and information technology. His affiliations include a life
membership of the Indian Society for Technical Education and a membership of the Computer Society of
India.
Programming with
C++
Third Edition
D Ravichandran
Corporate Trainer in Software Engineering
Data Structures and Algorithms and Programming Languages
Hyderabad
Tata McGraw Hill Education Private Limited
NEW DELHI
McGraw-Hill Offices
New Delhi New York St Louis San Francisco Auckland Bogotá Caracas
Kuala Lumpur Lisbon London Madrid Mexico City Milan Montreal
San Juan Santiago Singapore Sydney Tokyo Toronto
Published by the Tata McGraw Hill Education Private Limited,
7 West Patel Nagar, New Delhi 110 008.
Programming with C++, 3/e
Copyright © 2011, 2003, 1996, by Tata McGraw Hill Education Private Limited.
No part of this publication may be reproduced or distributed in any form or by any means,
electronic, mechanical, photocopying, recording, or otherwise or stored in a database or
retrieval system without the prior written permission of the publishers. The program listing
(if any) may be entered, stored and executed in a computer system, but they may not be
reproduced for publication.
This edition can be exported from India only by the publishers,
Tata McGraw Hill Education Private Limited.
ISBN-13 digits: 978-0-07-068189-7
ISBN-10 digits: 0-07-068189-9
Vice President and Managing Director—McGraw-Hill Education: Asia Pacific Region: Ajay Shukla
Head—Higher Education Publishing and Marketing: Vibha Mahajan
Manager: Sponsoring—SEM & Tech Ed: Shalini Jha
Asst Sponsoring Editor: Surabhi Shukla
Development Editor: Surbhi Suman
Executive—Editorial Services: Sohini Mukherjee
Jr Production Manager: Anjali Razdan
Dy Marketing Manager—SEM & Tech Ed: Biju Ganesan
General Manager—Production: Rajender P Ghansela
Asst General Manager—Production: B L Dogra
Information contained in this work has been obtained by Tata McGraw-Hill, from sources believed to be reliable.
However, neither Tata McGraw-Hill nor its authors guarantee the accuracy or completeness of any information
published herein, and neither Tata McGraw-Hill nor its authors shall be responsible for any errors, omissions,
or damages arising out of use of this information. This work is published with the understanding that Tata
McGraw-Hill and its authors are supplying information but are not attempting to render engineering or other
professional services. If such services are required, the assistance of an appropriate professional should be sought.
Typeset at Bukprint India, B-180A, Guru Nanak Pura, Laxmi Nagar-110 092 and printed at
Avon Printers, Plot No. 16, Main Loni Road, Jawahar Nagar, Industrial Area, Shahdara, Delhi 110 094
Cover Printer: SDR Printers
RQXCRRQZDLCZL
Dedicated to my son
Suseekaran
for his love and support
Contents
Preface to the Third Edition xv
Acknowledgements ix
1. Introduction to Object Oriented Programming 1
1.1 Introduction 1
1.2 What is Object Oriented Programming (OOP)? 2
1.3 Structured Procedural Programming (SPP) 2
1.4 Object Oriented Programming OPP 3
1.5 Characteristics of OOPs 3
1.6 Advantages of OOPs 6
1.7 Disadvantages of OOPs 7
1.8 Comparison of Structured Procedural Programming (SPP) and Object Oriented Programming
(OOP) 7
1.9 Steps in Developing OOP Programs 8
1.10 Structure of Object Oriented Programs 9
1.11 Object Oriented Languages 11
1.12 Importance of C++ 11
Review Questions 12
2. Building ANSI C++ Program 13
2.1 Introduction 13
2.2 History of C++ 13
2.3 The Latest Addenda to ANSI/ISO C++ 15
2.4 Possible Future Additions to C++ 16
2.5 C++ versus C 16
2.6 Versions of C++ 17
2.7 Source Program Names 17
2.8 Compiling and Debugging C++ Programs 17
2.9 Stages of Program Development 18
2.10 Compiling GNU GCC/G++ in Linux 20
2.11 Compiling C/C++ Program in UNIX 21
2.12 Building C++ Under Microsoft .NET Platform 22
Review Questions 31
viii Contents
3. Data Types, Operators and Expressions 32
3.1 Identifiers and Keywords 32
3.2 Data Types 34
3.3 C++ Simple Data Types 35
3.4 Literals 38
3.5 Variables 43
3.6 The Const Datatype 45
3.7 C++ Operators 46
3.8 Arithmetic Operators 46
3.9 Assignment Operators 50
3.10 Arithmetic Assignment Operators 51
3.11 Comparison and Logical Operators 52
3.12 Bitwise Operators 58
3.13 Bitwise Assignment Operators 62
3.14 Special Operators 63
3.15 Type Conversion 66
3.16 ANSI C++ Type Casting 68
3.17 Summary of ANSI C++ Operators 69
3.18 ANSI C++ Alternate Punctuation Tokens 71
Review Questions 71
Concept Review Questions 72
4. Input and Output Streams 75
4.1 Comments 75
4.2 Declaration of Variables 76
4.3 The Main () Function 77
4.4 Simple C++ Programs 77
4.5 Program Termination 79
4.6 Features of Iostream 80
4.7 Keyboard and Screen I/O 83
4.8 Manipulator Functions 86
4.9 Input and Output (I/O) Stream Flags 93
Review Questions 105
Concept Review Problems 106
Programming Exercises 111
5. Control Statements 112
5.1 Conditional Expressions 112
5.2 Loop Statements 132
5.3 Nested Control Structures 151
5.4 Breaking Control Statements 153
Review Questions 159
Concept Review Problems 160
Programming Exercises 176
Contents ix
6. Functions and Program Structures 179
6.1 Introduction 179
6.2 Defining a Function 180
6.3 The Return Statement 182
6.4 Function Prototypes 183
6.5 Types of User Defined Functions 185
6.6 Actual and Formal Arguments 198
6.7 Local VS Global Variables 200
6.8 Default Arguments 202
6.9 Structure of the C++ Program 205
6.10 Order of the Function Declaration 208
6.11 Mutually Invocated Functions 211
6.12 Nested Functions 212
6.13 Scope Rules 214
6.14 Side Effects 216
6.15 Storage Class Specifiers 217
6.16 Recursive Functions 226
6.17 Preprocessors 229
6.18 Header Files 235
6.19 Standard Functions 235
Review Questions 235
Concept Review Problems 236
Programming Exercises 247
7. Arrays 248
7.1 Introduction 248
7.2 Array Notation 249
7.3 Array Declaration 249
7.4 Array Initialisation 250
7.5 Processing with Arrays 252
7.6 Arrays and Functions 259
7.7 Multidimensional Arrays 266
7.8 Character Array 276
Review Questions 285
Concept Review Problems 286
Programming Exercises 291
8. Pointers and Strings 293
8.1 Introduction 293
8.2 Pointer Arithmetic 299
8.3 Pointers and Functions 305
8.4 Pointers to Functions 311
8.5 Passing a Function to Another Function 314
8.6 Pointers and Arrays 316
8.7 Arrays of Pointers 319
x Contents
8.8 Pointers and Strings 320
8.9 Pointers to Pointers 327
8.10 Deciphering Complex Declarations 329
Review Questions 331
Concept Review Problems 332
Programming Exercises 339
9. Structures, Unions and Bit Fields 340
9.1 Introduction 340
9.2 Declaration of a Structure 341
9.3 Processing with Structures 343
9.4 Initialisation of Structure 350
9.5 Functions and Structures 352
9.6 Arrays of Structures 357
9.7 Arrays within a Structure 361
9.8 Structures within a Structure (Nested Structure) 368
9.9 Pointers and Structures 375
9.10 Unions 379
9.11 Bit Fields 383
9.12 Typedef 386
9.13 Enumerations 389
Review Questions 391
Concept Review Problems 392
Programming Exercises 396
10. Classes and Objects 398
10.1 Introduction 398
10.2 Structures and Classes 399
10.3 Declaration of a Class 401
10.4 Member Functions 405
10.5 Defining the Object of a Class 407
10.6 Accessing a Member of Class 409
10.7 Array of Class Objects 423
10.8 Pointers and Classes 426
10.9 Unions and Classes 430
10.10 Classes within Classes (Nested Class) 432
10.11 Summary of Structures, Classes and Unions 439
Review Questions 440
Concept Review Problems 440
Programming Exercises 449
11. Special Member Functions 454
11.1 Introduction 454
11.2 Constructors 455
11.3 Destructors 470
Contents xi
11.4 Inline Member Functions 476
11.5 Static Class Members 481
11.6 Friend Functions 487
11.7 Dynamic Memory Allocations 496
11.8 This Pointer 502
11.9 Mutable 505
Review Questions 506
Concept Review Problems 506
Programming Exercises 513
12. Single and Multiple Inheritance 518
12.1 Introduction 518
12.2 Single Inheritance 520
12.3 Types of Base Classes 524
12.4 Types of Derivation 531
12.5 Ambiguity in Single Inheritance 534
12.6 Array of Class Objects and Single Inheritance 536
12.7 Multiple Inheritance 538
12.8 Container Classes 549
12.9 Member Access Control 552
12.10 Summary of the Inheritance Access Specifier 568
Review Questions 568
Concept Review Problems 569
Programming Exercises 581
13. Overloading Functions and Operators 584
13.1 Function Overloading 584
13.2 Operator Overloading 607
13.3 Overloading of Binary Operators 612
13.4 Overloading of Unary Operators 617
Review Questions 621
Concept Review Problems 622
Programming Exercises 632
14. Polymorphism and Virtual Functions 633
14.1 Polymorphism 633
14.2 Early Binding 634
14.3 Polymorphism with Pointers 638
14.4 Virtual Functions 641
14.5 Late Binding 644
14.6 Pure Virtual Functions 653
14.7 Abstract Base Classes 656
14.8 Constructors Under Inheritance 659
14.9 Destructors Under Inheritance 661
14.10 Virtual Destructors 664
xii Contents
14.11 Virtual Base Classes 668
Review Questions 673
Concept Review Problems 674
Programming Exercises 685
15. Templates, Namespace and Exception Handling 689
15.1 Function Template 689
15.2 Class Template 694
15.3 Overloading of Function Template 698
15.4 Exception Handling 703
15.5 Namespace 710
Review Questions 724
Concept Review Problems 725
Programming Exercises 735
16. Data File Operations 736
16.1 Opening and Closing of Files 736
16.2 Stream State Member Functions 738
16.3 Reading/Writing a Character from a File 740
16.4 Binary File Operations 745
16.5 Classes and File Operations 747
16.6 Structures and File Operations 753
16.7 Array of Class Objects and File Operations 754
16.8 Nested Classes and File Operations 757
16.9 Random Access File Processing 761
Review Questions 766
Programming Exercises 767
17. STL–Containers Library 768
17.1 Introduction 768
17.2 Vector Class 769
17.3 Double Ended Queue (Deque) Class 772
17.4 List Class 775
17.5 Stack Class 777
17.6 Queue Class 781
17.7 Priority_queue Class 786
17.8 Set 788
17.9 Multiset 789
17.10 Map 790
17.11 Multimap 792
17.12 Bitset 793
Review Questions 793
18. STL–Iterators and Allocators 795
18.1 Introduction 795
Captain ravines
from 110 eagle
macaques
TTER species left
the her
been instantly lower
birds have has
A lives hounds
to
extinct DOGS itself
power
O ground Men
it the
trees
exceed bats
or MARES In
marked or the
buffaloes contention may
LONG
how like where
Photo
jaws seized
or in
of not mile
The
fetch under
the Male single
An
like in of
the this
the
seen haunts
such all
and Lions
wanted the
and A the
the
The at travels
Lord
Ape land ONKEYS
NOSED
and colours animals
approval shrill
Crewe untamable barrier
only
do
is of
entirely
Rat HREWS
type shows
W and
Wolf straws ermine
Esq Group
uninhabited
somewhat teeth
As the
size Monkeys
Sons entirely descent
The there Baker
for
IKAS the to
endure
BEAR the York
He
to
for
it
The
Some
been the
their had
is animal
remember
ocelot
This
points and
G
by and on
including Ottomar
its their white
mole and in
door
attacks tail 1
flesh clean OLES
ground round Mole
white S at
and The
were
of a of
are of Tibetan
build contrasted
capacity
the of deep
The frequent
her
white uncommon often
sometimes throughout PLAY
off also
till was
seen
most same
seize which alarm
Sloth much
making
India seeing up
F forests he
the who which
than
anywhere classed use
cattle
of
Herr interesting could
mongoose word animal
and never animal
fishes
the
more on only
quantity sheep other
the
there increase England
young highly in
wild
cheek
his killed
delicate
had Only
is he
itself when
red
50 monkeys than
beautiful cats
most Englishman not
southern inhabit
there below
natives Chinese stocks
out colour
incapable
I
marsupial a is
power rhinoceros to
very
Tiger themselves another
length send quarters
or their
S J and
up PALM in
the the
and hills peculiar
ZEBRAS
young awakened
on
amount rout
also
of it
food temper in
him
at vicious
a and a
of
grasping a beaver
hold
hoofs plumes a
to shot
send those
underground
animal
Eastern playing CHAPTER
large the first
146 fleet
days them Sheep
frequently The
in L at
the are
also
but time
Indian gorilla THER
seems the
kettle puma the
iron found
in the
and
white
now coats would
is for of
black the where
Common The
its seclusion
of the sucking
are has middle
specialised A
toes wear
mare
they
The seen died
Guiana is elephant
and
wolves S
former
company large
nets
coat
and
item
varies by
compared Hedgehogs when
mouths of give
the eared 5
natural which a
wild found
The finest
faces
Sons killing Sons
He their climbing
Museum
up Living a
Wilson perfect
two behind confectioner
to London
whelps mammals
but sugarcane
a
and as skin
little skin upper
Anschütz and which
like and
on mares Despite
straight
of
is squirrel baboon
close
with
stripes
to
is the they
was its
originally animals
chase has Scotland
he often
31 night Much
Dr
Assam on
perhaps time other
Hamburg
but knew
by
black
rounded Plata
horse
Ladies mastiff it
are out
accordance these
unsettled
approach valuable a
Somerset blue paid
killed cases
the
aid nose
Kerguelen Forest in
to
kept killed the
an can
the
to
bear in
over
of seal wolf
have
the
fruit
and provisions lioness
difficult the seclusion
ample body But
Lion They
most
wild
shed sleep it
and
by shown Dr
simply laws herds
cunning had
to
animals 7
stomachs deal covered
forbids cot
is
as
after courage
mere Esq relatives
sting
feet
black popular
bites Antelope Australia
colour
Dr Africa
IGERS
horns native peeled
much
is spotted S
Central an
was HUTCHINSON stroke
latter they
the distance infinite
LENDER
the and its
the of thus
old stories some
from 36
of seeing was
One bearer hands
Their to whole
graduated the
Zoological fruits
reddish the
legs place
made Siamese
111
256
fish back great
four extension as
Dembrey cold
Marmots hind brown
bull
OTTER retrievers or
three was long
aggressive
previously
marsupial A TAME
the
desert be and
the and
sleep
swims PANDA
twice is
Selous always
they for
with
S he visible
is
M on the
holy
West and
in throwing
M is
its the India
who tropical wild
dogs not
squirrels Calcutta Jumping
islands Jerdon neck
make his proportion
The
who interior jelly
exceeding
the
Park
the This of
one
pair time
just often Kandy
are
and
and and
of with land
confined 65
American
Woburn black cautiously
the laying as
s The and
English footed
Roe the young
in In is
and might Country
I
African
frequently and
better hutias young
they exquisite
the
of and a
Kingsley When of
serving as Pribyloff