Visit https://ebookgate.com to download the full version and
explore more ebooks
Programming in C 2nd Edition Safari
_____ Click the link below to download _____
https://ebookgate.com/product/programming-in-c-2nd-
edition-safari/
Explore and download more ebooks at ebookgate.com
Here are some recommended products that might interest you.
You can download now and explore!
Programming with ANSI C 2nd ed Edition Trivedi
https://ebookgate.com/product/programming-with-ansi-c-2nd-ed-edition-
trivedi/
ebookgate.com
C for business programming 2nd ed Edition Molluzzo
https://ebookgate.com/product/c-for-business-programming-2nd-ed-
edition-molluzzo/
ebookgate.com
Programming Principles and Practices using C 2nd Edition
Bjarne Stroustrup
https://ebookgate.com/product/programming-principles-and-practices-
using-c-2nd-edition-bjarne-stroustrup/
ebookgate.com
Programming in Objective C 4th Edition Stephen Kochan
https://ebookgate.com/product/programming-in-objective-c-4th-edition-
stephen-kochan/
ebookgate.com
Programming in ANSI C 6th Edition E. Balagurusamy
https://ebookgate.com/product/programming-in-ansi-c-6th-edition-e-
balagurusamy/
ebookgate.com
Programming in Scala 2nd 2nd Edition Martin Odersky
https://ebookgate.com/product/programming-in-scala-2nd-2nd-edition-
martin-odersky/
ebookgate.com
Mobile Computing 1st edition Edition Safari
https://ebookgate.com/product/mobile-computing-1st-edition-edition-
safari/
ebookgate.com
Separation Process Engineering Second Edition Safari
https://ebookgate.com/product/separation-process-engineering-second-
edition-safari/
ebookgate.com
Programming in Java 2nd edition Edition Choudhary
https://ebookgate.com/product/programming-in-java-2nd-edition-edition-
choudhary/
ebookgate.com
Programming in C++
Second Edition
Ashok Namdev Kamthane
Associate Professor
Department of Electronics and Telecommunication Engineering
Shri Guru Gobind Singhji
Institute of Engineering and Technology
Nanded, Maharashtra
Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd.
Licensees of Pearson Education in South Asia
No part of this eBook may be used or reproduced in any manner whatsoever without the publisher’s
prior written consent.
This eBook may or may not include all assets that were part of the print version. The publisher
reserves the right to remove any material in this eBook at any time.
ISBN 9788131791448
eISBN 9789332520288
Head Office: A-8(A), Sector 62, Knowledge Boulevard, 7th Floor, NOIDA 201 309, India
Registered Office: 11 Local Shopping Centre, Panchsheel Park, New Delhi 110 017, India
PrEfAcE xv
About thE Author xvii
1. iNtroductioN to c++ 1
2. bASicS of c++ 21
3. iNPut ANd outPut iN c++ 33
4. c++ dEclArAtioNS 99
5. dEciSioN StAtEmENtS 161
6. coNtrol looP StructurES 187
7. fuNctioNS iN c++ 203
8. clASSES ANd objEctS 257
9. coNStructorS ANd dEStructorS 345
10. oPErAtor ovErloAdiNg ANd tyPE coNvErSioN 395
11. iNhEritANcE 441
12. ArrAyS 511
Brief Contents
iv Brief Contents
13. PoiNtErS 531
14. c++ ANd mEmory modElS 577
15. biNdiNg, PolymorPhiSmS, ANd virtuAl fuNctioNS 603
16. APPlicAtioNS with filES 639
17. gENEric ProgrAmmiNg with tEmPlAtES 697
18. worKiNg with StriNgS 731
19. ExcEPtioN hANdliNg 759
20. ovErviEw of StANdArd tEmPlAtE librAry 785
21. AdditioNAl iNformAtioN About ANSi ANd turbo-c++ 817
22. c++ grAPhicS 843
APPENdicES 869
iNdEx 879
Preface xv
About the Author xvii
1. iNtroductioN to c++ 1
1.1 Differences between C and C++ 1
1.2 Evolution of C++ 2
1.3 The ANSI Standard 2
1.4 The Object Oriented Technology 2
1.5 Disadvantage of Conventional Programming 4
1.6 Programming Paradigms 5
1.7 Preface to Object Oriented Programming 6
1.8 Key Concepts of Object Oriented Programming 7
1.9 Advantages of OOP 15
1.10 Object Oriented Languages 16
1.11 Usage of OOP 17
1.12 Usage of C++ 18
Summary 18
Exercises 19
2. bASicS of c++ 21
2.1 Introduction 21
2.2 Steps to Create and Execute a C++ Program 21
2.3 Flowchart for Creating a Source File, Compiling, Linking
and Executing in C++ 22
2.4 C++ Environments 23
2.5 Typical C++ Environment (Borland C++) 24
2.6 Structure of a C++ Program 27
2.7 Illustrative Simple Program in C++ without Class 28
2.8 Header Files and Libraries 29
Summary 30
Exercises 31
Contents
vi Contents
3. iNPut ANd outPut iN c++ 33
3.1 Introduction 33
3.2 Streams in C++ and Stream Classes 34
3.3 Pre-defined Streams 34
3.4 Buffering 35
3.5 Stream Classes 36
3.6 Formatted and Unformatted Data 37
3.7 Unformatted Console I/O Operations 38
3.8 Type Casting with the cout Statement 44
3.9 Member Functions of the istream Class 56
3.10 Formatted Console I/O Operations 59
3.11 Bit Fields 67
3.12 Flags without Bit Fields 70
3.13 Manipulators 71
3.14 User-defined Manipulators 74
3.15 Manipulator with One Parameter 76
3.16 Manipulators with Multiple Parameters 77
3.17 More Programs 79
Summary 87
Exercises 88
4. c++ dEclArAtioNS 99
4.1 Introduction 99
4.2 Tokens 100
4.3 Variable Declaration and Initialization 108
4.4 Data Types in C++ 115
4.5 Operators in C and C++ 129
4.6 Scope Access Operator 133
4.7 Namespace 133
4.8 Memory Management Operators 137
4.9 Comments 141
4.10 Comma Operator 142
4.11 Comma in Place of Curly Braces 143
4.12 More Programs 145
Summary 155
Exercises 156
5. dEciSioN StAtEmENtS 161
5.1 Introduction 161
5.2 The if Statement 162
5.3 Multiple ifs 165
5.4 The if-else Statement 167
5.5 Nested if-else Statements 169
5.6 The else-if Ladder 171
5.7 Unconditional Control Transfer Statements 175
Contents vii
5.8 The switch Statement 177
5.9 Nested switch case 182
Summary 183
Exercises 184
6. coNtrol looP StructurES 187
6.1 Introduction 187
6.2 What Is a Loop? 187
6.3 The for Loop 188
6.4 Nested for Loops 191
6.5 The while Loop 192
6.6 The do-while Loop 195
6.7 The do-while Statement with while Loop 196
6.8 More Programs 197
Summary 199
Exercises 199
7. fuNctioNS iN c++ 203
7.1 Introduction 203
7.2 Parts of a Function 205
7.3 Passing Arguments 209
7.4 Lvalues and Rvalues 215
7.5 Return by Reference 216
7.6 Returning More Values by Reference 217
7.7 Default Arguments 218
7.8 const Arguments 222
7.9 Inputting Default Arguments 224
7.10 Inline Functions 225
7.11 Function Overloading 228
7.12 Principles of Function Overloading 230
7.13 Precautions with Function Overloading 234
7.14 Recursion 235
7.15 Library Functions 237
7.16 More Programs 241
Summary 252
Exercises 252
8. clASSES ANd objEctS 257
8.1 Introduction 258
8.2 Structure in C 259
8.3 Structure in C++ 261
8.4 Classes in C++ 262
8.5 Declaring Objects 263
8.6 The public Keyword 264
viii Contents
8.7 The private Keyword 265
8.8 The protected Keyword 266
8.9 Access Specifiers and Their Scope 267
8.10 Defining Member Functions 268
8.11 Characteristics of Member Functions 272
8.12 Outside Member Function as Inline 272
8.13 Rules for Inline Functions 274
8.14 Data Hiding or Encapsulation 274
8.15 Classes, Objects, and Memory 277
8.16 static Member Variables 280
8.17 static Member Functions 286
8.18 static Object 289
8.19 Array of Objects 290
8.20 Objects as Function Arguments 292
8.21 friend Functions 295
8.22 The const Member Functions 304
8.23 The Volatile Member Function 305
8.24 Recursive Member Function 306
8.25 Local Classes 307
8.26 empty, static, and const Classes 310
8.27 Member Function and Non-member Function 310
8.28 The main() Function as a Member Function 311
8.29 Overloading Member Functions 312
8.30 Overloading main() Functions 313
8.31 The main(), Member Function, and Indirect Recursion 314
8.32 Bit Fields and Classes 317
8.33 Nested Class 319
8.34 More Programs 320
Summary 339
Exercises 340
9. coNStructorS ANd dEStructorS 345
9.1 Introduction 346
9.2 Constructors and Destructors 348
9.3 Characteristics of Constructors and Destructors 349
9.4 Applications with Constructors 350
9.5 Constructors with Arguments (Parameterized Constructor) 353
9.6 Overloading Constructors (Multiple Constructors) 355
9.7 Array of Objects Using Constructors 359
9.8 Constructors with Default Arguments 360
9.9 Copy Constructors 361
9.10 The const Objects 363
9.11 Destructors 364
9.12 Calling Constructors and Destructors 367
9.13 Qualifier and Nested Classes 370
Contents ix
9.14 Anonymous Objects 372
9.15 Private Constructors and Destructors 374
9.16 Dynamic Initialization Using Constructors 375
9.17 Dynamic Operators and Constructors 377
9.18 main() as a Constructor and Destructor 379
9.19 Recursive Constructors 380
9.20 Program Execution Before main() 381
9.21 Constructor and Destructor with Static Members 383
9.22 Local Versus Global Object 384
9.23 More Programs 385
Summary 392
Exercises 392
10. oPErAtor ovErloAdiNg ANd tyPE coNvErSioN 395
10.1 Introduction 395
10.2 The Keyword Operator 398
10.3 Overloading Unary Operators 400
10.4 Operator Return Type 403
10.5 Constraint on Increment and Decrement Operators 404
10.6 Overloading Binary Operators 405
10.7 Overloading with friend Function 409
10.8 Overloading Assignment Operator (=) 412
10.9 Type Conversion 414
10.10 Rules for Overloading Operators 422
10.11 One-Argument Constructor and Operator Function 424
10.12 Overloading Stream Operators 425
10.13 More Programs 427
Summary 438
Exercises 439
11. iNhEritANcE 441
11.1 Introduction 442
11.2 Reusability 442
11.3 Access Specifiers and Simple Inheritance 442
11.4 Protected Data with Private Inheritance 449
11.5 Types of Inheritance 454
11.6 Single Inheritance 456
11.7 Multilevel Inheritance 457
11.8 Multiple Inheritance 459
11.9 Hierarchical Inheritance 460
11.10 Hybrid Inheritance 462
11.11 Multipath Inheritance 465
11.12 Virtual Base Classes 466
11.13 Constructors, Destructors, and Inheritance 468
11.14 Object as a Class Member 483
11.15 Abstract Classes 489
x Contents
11.16 Qualifier Classes and Inheritance 489
11.17 Constructors in Derived Class 490
11.18 Pointers and Inheritance 491
11.19 Overloading Member Function 492
11.20 Advantages of Inheritance 494
11.21 Disadvantages of Inheritance 494
11.22 More Programs 494
Summary 505
Exercises 506
12. ArrAyS 511
12.1 Introduction 511
12.2 One-dimensional Array Declaration and Initialization 511
12.3 Characteristics of Arrays 512
12.4 Accessing Array Elements Through Pointers 515
12.5 Arrays of Pointers 516
12.6 Passing Array Elements to a Function 517
12.7 Passing Complete Array Elements to a Function 518
12.8 Initialization of Arrays Using Functions 519
12.9 Two-dimensional Arrays 520
12.10 Pointers and Two-dimensional Arrays 523
12.11 Three- or Multi-dimensional Arrays 524
12.12 Arrays of Classes 525
Summary 528
Exercises 529
13. PoiNtErS 531
13.1 Introduction 531
13.2 Features of Pointers 532
13.3 Pointer Declaration 533
13.4 Arithmetic Operations with Pointers 536
13.5 Pointer to Pointer 538
13.6 void Pointers 539
13.7 wild Pointers 540
13.8 Pointer to Class 542
13.9 Pointer to Object 544
13.10 The this Pointer 546
13.11 Pointer to Derived Classes and Base Class 550
13.12 Pointer to Members 554
13.13 Accessing Private Members with Pointers 561
13.14 Direct Access to Private Members 562
13.15 Addresses of Objects and void Pointers 564
13.16 More Programs 565
Summary 573
Exercises 573
Contents xi
14. c++ ANd mEmory modElS 577
14.1 Introduction 577
14.2 Memory Models 577
14.3 Dynamic Memory Allocation 581
14.4 The new and delete Operators 582
14.5 Heap Consumption 586
14.6 Overloading new and delete Operators 588
14.7 Overloading new and delete in Classes 592
14.8 Execution Sequence of Constructor and Destructor 595
14.9 Specifying Address of an Object 597
14.10 Dynamic Objects 598
14.11 Calling Convention 599
Summary 600
Exercises 601
15. biNdiNg, PolymorPhiSmS, ANd virtuAl fuNctioNS 603
15.1 Introduction 603
15.2 Binding in C++ 604
15.3 Pointer to Base and Derived Class Objects 609
15.4 Virtual Functions 612
15.5 Rules for Virtual Functions 613
15.6 Array of Pointers 615
15.7 Pure Virtual Functions 618
15.8 Abstract Classes 619
15.9 Working of Virtual Functions 621
15.10 Virtual Functions in Derived Classes 627
15.11 Object Slicing 629
15.12 Constructors and Virtual Functions 631
15.13 Virtual Destructors 632
15.14 Destructors and Virtual Functions 634
Summary 635
Exercises 635
16. APPlicAtioNS with filES 639
16.1 Introduction 639
16.2 File Stream Classes 641
16.3 Steps of File Operations 643
16.4 Checking for Errors 650
16.5 Finding End of a File 653
16.6 File Opening Modes 655
16.7 File Pointers and Manipulators 657
16.8 Manipulators with Arguments 661
16.9 Sequential Access Files 664
16.10 Binary and ASCII Files 666
xii Contents
16.11 Random Access Operation 670
16.12 Error Handling Functions 674
16.13 Command-Line Arguments 679
16.14 Strstreams 680
16.15 Sending Output to Devices 682
16.16 More Programs 684
Summary 691
Exercises 692
17. gENEric ProgrAmmiNg with tEmPlAtES 697
17.1 Introduction 698
17.2 Need for Templates 698
17.3 Definition of Class Templates 698
17.4 Normal Function Templates 701
17.5 Working of Function Templates 704
17.6 Class Templates with More Parameters 704
17.7 Function Templates with More Arguments 705
17.8 Overloading of Template Functions 708
17.9 Member Function Templates 709
17.10 Recursion with Template Functions 710
17.11 Class Templates with Overloaded Operators 711
17.12 Class Templates Revisited 713
17.13 Class Templates and Inheritance 715
17.14 Bubble Sort Using Function Templates 717
17.15 Guidelines for Templates 718
17.16 Differences Between Templates and Macros 719
17.17 Linked Lists with Templates 720
17.18 More Programs 722
Summary 727
Exercises 728
18. worKiNg with StriNgS 731
18.1 Introduction 731
18.2 Moving From C String to C++ String 734
18.3 Declaring and Initializing String Objects 735
18.4 Relational Operators 738
18.5 Handling String Objects 740
18.6 String Attributes 743
18.7 Accessing Elements of Strings 747
18.8 Comparing and Exchanging 750
18.9 Miscellaneous Functions 752
18.10 More Programs 754
Summary 757
Exercises 757
Contents xiii
19. ExcEPtioN hANdliNg 759
19.1 Introduction 759
19.2 Principles of Exception Handling 760
19.3 The Keywords try, throw, and catch 760
19.4 Guidelines for Exception Handling 761
19.5 Multiple catch Statements 765
19.6 Catching Multiple Exceptions 767
19.7 Re-throwing Exception 768
19.8 Specifying Exceptions 769
19.9 Exceptions in Constructors and Destructors 771
19.10 Controlling Uncaught Exceptions 773
19.11 Exceptions and Operator Overloading 774
19.12 Exceptions and Inheritance 776
19.13 Class Templates with Exception Handling 777
19.14 Guidelines for Exception Handling 778
19.15 More Programs 779
Summary 781
Exercises 782
20. ovErviEw of StANdArd tEmPlAtE librAry 785
20.1 Introduction to STL 785
20.2 STL Programing Model 786
20.3 Containers 786
20.4 Sequence Containers 787
20.5 Associative Containers 789
20.6 Algorithms 789
20.7 Iterators 794
20.8 Vectors 795
20.9 Lists 801
20.10 Maps 808
20.11 Function Objects 811
Summary 814
Exercises 815
21. AdditioNAl iNformAtioN About ANSi ANd turbo-c++ 817
21.1 Introduction 817
21.2 Innovative Data Types 818
21.3 New Type-casting Operators 821
21.4 The Keyword explicit 826
21.5 The Keyword mutable 827
21.6 Namespace Scope 828
21.7 Nested Namespaces 829
21.8 Anonymous Namespaces 830
21.9 The Keyword using 830
xiv Contents
21.10 Namespace Alias 835
21.11 The Standard Namespace std 835
21.12 ANSI and Turbo-C++ Keywords 836
21.13 ANSI and Turbo-C++ Header Files 839
21.14 C++ Operator Keywords 840
Summary 840
Exercises 841
22. c++ grAPhicS 843
22.1 Introduction 843
22.2 Computer Display Modes 844
22.3 Video Display and Display Adapters 844
22.4 Initilisation of Graphics 844
22.5 Few Additional Graphics Functions 846
22.6 Programs Using Library Functions 848
22.7 Working with Texts 856
22.8 Filling Patterns with Different Colors and Styles 858
22.9 Mouse Programming 862
22.10 Drawing Noncommon Figures 866
Summary 867
Exercises 867
Appendices 869
Index 879
Programming in C++ is meant for students pursuing various disciplines such as engineer-
ing, science, computer application, and diploma courses. Students who are learning object-
oriented programming (OOP) can also refer to this book. It covers the subject of C++ as per
the syllabi prescribed by various branches of Indian universities, state board of technical
educations, and the Department of Electronics and Accreditation of Computer Courses. Hence,
this book can be adopted in engineering, degree as well as other courses that deal with this sub-
ject. Written for beginners and for those who have some knowledge of C, the book will be espe-
cially useful for students who are learning object-oriented programming.
Designed to bridge the gap between theory and practice, the chapters have been presented
using a systematic and lucid approach. Each topic is explained in an easy-to-understand manner
with ample worked-out examples and programs. The book abounds with about 700 solved
programs and as many as 300 exercises for the student’s benefit. The programmer can run the
solved programs, see the output and appreciate the concepts of C++.
The programs have been fully tested and executed with Borland’s Turbo C++ compiler
version 3.00 and Visual C++ 6.0 compiler. The programs in Chapter 22 have been tested and
compiled with Java Compiler version 2.
This second edition has been thoroughly revised based on comments and responses received
for the previous edition. All programming examples have been tested, compiled and executed.
While utmost care has been taken at the time of writing this book, it is possible that errors and
omissions may have inadvertently crept in. Such incongruities, if any, may please be pointed
out. Suggestions and feedback are most welcome and may be directed to my e-mail address:
ankamthane@gmail.com.
AcKNowlEdgEmENtS
I express my gratitude to the Minister for Technical and Medical Education of Maharashtra State,
Honorable Shri D. P. Sawant, who complimented and felicitated me for writing technical books,
while he was invited to our institute recently in the month of May 2013. He also encouraged me
to write more books.
I am grateful to Prof. B. M. Naik, Former Principal of S.G.G.S. Institute of Engineering and
Technology, Nanded, who has always acted as a source of encouragement. His dynamism and
leadership led me to write this book and I will never forget his support and words of wisdom.
Preface
xvi Preface
Special thanks are due to the members of the board of governors of S.G.G.S. Institute of
Engineering and Technology, who motivated me to write this book. I thank eminent industrialist
Shri B. N. Kalyani, head of the Kalyani Group of Companies, for inspiring and complimenting
me for authoring technical books. I am also obliged to Dr L. M. Waghmare, Director of our
institute, for supporting and appreciating me while writing this book.
I am indebted to all my colleagues, friends and students who helped me at the time of
preparing the manuscript for this book. I acknowledge the support rendered by Dr S. V. Bonde,
Dr P. D. Jadhav, Dr P. Pramanik, Dr P. S. Charpe, Dr B. M. Dabde, DrY.V. Joshi, Dr U.V. Kulkarni,
Dr S. P. Kallurkar, Dr V. M. Nandedkar, Dr A. U. Digraskar, Dr R. S. Holambe, Dr B. M. Patre,
Prof. R. K. Chavan, Dr J. V. L. Venkatesh, Prof. P. S. Nalawade, S. S. Hatkar, Dr R. C. Thool,
Dr V. R. Thool, Dr D. D. Doye, Milind Bhalerao, Dr A. B. Gonde, Dr A. Chakraborthi,
Dr A. V. Nandedkar, Dr P. B. Londhe, Dr R. R. Manthalkar, Dr S. S. Gajre, Prof. N. G. Megde,
Dr A. S. Sontakke, Dr R. H. Chille, Dr L. M. Waikar and A. I. Tamboli of S.G.G.S. Institute of
Engineering and Technology.
I thank my friends Principal Prof. S. L. Kotgire and Prof. Balaji Bacchewar for their words
of encouragement. M. M. Jahagirdar, L. M. Buddhewar, K. M. Buddhewar, D. V. Deshpande,
S. R. Kokne, M. G. Damkondawar, Yeramwar, Pampatwar, D. R. Yerawar, S. R. Tumma, and
S. R. Mana also helped me to a great extent while writing this book.
I thank Pearson Education for publishing this book. In particular, I thank Ms V. Pavithra and
Ms Neha Goomer for their help in seeing this book through production. In addition, I also thank
Thomas Rajesh for his constant encouragement.
I appreciate the help and support provided by all the students, faculty, and non-teaching staff
of this institute as well as that of other friends who have directly or indirectly added value to this
book.
Thanks are also due to my wife, Surekha, who persistently supported me at all times. I am
indebted to my sons Amol and Amit, daughter Sangita, as also my daughter-in-law Swarupa, who
all played a key role in bringing this book to fruition. Swarupa was of immense help in drawing
the figures in several chapters. I thank all of them.
Ashok Namdev Kamthane
Ashok Namdev Kamthane obtained his M.E. (Electronics) degree from S.G.G.S. Institute of
Engineering and Technology, Nanded.A meritorious student throughout his career, he has bagged
a number of prizes including cash and medals for his distinct work in the academics. For his
M. E. (Electronics) dissertation, he worked at the Bhabha Atomic Research Center, Mumbai.
Associated with the teaching profession for the past 30 years, Kamthane was instrumental
in the development of hardware and software using the 8051 (8-bit microcontroller) on Acoustic
Transceiver System required in submarines. He has also worked at Melton as an executive.
Currently Associate Professor at the Department of Electronics and Telecommunication
Engineering in S.G.G.S Institute of Engineering and Technology, he has guided a number of
undergraduate and postgraduate students in their projects and published a number of technical
papers at both national and international conferences.
About the Author
This page is intentionally left blank.
•
•
•
•
•
•
•
•
•
•
•
•
1.1 Differences between C and C++
1.2 Evolution of C++
1.3 The ANSI Standard
1.4 The Object Oriented Technology
1.5 Disadvantage of Conventional Programming
1.6 Programming Paradigms
1.7 Preface to Object Oriented Programming
1.8 Key Concept of Object Oriented Programming
1.9 Advantages of OOP
1.10 Object Oriented Languages
1.11 Usage of OOP
1.12 Usage of C++
Introduction to C++
Chapter
Outline
1.1 Differences between c anD c++
Some differences between C and C++ are as follows:
(1) C is a procedure/function-oriented language and C++ language is driven by a procedure/
object.
(2) Data is not protected in C, whereas data is secured in C++. Data hiding concept is absent
in C.
(3) C uses a top down approach while C++ uses a bottom up approach. The program is
prepared step by step in C, and in C++ base elements are prepared first.
(4) In C, we cannot give the same name to two functions in a program, whereas due to the
function overloading feature, the above concept is possible in C++. One can initialize a
number of functions with the same name, but with different arguments. The polymorphism
feature is built in C++, which supports this concept.
c H a P t e r
1
2 Introduction to C++
(5) C uses printf() and scanf() functions to write and read the data respectively,
while C++ uses cout and cin objects for output and input operations, respectively.
Further, the cout uses << (insertion operator) and cin uses >> ( extraction operator).
(6) C uses stdio.h file for input and output functions, whereas C++ uses iostream.h
for these functions.
(7) Constructor and destructors are absent in C and the same are provided in C++.
(8) Inline functions are supported by C++, and the same are absent in C. Inline func-
tions can be used as micros. They are stated by a word ‘inline’.
1.2 evolution of c++
C++ is an object oriented programming language and also con-
sidered as an extension of C. Bjarne Stroustrup at AT&T Bell
Laboratories in Murray Hill, New Jersey (USA) developed this
language in the early 1980s. Stroustrup, a master of Simula67
and C, wanted to combine the features of both the languages
and he developed a powerful language that supports object-ori-
ented programming with features of C. The outcome was C++
as per Fig. 1.1.Various features were derived from Simula67
and algol68. Stroustrup called the new language ‘C with
classes’. However, in 1983, the name was changed to C++.
The thought of C++ came from the C increment operator
++. Rick Mascitti coined the term C++ in 1983. Therefore,
C++ is an extension of C. C++ is a superset of C. All the
concepts of C are applicable to C++ also.
For developing complicated applications, object orient-
ed language such as C++ is the most convenient and easy.
Hence, a programmer must be aware of its features.
1.3 tHe ansi stanDarD
The ANSI stands for American National Standards Institute. This Institute was founded in 1918.
The main goal for establishing this Institute was to suggest, reform, recommend, and publish stan-
dards for data processing in the USA. This committee sets up the standard in the computer industry.
The recognized council working under the procedure of the American National Standards
Institute (ANSI) has made an international standard for C++. The C++ standard is also referred to
as ISO (International Standards Organization) standard. The process of standardization is gradual
and the first draft of the planned ANSI standard was made on 25 January 1994. This book will
continue to refer ANSI standard code, which is more commonly used. The ANSI standard is an
attempt to ensure that the C++ is portable.
1.4 tHe object orienteD tecHnology
Nature is composed of various objects. Living beings can be categorized into different objects.
Let us consider an example of a teaching institute which has two different working sections –
teaching and non-teaching. Further sub-grouping of teaching and non-teaching can be made for
fig. 1.1 Evolution of C++
C SIMULA 67
C WITH CLASSES
ALGOL 68
C++
The Object Oriented Technology 3
the coordination of management. The various departments of any organization can be thought of
as objects working for certain goals and objectives.
Usually an institute has faculty of different departments. The Director/Principal is a must for
the overall management of the institute. The Academic Dean is responsible for the academics of
the institute. The Dean for Planning should have the future plans of the institute and he/she must
see how the infrastructure is utilized effectively. The Dean R&D should see research activities
run in the institute forever.
Besides teaching staff there must be laboratory staff for assistance in conducting practical ses-
sions, and a site development section for beautification of the campus. The accounts department
is also required for handling monetary transactions and salaries of the employees. The Sports sec-
tion is entrusted the responsibility of sports activities. The Registrar for Administration and staff
for dealing with administrative matters of the institute are also required. Each department has an
in-charge who carries clear-cut given responsibilities. Every department has its own work as stat-
ed above. When an institute’s work is distributed into departments as shown in Fig. 1.1, it is com-
fortable to accomplish goals and objectives. The activities are carried on smoothly. The burden of
one particular department has to be shared among different departments with personnel. The staff
in the department is controlled properly and act according to the instructions laid down by the
management. The faculty performs activities related to teaching. If the higher authority needs to
know the details regarding the theory, practical, seminar and project loads of individuals of the de-
partment, then a person from the department furnishes the same to the higher authority. This way
some responsible person from the department accesses the data and provides the higher authority
with the requisite information. It is also good to think that no unconnected person from another
department reads the data or attempts to make any alteration that might corrupt the data.
As shown in Fig. 1.2, an institute is divided into different departments such as library,
classroom, computer laboratory, etc. Each department performs its own activities in association
with the other departments. Each department may be considered as a module and it contains
class and object in C++ language. This theory of class and object can be extended to every
walk of life and can be implemented with software. In general, objects are in terms of entities.
Class Room
Computer Lab
Library
fig. 1.2 Relationship between different sections
4 Introduction to C++
In a nutshell, in object oriented programming objects of a program interact by sending
messages to each other.
1.5 DisaDvantage of conventional Programming
Traditional programming languages such as COBOL, FORTRAN, C etc. are commonly known
as procedure oriented languages. The program written in these languages consists of a sequence
of instructions that tells the compiler or interpreter to perform a given task. Numerous functions
are initiated by the user to perform a task. When a program code is large, it becomes inconve-
nient to manage it. To overcome this problem, procedures or subroutines were adopted to make
a program more understandable to the programmers. A program is divided into many functions.
Main Function
Function-A
Function-D
Function-F Function-G Function-H
Function-E
Function-B Function-C
fig. 1.3 Flow of functions in non-OOP languages
Each function can call another function, as shown in Fig. 1.3. Each function has its own task. If
the program is too large the function also creates problems. In many programs, important data
variables are declared as global. In case of programs containing several functions, every function
can access the global data as per the simulation in Fig. 1.4. In huge programs it is difficult to know
what data is used by which function. Due to this the program may contain several logical errors.
Global Variables Global Variables Global variables
Function A
Local Variable
Function B
Local Variable
Function C
Local Variable
Function D
Local Variable
fig. 1.4 Sharing of data by functions in non-OOP languages
The following are the drawbacks observed in monolithic, procedure, and structured program-
ming languages:
Programming Paradigms 5
(1) Huge programs are divided into smaller programs known as functions. These functions
can call one another. Hence security is not provided.
(2) No importance is given to security of data and importance is laid on doing things.
(3) Data passes globally from function to function.
(4) Most function accesses global data.
1.6 Programming ParaDigms
(1) monolithic Programming:
(A) In these types of programming languages,
theprogramiswrittenwithasinglefunction.
A program is not divided into parts; hence it
is named as monolithic programming. It is
also called single thread execution.
(B) When the program size increases it leads
to difficulty.
(C) In monolithic programming languages
such as basic and assembly language, the
data variables declared are global and the
statements are written in sequence.
(D) The program contains jump statements
such as goto that transfers control to any
statement as specified in it. Fig. 1.5 shows
a program of monolithic type. The global
data can be accessed from any portion of
the program. Due to this reason the data is
not fully protected.
(E) The concept of sub-programs does not
exist, and hence is useful for small programs.
(2) Procedural/structured Programming
(A) Sometimes known as modular programming.
(B) Programs written are more efficient and easier to understand and modify.
(C) The procedural/structured programming languages are similar to solving a prob-
lem by human. In a nut shell, humans attempt a problem by adopting a sequence
of operations.
(D) It makes use of a top-down design model in which a program developer maps out
the overall program structure into separate subsections.
(E) Large size programs can be developed in structured programming such as Pascal
and C. Programs are divided in multiple sub-modules.
(F) Procedural/Structured programming languages such as FORTRAN, BASIC, AL-
GOL, COBOL, C, etc., are divided into a number of segments called as subpro-
grams. There is a main function and it invokes subprograms. Thus, it focuses on
functions apart from data. Figure 1.6 describes a program of procedural/structured
type. It shows different sub-programs accessing the same global data. Here also
the programmer can observe the lack of secrecy.
fig. 1.5 Program in monolithic
programming
1 Statement
2 Statement
3 Statement
50 Statement
51 Statement
52 Statement
99 Statement
100 Statement
goto 50
goto 1
GLOBAL DATA
6 Introduction to C++
(G) The control of program can be transferred using unsafe goto statement.
(H) This type of programming language uses different control structures that are as
follows.
• Decision/selection control statements
• Iteration control statements
• Jump control statements
(I) Data are global and all the sub-programs share the same data, i.e. data are globally
accessible to all functions. Thus, any function operates on the global data and this
directs to loosing some vital information. We can conclude here that a module
represents a function.
(J) Procedural structured/programming languages permit data transfer through mes-
sages by means of functions.
(K) Least importance is given to the data in procedural/structured programming languages.
(L) These languages are used for developing medium-sized software applications.
(M) Complier and interpreter construction are easy and simple with this type of pro-
gramming language. Furthermore, these compilers and interpreters need low
memory to run on the computers.
(N) It is difficult to implement simultaneous processes/parallelization.
Modules
GLOBAL DATA
Local Data
Local Data
Local Data
fig. 1.6 Program in procedural/structured programming
1.7 Preface to object orienteD Programming
The prime factor in the design of object oriented programming approach is to rectify some of
the faults observed in the procedure oriented languages. OOP acts with data as a critical com-
ponent in program development. It does not allow the data to flow freely around the systems. It
ties data to the functions that operate on it and prevents it from accidental change due to external
functions. OOP permits us to analyze a problem into a number of items called objects and then
assembles data and functions around these items as per Fig. 1.7. Following are the impressive
characteristics of object-oriented programming:
(1) OOP pays more importance to data rather than function.
(2) Programs are divided into classes and their member functions.
(3) OOP follows a bottom-up approach.
(4) New data items and functions can be comfortably added whenever essential.
(5) Data is private and prevented from accessing external functions.
(6) Objects communicate with each other through functions.
Data variables
Object A Object B Object C
Member function Member function Member function
Member function Member function Member function
Data variables Data variables
Data variables Data variables Data variables
fig. 1.7 Relation between data and member function in OOP
1.8 Key concePts of object orienteD Programming
Object oriented programming language is a feature that allows a mode of modularizing programs by
forming ory area for data as well as functions that is used as object for making copies of modules as per
requirement.
There are several fundamental concepts in object oriented programming. They are shown in Fig. 1.8
and are discussed as follows.
fig. 1.8 Concepts/elements of object oriented paradigm
C++
Encapsulation
Data abstraction
Inheritance
Polymorphism
Delegation
Genericity
Key Concepts of Object Oriented Programming 7
8 Introduction to C++
(1) objects
Objects are primary run-time entities in object oriented programming.
Objects are primary run-time entities in object-oriented programming. They may stand for a
thing that makes sense in a specific application. Some examples are a spot, a person, any data
item related to the program including user-defined data types. Programming issues are analyzed
in terms of object and the type of transmission between them. Program objects must be selected
like the items equivalent to actual world objects. Objects occupy space in memory. Every object
has its own properties or features that illustrate what the object can do. An object is a specimen
of a class. It can be singly recognized by its name. It declares the state that is shown by the data
values of its characteristic at a specific time. The state of the object varies according to the pro-
cedure used with it. It is called as the action of the object. The action of the object depends upon
the member function defined within its class.
Fig. 1.9 (a) shows some of the objects that we use in our daily life.

Telephone

Book

Computer

Watch Lock


Home

Trophy

Television

Bicycle

Ambulance
fig. 1.9 (a) Commonly available objects fig. 1.9 (b) Representation of
an object
Object: City
Data:
Name_of_city
Population
Area
Functions:
Average age
Literacy_rate
Display
Objects communicate with each other by sending messages. An object can be represented by
Fig 1.9 (b).
The name of the above object is city. Its data members are name_of_city, population, and
area. The various functions associated with the city are average age, literacy_ rate, and display.
(2) classes
A class is grouping of objects that have the identical properties, common behavior, and shared relation-
ship. A class binds the data and its related functions together.
A class is the accomplishment of abstract data type. It defines the nature and methods that act
on the data structure and abstract data type, respectively. Specimens are also called as objects. In
other words, a class is a grouping of objects that have identical properties, common behavior, and
shared relationship. For example, Tata’s Swift, Maruti’sAlto etc. are the members of a class car.
The entire group of data and code of an object can be built as a user-defined data type us-
ing class. Objects are nothing but variables of type class. Once a class has been declared, the
programmer can create a number of objects associated with that class. The syntax used to create
Key Concepts of Object Oriented Programming 9
an object is similar to the syntax used to create an integer variable in C. A class is a model and
not a true specimen of the object. Every object has its own value for each of its member variables.
However, it shares the property names or operations with other instances of the class. Thus,
classes define the characteristic and action of objects.
Class: car
Properties: company, model, color, and capacity
Actions: Speed(), average() and break().
Class: computer
Properties: Brand, resolution, price and size
Action: processing(), display() and printing()
Class: floppy
Properties: company, size and capacity
Action: storing(), protection(), and retrieving()
fig. 1.10 Objects and their properties
In Fig. 1.10 commonly useful classes are described with their properties and action they per-
form. For example, a car has properties like company, model and color with which a car can be
identified among a number of cars of other properties, and the actions like speed() and aver-
age() describes its working.
Class home
{
Telephone
Book
Computer
Watch
Lock
}
Class vehicle
{}
Class entertainment
{     }
fig. 1.11 Classes and their members
Figure 1.11 describes the classes and related data that come under the different classes.

{





}
10 Introduction to C++
(3) method
An operation required for an object or entity when coded in a class is called a method.
An operation required for an object or entity when coded in a class is called a method. The opera-
tions that are required for an object are to be defined in the class. All objects in a class carry out
certain common actions or operations. Each action needs an object that becomes a function in the
class that defines it and is referred to as a method.
In Fig. 1.12 the class and its associated data members and functions are shown in different
styles. It is a frequent style of writing a class in the program.
The class A contains private data members and public methods or member functions.
Usually, the data members are declared private and methods or member functions are declared
as public and they are available outside the class. The data member of any class uses its member
functions or methods to perform operations.
class A
{
private
data member1;
data member2;
data member(n);
public
method1() { }
method2() { }
method_n() { }
};
Members
Methods or
Member functions
(a)
Data member 1
Data member 2
Data member 3
:
:
Data member n
Method 1
Method 2
Method 3
:
:
Method n
Class A
Data member 1
Data member 2
Class A
Method 1
Method 2
Method n
(b)
fig. 1.12 (a) and (b) Representation of methods in different manners
Key Concepts of Object Oriented Programming 11
(4) Data abstraction
Abstraction refers to the procedure of representing essential features without including the background
details.
Abstraction refers to the procedure of representing essential features without including the back-
ground details. Classes use the theory of abstraction and are defined as a list of abstract properties
such as size, cost, height, and few functions to operate on these properties. Data abstraction is
the procedure of identifying properties and method related to a specific entity as applicable to
the application.
A powerful method to achieve abstraction is through the manipulation of hierarchical clas-
sifications. It permits us the breaking of semantics of multiple systems into layers by separating
them into multiple controllable parts. For example, a computer as shown in Fig. 1.13 is made of
various parts such as CPU, keyboard, and so on. We think it as a single unit, but the single unit
has several sub-units. They together do the single task. By assembling sub-parts we can build a
single system.
Hierarchical abstraction of complicated systems can also be used in computer software. The
data from conventional procedure oriented programs can be converted by abstraction mechanism
into its partial objects. A series of operation steps may develop a set of messages between these
objects. Each object shows its own attributes.
Data abstraction is used to define a data type available in the programming language, called
as abstract data type (ADT). It consists of a set of values and a set of operations.

(a) Computer as single unit

(b) Different components of computer
fig 1.13 Computer and its parts
(5) encapsulation
The packing of data and functions into a single component is known as encapsulation.
C++ supports the features of encapsulation using classes. The packing of data and functions into
a single component is known as encapsulation. The data is not reachable by the outside functions.
Only those functions that are able to access the data are defined within the class. These functions
prepare the interface between the object’s data and the program. With encapsulation we can
accomplish data hiding. Data hiding is an important feature using which an object can be used
without the user knowing how it works internally.
In C++ the fundamental of encapsulation is class. A class defines the structure of data and
member functions. It is common to all its objects. Class is a logical structure whereas object is
12 Introduction to C++
a physical actuality. The goal of the class is to encapsulate complication. The class also has a
mechanism for hiding the data. Each member in the class may be private or public. Any non-
member function cannot access the data of the class. The public section of the class must be
mindfully coded not to expose the inner details of the class. Figure 1.14 explains sections of
encapsulation.
class C
κ Private Data
Members
υ Private methods
Φ Public methods
ι Public data
members ι ι ι ι
Φ Φ
Φ Φ Φ
Φ
Φ
Φ
Φ
Φ
Φ
Φ
Φ
υυυ
υυυ
υυυ
υυυ
κκκκκ
κκκκκ
κκκκκ
κκκκκ
Φ
fig. 1.14 Encapsulation: Private and public sections
(6) inheritance
Inheritance is the method by which objects of one class get the properties of objects of another class.
Inheritance is the method by which objects of
one class get the properties of objects of another
class. In object oriented programming inheritance
provides the thought of reusability. The programmer
can add new properties to the existing class without
changing it. This can be achieved by deriving a new
class from the existing one. The new class will pos-
sess features of both the classes. The actual power
of the inheritance is that it permits the programmer
to reuse a class that is nearly, but not precisely, what
he wants, and to tailor the class in such a manner
that it does not bring any unwanted incidental re-
sult into the rest of the class. Thus, inheritance is the
feature that permits the reuse of an existing class to
make a new class. Figure 1.15 shows an example of
inheritance.
In Fig. 1.15, red, yellow and blue are the main colors. The orange is created from the combi-
nation of red and yellow, green is created from yellow and blue and violet is created from red and
blue. The orange color has attributes of both red and yellow, which produces a new effect. Thus,
many combinations are possible.
(7) Polymorphism
Polymorphism allows the same function to act in a different way in different classes.
Red Yellow Blue
Violet
Orange Green
Bluish
brown
Yellowish
brown
Reddish
brown
fig. 1.15 Inheritance
Key Concepts of Object Oriented Programming 13
Polymorphism makes it possible for the same functions to act differently on different classes as
shown in Fig. 1.16. It is an important feature of OOP concept. It holds an ability to take more than
one form. Polymorphism accomplishes an important part in allowing objects of different classes
to share the same external interface. It is possible to code a non-specific (generi(c) interface to a
set of associated actions.
Line
Display()
Single Object Dash Object
Dotted Object
Display(dotted) Display(single) Display(dash)
fig. 1.16 Polymorphism in OOP
(8) Dynamic binding
Binding means connecting one program to another program that is to be executed in reply to the call.
Binding means connecting one program to another program that is to be executed in reply to
the call. Dynamic binding is also known as late binding. The code present in the specified
program is unknown till it is executed. It is analogous polymorphism.
In Fig. 1.16 polymorphism allows the single object to invoke similar function from different
classes. The program action is different in all the classes. At execution time, the code analogous
to the object under the present reference will be executed. The reader is advised to refer polymor-
phism chapter for more details.
(9) message passing
An object oriented programming includes objects. The objects communicate with one another.
The programming with these objects should be followed with following steps.
(1) Declaring classes that define objects and their actions.
(2) Declaring objects from classes.
(3) Implementing relation between objects.
Data is transferred from one object to another object. A message for an object is the demand
for implementation of the process. Message passing consists of indicating the name of the object,
function, and required data elements (Fig. 1.17). Objects can be created, released, and interacted
with each other. An object is workable, as long as it is active. In object oriented programming
there is a panorama of independent objects that communicate with each other by swapping mes-
sages. Objects invoke member functions. They also negate if the calling object is not a member of
14 Introduction to C++
the same class. Thus a message is a solicitation to an object to call one of its member functions.
A message contains name of the member function and parameters of the function. Execution of
member function is just a response generated due to receipt of a message. It is possible when the
function and the object are of the same class.
Obj.Display (argument)
Object Data
Communication operator
Message
fig. 1.17 Message Passing
(10) reusability
Object oriented technology allows reusability of the classes by extending them to other classes using
inheritance.
Object oriented technology allows reusability of the classes by extending them to other class-
es using inheritance. Once a class is defined, the other programmer can also use it in their
programs. The programmer can also add new feature to the derived classes. The verified and
checked qualities of base classes need not to be redefined. Thus, the reusability saves the time.
In Fig. 1.18, class A is reused and class B is created. Again class B is reused and class
C is created.
CLASS A
CLASS B
CLASS C
fig. 1.18 Reusability
(11) Delegation
In OOP, two classes can be joined in two ways: (a) Inheritance, (b) Delegation. Both these ways
provide reusability of the class.
In Inheritance one class can be derived from the other class. The relationship between these
two classes is called as kind of relationship. For example if class Y is derived from class X, then
class Y is known as kind of X. Figure 1.19 (a) explains this point.
Advantages of OOP 15
Class X//Base class
Class Y//Derived class
CLASS A
{ };
CLASS B
{ };
CLASS C
{
A a; // Object of class A as data member
B b; // Object of class B as data member
}
(a) (b)
fig. 1.19 Relationships between two classes: (a) Kind of relationship (Inheritance)
(b) has a relationship (Delegation)
The second type of relationship is has a relationship. When object of one class is used as
data member in the other class, such composition of objects is known as delegation. As shown in
Fig. 1.19 (b) class C has two data members. These two data members are objects of class A
and B, such relationship between the classes in known as has a relationship.
(12) genericity
The software components of a program have more than one version depending on the data
types of arguments. This feature allows declaration of variables without specifying exact
data type. The compiler identifies the data type at run time. The programmer can create a
function that can be used for any type of data. The template feature in C++ allows generic
programming.
1.9 aDvantages of ooP
Object oriented technology provides many advantages to the programmer and the user. This
technology solves many problems related to software development, provides improved quality
and low cost software.
(1) Object oriented programs can be comfortably upgraded.
(2) Using inheritance, we can eliminate redundant program code and continue the use of
previously defined classes.
(3) The technology of data hiding facilitates the programmer to design and develop safe
programs that do not disturb code in other parts of the program.
(4) The encapsulation feature provided by OOP languages allows programmer to define the
class with many functions and characteristics and only few functions are exposed to the
user.
(5) All object oriented programming languages allows creating extended and reusable parts
of programs.
(6) Object oriented programming changes the way of thinking of a programmer. This re-
sults in rapid development of new software in a short time.
(7) Objects communicate with each other and pass messages.
16 Introduction to C++
1.10 object orienteD languages
There are many languages which support object oriented programming. Tables 1.1 and 1.2 describe
the OOP languages and features supported by them.
table 1.1 Properties of pure OOP and object based languages
Pure object oriented languages object based
languages
Properties java simula smalltalk eiffel java ada
Encapsulation      
Inheritance      No
Multiple inheritance      No
Polymorphism      
Binding (Early and late) Both Both Late binding Early binding Both Early binding
Genericity      
Class libraries      Few
Garbage collection      
Persistence   Promised Less  Same as 3GL
Concurrency   Less Promised  Hard
table 1.2 Properties of extended traditional languages
extended traditional languages
Properties objective c c++ charm ++ objective Pascal turbo Pascal
Encapsulation     
Inheritance     
Multiple inheritance    - - - - - -
Polymorphism     
Binding (Early and late) Both Both Both Late Early
Genericity     
Class libraries     
Garbage collection     
Persistence     
Concurrency Poor Poor   
The following are the object-oriented languages, which are widely accepted by the pro-
grammer.
• C++
• Smalltalk
• Charm ++
• Java
smalltalK
Smalltalk is a pure object oriented language. C++ makes few compromises to ensure quick per-
formance and small code size. Smalltalk uses run-time binding. Smalltalk programs are con-
sidered to be faster than the C++. Smalltalk needs longer time to learn than C++. Smalltalk
programs are written using Smalltalk browser. Smalltalk uses dynamic objects and memory is
allocated from free store. It also provides automatic garbage collection and memory is released
when object is no longer in use.
cHarm++
Charm ++ is also an object oriented programming language. It is a portable. The language pro-
vides features such as inheritance, strict type checking, overloading, and reusability. It is de-
signed in order to work efficiently with different parallel systems together with shared memory
systems, and networking.
java
Java was developed by Patrick Naughton, James Gosling, ChrisWarth, Mike Sheridan and Ed Frank
at Sun Microsystems. Java is an object oriented programming language and supports maximum
OOP characteristics exist. Its statement structure is like C and C++, but it easier than C++. Java
excludes few confusing and unsafe features of C and C++ like pointers.
Java allows client/server programming. Java is used for Internet programming. The Java
programs are downloaded by the client machines and executed on different types of hardware.
This portability is achieved by translation of Java program to machine code using compiler and
interpreter.
The Java compiler converts the source program to JVM (Java virtual machine). The JVM is
a dummy CPU. The compiler Java program is called as byte code. The Java interpreter translates
byte code into the object code. Compiler and interpreter do the conversion of Java program to
object code.
1.11 usage of ooP
Object oriented technology is changing the style of software engineers to think, analyze, plan,
and implement the software. The software developed using OOP technology is more efficient and
easy to update. OOP languages have standard class library. The users in their program can reuse
the standard class library. Thus, it saves lot of time and coding work.
The most popular application of object oriented programming is windows. There are sev-
Usage of OOP 17
18 Introduction to C++
eral windowing software based on OOP technology. Following are the areas for which OOP is
considered.
(1) Simulation
(2) Object oriented DBMS
(3) Office automation software
(4) Artificial Intelligence and expert systems
(5) CAD/CAM software
(6) Network programming & Internet applications
(7) System software
1.12 usage of c++
C++ is a flexible language. Lengthy programs can be easily controlled by the use of C++. It
permits us to create hierarchy -associated objects and libraries that can be useful to other pro-
grammers. C++ helps the programmer to write bug-free program, which are easy to maintain.
summary
(1) C++ is an object oriented programming
language invented by Bjarne Stroupstrup at
AT&T Bell Laboratories.
(2) The recognized council working under the
procedure of theAmerican National Standard
Institute (ANSI) has made an international
standard for C++.
(3) The disadvantage in conventional program-
ming language is that the program written in
these languages consists of a sequence of in-
structions that tells the compiler or interpreter
to perform a given task. When program code
is large then it becomes inconvenient to man-
age.
(4) The prime factor in the design of object ori-
ented programming approach is that to get
back some of the faults found in the proce-
dure oriented languages.
(5) In monolithic programming languages such
as basic and assembly language, the data
variables declared are global and the state-
ments are written in sequence.
(6) In the procedural programming languages
such as FORTRAN and COBOL, programs
are divided into number of segments called
as subprograms. Thus it focuses on functions
apart from data.
(7) Larger programs are developed in structured
programming such as Pascal and C. Pro-
grams are divided in multiple sub modules
and procedures.
(8) OOP acts with data as a critical component in
the program development and does not let the
data to flow freely around the systems.
(9) Object: Objects are primary run-time enti-
ties in an object-oriented programming. They
may stand for a thing that makes sense in a
specific application.
(10) Class:A class is grouping of objects that have
the identical properties, common behavior,
and shared relationship. The entire group of
data and code of an object cab be built as a
user-defined data type using class.
(11) Method: An operation required of an object
or entity when coded in a class is called a
method.
(12) Data Abstraction: Abstraction directs to the
procedure of representing essential features
without including the background details.
(13) Encapsulation: C++ supports the features of
encapsulation using classes. The packing of
data and functions into a single component is
known as encapsulations.
(14) Inheritance: Inheritance is the method by
Exercises 19
eXercises
(A) Answer the following questions.
which objects of one class get the proper-
ties of objects of another class. In object ori-
ented programming inheritance provides the
thought of reusability.
(15) Polymorphism: Polymorphism makes pos-
sible the same functions to act differently on
different classes. It is an important feature of
OOP concept.
(16) Object oriented technology allows reusabil-
ity of the classes by extending them to other
classes using inheritance.
(17) The languages C++, Smalltalk, Eiffel and
Java are widely used OOP languages.
(18) Object oriented technology is changing the
style of software engineers to think, analyze,
plan and implements the software. The soft-
ware developed using OOP technology is
more efficient and easy to update.
(19) C++ is a flexible language. Lengthy programs
can be easily controlled by the use of C++.
(1) Compare C and C++.
(2) What is object oriented programming?
(3) Explain the key concepts of OOP.
(4) What is ANSI standard?
(5) What are the disadvantages of conven-
tional programming languages?
(6) Explain the characteristics of monolithic
programming languages.
(7) Compare structured and procedural lan-
guages.
(8) List the disadvantages of procedural pro-
gramming languages.
(9) Explain evolution of C++.
(10) List the names of popular OOP languages.
(11) ListtheuniquefeaturesofanOOPparadigm.
(12) What is an object and class?
(13) How is data secured in OOP languages?
(14) Compare and contrast OOP languages
with procedure oriented languages.
(15) Mention the types of relationships be-
tween two classes.
(16) What is structured oriented program-
ming? Discuss its pros and cons.
(17) How is global data shared in procedural
programming?
(18) Describe any two object oriented pro-
gramming languages.
(19) What are the differences between Java
and C++?
(20) Mention the advantages of OOP languages?
(21) What do you mean by message passing?
(22) Distinguish between inheritance and
delegation.
(23) Can we define member functions in
private section?
(24) Can we declare data member in the public
section?
(B) Answer the following by selecting the appropriate option.
(1) Datahidingconceptissupportedbylanguage
(a) C
(b) Basic
(c) Fortran
(d) C++
(2) Function overloading means
(a) different functions with different
names
(b) function names are same but same
number of arguments
(c) function names are same but differ­
ent number of arguments
(d) none of the above
(3) C++ language was invented by
(a) Bjarne Stroupstrup
(b) Dennis Ritche
(c) Ken Thompson
(d) none of the above
(4) The languages COBOL and BASIC are
commonly known as
20 Introduction to C++
(a) procedure oriented languages
(b) object oriented languages
(c) low level languages
(d) none of the above
(5) A program with only one function is ob-
served in
(a) monolithic programming langu­
ages.
(b) object oriented languages
(c) structured programming languages
(d) none of the above
(6) The packing of data and functions into a
single component is known as
(a) encapsulation
(b) polymorphism
(c) abstraction
(d) none of the above
(7) The method by which objects of one class
get the properties of objects of another
class is known as
(a) inheritance
(b) encapsulations
(c) abstraction
(d) none of the above
(8) The mechanism that allows same func-
tions to act differently on different classes
is known as
(a) polymorphism
(b) encapsulations
(c) inheritance
(d) none of the above
(9) The existing class can be reused by
(a) inheritance
(b) polymorphism
(c) dynamic binding
(d) abstraction
(10) Composition of objects in a class is
known as
(a) delegation
(b) inheritance
(c) polymorphism
(d) none of the above
(11) A class
(a) binds the data and its related func­
tions together
(b) data and their addresses
(c) contains only functions
(d) none of the above
(12) The major drawback of procedural pro-
gramming languages is
(a) frequently invoking functions from
main()
(b) non security of data
(c) non security of methods
(d) none of the above
C H A P T E R
CHAPTER
OuTlinE
•
•
•
•
•
•
•
•
Basics of C++
2.1 Introduction
2.2 Steps to Create and Execute a C++ Program
2.3 Flowchart for Creating a Source File, Compiling, Linking and Executing in C++
2.4 C++ Environments
2.5 Typical C++ Environment (Borland C++)
2.6 Structure of a C++ Program
2.7 Illustrative Simple C++ Program without Class
2.8 Header Files and Libraries
2
2.1 inTRODuCTiOn
A programmer must know rules and steps to develop programs with C++. Programs given in this
book are developed using Borland’s C++ IDE compiler version 3.0. Let us try to follow the steps
for creating, compiling and running programs under Borland’s C++ IDE compiler.
2.2 STEPS TO CREATE AnD EXECuTE A C++ PROGRAM
For creating and executing a C++ program, one must follow various phases. The C++ program
is created with an editor and saved with extension .cpp. Following this step, compilation and
execution operations are to be performed. The following phases are essential in ‘C++’ when a
program is to be executed in MS-DOS mode.
(1) Create
(2) Save
(3) Compile
(4) Execute.
22 Basics of C++
We would now see the steps in each phase.
(1) Steps for creation of a C++ program
(a) Open the Turbo C++ editor. In this book, the path selected for opening the C++ edi-
tor is C:TURBOC3TCBIN. Executable file TC is to be clicked in BIN file to open
the window of C++.
(b) In the Edit menu section with alt+f, select the New option. A new file is selected
with this procedure.
(c) The program should be written in ‘C++’ editor.
(2) Saving a C++ program
(a) Save the program using the Save option in the file menu with extension .cpp.
The reader may create his/her own folder where programs are to be stored. The
file name does not necessarily include extension “.cpp.” The default extension
is “.cpp.” The user can also specify his/her own extension. The C++ program
includes preprocessor directives.
(3) Compilation of a C++ program
(a) The source program contains statements that are to be translated into object codes.
These object codes are used for execution by the computer. So, compile the source
code with alt+c keys.
(b) If the program contains errors, the programmer should correct it using C++ editor.
(c) If there is no error in the program, compilation proceeds and the translated program
is stored in another file with the same file name and with extension “.obj.” This
object file is stored on a secondary storage device such as the disk.
(4) Linking and running/execution of a C++ program
(a) The linking is also an essential process. It puts together all the program files and
functions that are required by the program. For example, if the programmer is us-
ing pow() function, then the object code of this function should be brought from
math.h library of the system and linked to the main() program. After linking, the
program code is stored on the disk. The program code generated is called the execut-
able code.
(b) Run the executable code file with alt+r, in case of no errors. In case there are errors,
correct the program, and follow steps (1), (2), (3), and (4).
2.3 FlOWCHART FOR CREATinG A SOuRCE FilE, COMPilinG, linKinG
AnD EXECuTinG in C++
The following steps are necessary for execution of a program in C++.
• Write the code for a program and save it
• Compile the program with a compiler
• Link the program with library functions
• Run the program.
A flowchart for implementing the aforesaid steps is given in Figure 2.1
C++ Environments 23
Open any text editor
Write the code for the program
Compile the program
No
Yes
Correct the code
Link with library
Run the program
Syntax
Error / s?
Save the file with .cpp as an
extension
Figure 2.1 Flowchart for creating a C++ program, compiling and linking
The process of compiling, linking and running a program in C++ is elaborated in the following
section.
2.4 C++ EnViROnMEnTS
C++ programs can be implemented on different operating systems such as UNIX, Linux, Win-
dows, and DOS, etc. C++ programs executed under DOS environment can also run successfully
under Windows, because we have to follow the same programming rules on both platforms. Only
the C++ execution environments are different.
Various types of C++ compilers are described below.
(1) GNU C++: The GNU C++ is a compiler and it is available in the source code form. It is
available in different versions.
(2) NDP C++: NDP C++ is also a C++ compiler, i.e. compatible with AT&T C++ 2.0 for
DOS,UNIX , Sun OS, etc.
(3) Oregon C++: Oregon C++ is a C++ compiler compatible with AT&T C++ 2.0 for a
variety of UNIX systems.
(4) Zortech C++ Version 2.1: This compiler has been developed for MS-DOS, OS/2, and
UNIX.
(5) Borland C++: Borland C++ compiler is a combination of two compilers. They areANSI
standard C compiler and C++ compiler. It runs on MS-DOS. Borland C++ includes Tur-
bo Assembler, Turbo Debugger, and Turbo Profiler.
In the following section, brief information for creating, compiling, and executing C++ programs
are described using Borland C++ compiler.
24 Basics of C++
2.5 TYPiCAl C++ EnViROnMEnT (BORlAnD C++)
In this section, brief information is given about the different platforms for C++ implementation,
and execution of C++ programs using Borland C++ compiler under the Windows platform is
described.
STEP 1: OPEn AnY TEXT EDiTOR
Unix/Linux platform:
Use text editors such as Gedit, Kwrite, Medit, ed, VI, etc.
Windows platform:
Use text editors such as Notepad, Wordpad, etc.
Alternately, one can use integrated Borland C++ compiler, which supports its own text editor.
Once Turbo C++ is installed, it automatically creates a directory turboc3 and subdirectory
bin. Follow the path c:turboc3 and click the executable file tc. One can use desktop
shortcut for turboc3. Turbo C++ screen appears, which is blank initially and has a menu bar at
the top, which is shown as follows.
STEP 2: WRiTE THE CODE FOR THE PROGRAM
Write the code to fulfill the requirements of the program, if possible using the proper syntax and
indentation using an editor.
Typical C++ Environment (Borland C++) 25
Alternatively, create a source program using integrated Turbo C++ editor. Go to the File menu
and select New. The file name NONAME00.CPP appears on the screen at the centre of the window.
Check whether your source program is typed correctly. If mistakes are found, correct them.
STEP 3: SAVE THE FilE WiTH .CPP AS An EXTEnSiOn
26 Basics of C++
Now press F2 to save your program or use Save option with .cpp extension. You can change
the file name and save it using the Save option in File menu. In the following window the file
is saved with ABC.CPP.
STEP 4: COMPilE THE PROGRAM
Unix/Linux platform:
Open the terminal window; change the working directory to the directory where the program file
is stored.
Compile the program using the command: g++ filename.cpp
It will display the errors and warnings. If there are any errors and warnings, correct them and
save the corrected file again.
After successful compilation, file a.out will be created in the same directory.
Windows platform:
Use IDE such as Turbo C++.
From the File menu, open the program file and compile it using ‘Compile’option in Com-
pile menu or use Alt+F9.
It will display the errors and warnings. If there are any errors or warnings, correct them and
save the corrected file again, compile again. If program is correct, then the window shows:
• Warnings: 0
• Errors: 0
After successful compilation, a file filename.obj will be created in the same directory. The fol-
lowing window shows the compilation of a program named ABC.CPP.
Random documents with unrelated
content Scribd suggests to you:
"I have told you, madame," said the doctor, showing a vial containing
a dark liquid, "this potion will restore this child to consciousness, will
light up the faint spark of intelligence which still remains, perhaps. Then
the sight of the person who exercises on her so strange an influence
may work a miracle, for, alas! madame, nothing but a miracle can bring
your child back to life."
"I know it, I know it," said Catherine, choking back her tears, "I am
prepared for the worst. But, tell me, the potion,—what effect will it
have?"
"I can answer for its immediate effects; but not for the consequences
that may follow."
"What is to be done? Mon Dieu! what is to be done?" cried Catherine,
in accents of anguish.
"Do not hesitate, madame," I said; "since all hope is gone, accept the
only chance that remains!"
"I am of the same opinion, do not hesitate, madame," said Frank,
who shared our emotion.
"Proceed, monsieur," whispered Madame de Fersen, in an accent of
desperate determination; and she knelt down by her child's cot.
Her lips moved in prayer.
She, Frank, and I fixed upon the doctor sorrowing and apprehensive
looks.
He alone was calm, as with slow and silent steps he approached
Irene's bedside.
At the sight of his tall figure, his austere countenance, his long white
hair, his peculiar garb, one might have supposed him a man gifted with
some occult power, ready to perform by a potion some mysterious
charm.
He poured into a golden spoon a few drops of the liquid contained in
the vial.
Madame de Fersen took it, and approached the spoon to the child's
lips.
But her hand trembled to such an extent that the liquid was spilled.
"I am afraid," said she, with a frightened look.
She gave back the spoon to the doctor. He filled it once more, and
with a firm hand put it to Irene's lips.
The child swallowed it without reluctance.
It is impossible to express the intense alarm, the mortal anguish, with
which we watched the effects of the potion.
The doctor himself, eagerly bending over the bed, watched Irene's
face with anxious eyes.
Soon the potion began to work.
By degrees, Irene began moving her arms and hands, and her cheeks
assumed a faint tinge of colour. Several times she quickly turned her
head on her pillow, moaned piteously, closed her eyes, and then opened
them.
The lamp was in front of her, and the bright light seemed painful, for
she covered her eyes with her hands.
"She sees! she sees!" cried the doctor, with an alacrity that seemed to
us of good omen.
"She is saved!" exclaimed Catherine, clasping her hands, as if in
thanks to Heaven.
"No rash expectation, madame!" said Doctor Ralph, austerely and
almost harshly. "I have already told you this semblance of life is
deceptive. It is like galvanism which gives motion to a dead body, and a
breath may snap the invisible cord which binds this child to life." Then,
turning to me, he added: "It will be your turn, monsieur, presently to
endeavour to strengthen that feeble thread. I solemnly declare, if that
child lives, which, alas! I scarcely dare to hope, it is to you she will owe
it, for known science does not work such miracles."
"God alone can work them," said Frank, in a solemn voice.
"Or certain mysterious and magnetic influences which one must
concede without understanding them," added the doctor.
The stimulus of the potion upon Irene became more and more
apparent. Two or three times she sighed deeply, held forth her arms,
and then murmured, in a feeble voice: "Mother! Arthur!"
"Now," said the doctor, "take one of the child's hands in yours,
monsieur, and let the other be in her mother's; come as close to her as
possible, and call her, softly, slowly, so that the sound may have time to
reach her feeble hearing."
I took hold of one of Irene's hands, her mother held the other.
Her hand was cold and moist.
I leaned over Irene. Her big eyes, looking still larger since her illness,
wandered around as if in search of some one.
"Irene—Irene—I am here," I said, in a low voice.
"Irene—my child—your mother is here also," said Catherine, with an
accent of passionate and fearful anxiety impossible to describe.
At first the child did not seem to hear us.
"Irene—it is your friend—it is Arthur and your mother. Do you not
hear her?"
"Your mother—mon Dieu! your mother is near you!" repeated
Catherine.
This time the child's look no longer wandered. She moved her head
suddenly, as if a sound from afar had reached her.
"How is her hand?" inquired the doctor, in a whisper.
"Still cold," I answered.
"Still cold," rejoined the mother.
"That is bad, you are not yet en rapport,—continue."
"Irene—dear child—angel—do you hear me? It is I—Arthur," I
whispered.
Irene raised her eyes, and met mine fastened on her.
I had often heard magnetic attraction spoken of, and this time I
experienced its action and reaction.
I fixed an eager and despairing glance upon Irene. By degrees, as if
her eyes took life from mine, they lost their dullness, they became clear,
bright, beaming with intelligence.
On her countenance, returning to life, I could follow the progress of
her thoughts, of her awakening mind.
She threw out her arms, and an angelic smile lighted on her lips.
Too weak to raise her head, she sought her mother with her glance.
Catherine bent over the bed, still holding, as I did, one of Irene's
hands.
After looking at us for a moment, the child gently brought together
her mother's hand and mine; her eyes suffused with tears, and she wept
freely.
When my hand touched Catherine's, my heart received an electric
shock. For a moment I heard no more, I saw no more. I held Catherine's
and Irene's hands in mine, and became unconscious of the contact.
It seemed to me that a flood of electricity surrounded us, and
blended us in one.
This impression was deep, inexplicable, almost painful. When I
regained consciousness, I heard the doctor exclaiming, "She has shed
tears! she is saved!"
"You have given her back to me," said Catherine, falling on her knees
before me.
CHAPTER XXIII
THE GROVE
This healing crisis saved Irene.
During the month of convalescence I left her neither by day nor by
night.
In the early days of spring, Doctor Ralph urged Madame de Fersen to
go to the country with her daughter, and recommended the vicinity of
Fontainebleau.
Madame de Fersen having seen a very pretty cottage, called the
Grove, had secured it, and the necessary repairs having been made, it
was decided we should take up our residence there the first days of May.
If my continuous abode at Madame de Fersen's house had been
known, it would have provoked the most odious comments.
Consequently, the morning after the crisis, which had proved so
favourable to Irene, I told her mother that she must forbid access to her
apartment to every one, with the exception of the doctor, the nurse, and
one of her maids, on whose discretion she could rely.
I had occupied during Irene's illness a vacant entresol, of which the
windows opened on an uninhabited piece of ground, thus my return to
Paris and my presence at Catherine's house was unknown to every one.
Madame de Fersen took to Fontainebleau only the same people who
had been in attendance on her during her little girl's illness, the nurse
and two maids. The rest of the household remained in Paris.
She asked me to follow her to the Grove in two days.
She took her departure.
The next morning I received from her most detailed instructions
about finding my way to the small park gate at the Grove.
At the appointed hour I was at that gate; I knocked, and it was
opened.
The sun was about setting, but it still threw some warm rays across
the green lacework and violet clusters of an arbour of glycynia, under
which Catherine was waiting for me with Irene, whose hand she was
holding.
Was it intentional, or was it mere chance? I know not, but like the
day when for the first time I saw her on board the Russian frigate,
Catherine wore a gauzy white gown and a lace head-dress ornamented
with a spray of red geranium.
The trials through which she had passed had made her fall away, but
she was still beautiful, and even more lovely than beautiful. Her figure,
as heretofore, was elegant and stately; her countenance noble, gracious,
and pensive; her large, soft eyes of a perfect blue were fringed with
long, dark lashes; the heavy tresses of her jet black hair framed her
brow, lofty and sad, and her face paled by sorrow.
Irene, like her mother, was dressed in white; her long dark hair was
tied with ribbons and fell to her waist, and her lovely face, though still
pensive and sad, showed scarcely any traces of her recent sufferings.
Catherine's first impulse was to take her child in her arms, and,
placing her in mine, she said, with great emotion, "Is she not now your
Irene also?"
And amid her tears her eyes shone with joy and gratitude.
There are emotions which one cannot attempt to describe, for they
are as vast as the infinite.
This first outburst of happiness passed, Madame de Fersen said to
me, "Now I must show you to your apartment."
I offered Catherine my arm, Irene took my hand, and allowed them
to lead me.
For some time we kept silent.
After following a long avenue, rapidly becoming dark as the sun sank
below the horizon, we came to a clearing on the outskirts of the wood.
"Here is your cottage," said Madame de Fersen.
My cottage was a sort of Swiss chalet, half hidden in a mass of pink
acacias, of linden-trees and lilacs. It was built on the edge of a small
lake, on a foundation of great boulders of that flinty rock found in the
neighbourhood of Fontainebleau. This structure having been erected as
a point of observation, every advantage had been taken to make the
most of its charming position.
A thick carpet of periwinkles, of ivy, of moss, and wild strawberry
covered almost entirely the whitish rocks, and from each cranny
sprouted a tuft of iris, of rhododendron, or heather.
On the other side of the lake a beautiful lawn, surrounded by the
woods, rose in a gentle incline up to the front of the house occupied by
Madame de Fersen, and which might be seen from a distance.
The sight was limited on all sides by a ring of verdure, formed by the
thick woods surrounding the high walls of the park, and hiding them
completely.
One might have wished more variety in the prospect; but as our life
at the Grove was to be surrounded by the most profound mystery, this
extensive and impenetrable barrier of leafage was very precious.
After a few minutes we reached the foot of the steps leading to the
cottage. Madame de Fersen drew a small key from her belt and opened
the front door.
At a glance I saw that she had been the presiding genius in the
arrangement of the two rooms. Everything was of excessive but elegant
simplicity. I found flowers on every side; also a piano, a painter's easel,
and some books which she had heard me mention as my favourites.
Pointing out to me an ebony cabinet frame with doors richly inlaid
with mother-of-pearl, Madame de Fersen asked me to open it. On one
side I found the exquisite sketch which Frank had made of the dying
Irene, and on the other side a recent portrait of Irene also painted by
Frank.
I took Catherine's hand and carried it to my lips, with a feeling of
inexpressible gratitude.
She herself pressed her hand to my lip with an impulse full of
tenderness. She then turned and passionately embraced her child.
I closed the panel, still more touched by this mark of Catherine's
remembrance, for I had expressed to her my views regarding portraits
exposed to the gaze of all.
When we left the cottage, the purple and gold of the dying sun was
mirrored in the bosom of the lake. The acacias were dropping their
roseate and fragrant petals. No sound was heard; on all sides the
horizon was bounded by dark masses of verdure; we found ourselves in
the midst of the most profound solitude, the most peaceful, the most
mysterious.
Impressed by the sight of this sad and touching picture, Catherine
leaned on the balcony of the chalet, and remained a few minutes
plunged in reverie.
Irene sat at her feet, and began to gather roses and honeysuckle to
make a bouquet.
I leaned against the door, and could not help feeling a pang of
anguish as I looked upon Madame de Fersen.
I was going to pass long days near this woman, so passionately
loved, and delicacy forbade my speaking one word of this deep and
ardent love, which circumstances recently had combined to increase.
I knew not if I was beloved, or, rather, I despaired of being loved; it
seemed to me that fate, which had brought Madame de Fersen and me
together, by the death-bed of her child, during a month of terrible
anguish, had been too tragic to end in so tender a sentiment.
I was absorbed in these sad thoughts, when Madame de Fersen
made a quick movement, as if she were aroused from a dream, and said
to me, "Pardon me, but it is so long since I breathed air so fragrant and
invigorating that I selfishly enjoy this lovely nature."
Irene divided her bouquet in two, gave one half to her mother, the
other to me, and we then started towards the house.
We reached it after a long walk, for the park was very extensive.
CHAPTER XXIV
DAYS OF SUNSHINE
THE GROVE, 10th May, 18—.[6]
It is eleven o'clock; I have just left Madame de Fersen. Here am I in
the chalet, which, henceforward, I am to occupy near her!
I experience a strange emotion.
Events have succeeded each other with such rapidity, my heart has
been torn by such conflicting passions, that I feel the necessity of
reviewing my memories, my desires, and my hopes.
I therefore resume my journal, interrupted after my departure from
Khios.
My thoughts press so confusedly upon my brain that I hope to clear
them by writing. I act like those who, unable to make a mental
calculation, are obliged to have recourse to pencil and paper.
What for me will be the end of this love? Doctor Ralph has formally
declared to Madame de Fersen that, for a long time yet, my presence is
indispensable to Irene's perfect recovery, and that, for two or three
months longer, it was absolutely necessary to soothe the child's
imagination, and not give her the slightest shock or the least sorrow,
these emotions being the more dangerous for her in that they were so
profoundly concentrated.
Doctor Ralph attributes the attraction which I have for Irene to
magnetic and mysterious affinities and he cites many examples, both
among human beings and animals. He is unable, however, to offer any
explanation of this. As I said, this attraction places me in a singular
position.
The effect of my presence or absence upon this child is a proven and
undeniable fact. For the past year Irene has had three or four attacks,
sometimes slight, others serious and almost fatal, whose sole origin was
her grief at not seeing me, and, above all, at not seeing me near her
mother; for the nurse has since told me that even our meetings at the
Tuileries did not quite satisfy Irene, who pined for the time spent on
board the frigate.
My presence, therefore, is, one may say, the tie that binds Irene to
life.
Were it not for my love, my passion for Catherine, were it not for the
deep interest her child inspires in me, this imperious obligation to remain
ever at Irene's side would be both painful and embarrassing.
But I worship her mother! When I compare other passions which I
have experienced to that which she inspires, I find this the truest of all;
and, seeing her daily, brought near her by the most startling and
mysterious circumstances, most apt to bring the most passive love to a
point of exaltation, I still must be silent; Catherine for me must be
sacred as a sister, as a friend!
Can I, in the name of my past devotedness, in the name of the fatal
influence I exercise over Irene, approach Catherine, professing my love,
and expressing my hopes?
It would be base, it would be despicable.
And if the unhappy mother were to think—oh, Heaven!—that I
demanded her love as the price for my presence near her child!
Ah, this thought is horrible!
My resolution is taken, irrevocably taken.
Never shall a word of love pass my lips.
THE GROVE, 11th May, 18—.
My best deeds bring me bad luck,—one reason the more for keeping
silent.
This morning the newspapers were brought in.
Madame de Fersen opened one, and began to read.
All at once she ceased to read, I saw her shiver and blush deeply;
then, with an expression of dumb surprise, lowering her hands to her
knees, she shook her head, as if she were saying, "Is this really
possible!"
Looking at me with eyes filled with tears, she quickly rose, and left
the room.
Not knowing what might have caused this keen emotion, I picked up
the newspaper, and the following lines soon explained to me Madame de
Fersen's dismay.
"It is well known that a month ago the firm —— & Co. failed for a
sum amounting to several millions. The head of the firm secretly
embarked for the United States. A few creditors, warned by alarming
rumours as to the solvency of the firm, were in time to withdraw a
portion of their funds. M. Dumont, business agent of M. le Comte de
——, involved in this bankruptcy to the amount of one hundred and fifty
thousand francs, has not been equally fortunate; although he had come
to Havre to ward off this disaster, he was not provided with the
necessary papers, and as the bankruptcy was considered fraudulent, he
laid his complaint before the district attorney, but in view of the assets
amounting to scarcely eighty thousand francs, the numerous creditors of
the firm —— must look upon their funds as lost."
Madame de Fersen knew of my hurried departure for Havre, for her
courier had overtaken me before I reached that town. I had returned
immediately, and the date of my return coincided with that of the
bankruptcy. It was therefore evident to Catherine that my eagerness to
return to the dying Irene was the sole cause of the severe loss I had
sustained. Thus now, more than ever, should I appear to demand a
reward for my sacrifices.
While mechanically skimming the newspaper, beneath the article
which I have quoted, I came upon the following paragraph, which also
concerned me.
The paper which I was reading was a semi-official journal, and might
be considered well informed.
"Many changes are imminent in our corps diplomatique. Among those
mentioned as likely to be called to a prominent position in foreign affairs
is M. le Comte Arthur de ——, who, though still young, has strong claims
to this favour on account of his travels, his researches, and the
conscientious work to which he has devoted himself for some time past,
as chief secretary of his Excellency the Minister of Foreign Affairs. These
particulars, for whose accuracy we can vouch, prove clearly that when
high birth and the advantages of fortune accompany an eminent and
recognised capacity, everything may be expected from the favours of the
king's ministry."
This article evidently emanated from the office of M. de Sérigny, who
thought, perhaps, that it would give me pleasure if, during my absence,
he asked the king some favour for me.
I must confess, this piece of news left me indifferent, and I went in
search of Catherine.
I found her in an avenue of the park.
"I know all," she said, holding out her hand. "Another sacrifice," she
continued, raising her eyes to heaven. "And I, what have I done for
him?"
These words went to my heart, and produced so great, so sweet an
emotion, that, in spite of myself, my hopes once more were aroused,
but, controlling my thoughts, and wishing to change the subject, I said:
"Do you not congratulate me on my future successes?"
She looked at me in amazement.
"What successes?"
"Have you not read to-day's paper?"
"Yes, I have. But of what success are you speaking?"
"They say in this paper that very soon I shall be called to a very
important position at the Foreign Office."
Catherine, without appearing to have heard me, replied:
"Will you make me a promise?"
"What is it?"
"I shall send Irene to you to the chalet, but I do not wish to see you
to-day. You will not be vexed with me?" she said, sadly, to me, holding
out her hand.
"No, certainly not," I said, much surprised, however, at this sudden
determination.
THE GROVE, 13th May, 18—.
How long is it since this journal was interrupted? I know not. I cannot
remember.
Besides, what do I know now? What do I remember?
All that has happened, is it not a dream, a dream so dazzling that I
ask myself where is the limit of reality? Where ends the dream? Where
commences the awakening?
Dream, memory, awakening! These are vain words, and faded, which
I used before this day.
I wish now for new words to describe what I had never before felt.
Not only does it seem to me impossible to use the words of other
days to describe my feelings of to-day, it seems to me a blasphemy, a
profanation.
Am I not the dupe of a delusion? Is it I, my own self, who is writing
this at the Grove, in the chalet?
Yes, yes, it is my own self. I am looking at the clock which points to
the hour of five. I see the lake reflecting the rays of the sun. I hear the
trees rustling in the breeze. I scent the fragrance of the flowers, and in
the distance I see her dwelling,—hers.
It is not, then, a dream?
Let me see, let me gather my thoughts, let me go back step by step
to the source of that torrent of happiness which intoxicates me.
What day is this? I know not. Ah, yes, it is Sunday. She went to mass
this morning, and there she wept, she wept abundantly.
Blessed be those precious tears!
But when did we receive those papers? Ah, here they are,—it was the
day before yesterday.
The day before yesterday! 'Tis strange! If years had passed since that
day it would not seem to me further away!
Between the past of yesterday, which was almost indifferent to us,
and the present to-day, which is all in all to us, is there not the distance
of centuries?
Yes, it was the day before yesterday that Catherine begged me to
leave her to herself.
I obeyed her wishes, but felt very sad.
Irene came to play on the steps of the chalet.
The dinner bell sounded.
Instead of appearing at table, as usual, Catherine sent word begging
me to dine by myself, for she was suffering.
In the evening the air was sultry. Catherine came down to the
parlours. I found her looking very pale.
"I am stifling," she said, "I am restless, nervous, agitated, the
weather is so stormy."
She then asked me to give her my arm, as she was going to walk in
the park. Contrary to her custom, she requested Madame Paul, Irene's
nurse, to follow us with the little girl.
We followed the winding avenue of the woods, and soon came upon
the arbour, covered with glycynia, where she had waited for me with
Irene the first day of my arrival at the Grove.
I know not whether it was emotion, or fatigue, or indisposition, but
Catherine complained of feeling tired, and seated herself on a bench.
The sun had just set; the sky was covered with clouds, gilded by the
last rays of the sun. Almost continuously the entire hemisphere was
illumined with vivid flashes of summer lightning, which Irene watched
with a curious and tranquil air.
Catherine did not speak, and seemed deeply absorbed.
Twilight had begun to darken the woods, when Irene, who was
resting on her nurse's lap, fell asleep.
"Madame," said Madame Paul, "Mlle. Irene is falling asleep, and the
doctor was very particular that she should not be exposed to the damp
evening air."
"Let us go home," said Catherine, as she rose.
She felt so weak that she leaned on my arm with her whole weight.
We walked a few steps, but very slowly; Madame Paul was in front
with Irene.
Suddenly I felt Catherine giving way, and she said, in a broken voice,
"I cannot take another step, I am prostrated."
"Just make an effort," I said to her, "to reach the chalet, which is
close at hand, and you can rest on the bench at the door."
"But, Irene!" she exclaimed, anxiously.
A turn in the road hid the nurse, who was already some way in
advance.
I supported Catherine, and a few seconds later she was seated at the
entrance of the chalet.
The threatening clouds had dispersed; at our feet we saw the lake
reflecting the stars as they made their appearance; the perfume of
flowers, rendered more acute by the warm and sultry weather,
permeated the atmosphere; there was not a breath of air, not a sound.
The night was so soft, so balmy and clear, that in the uncertain light I
could perfectly distinguish Catherine's features. My whole being seemed
concentrated in my heart, which was beating violently.
Like Catherine, I felt overpowered, unnerved, by the warm, perfumed
air which surrounded us.
Madame de Fersen was seated, resting on cushions, her head leaning
on her hands.
The calm was so intense that I could hear Catherine's panting breath.
I fell into a deep reverie, at once sad and blissful.
Never, perhaps, would I have a more favourable opportunity to
unbosom myself to Catherine; but my scruples, and the dread of
seeming to ask reward for a service rendered, kept me silent.
Suddenly she exclaimed:
"I implore you, do not leave me to my thoughts; let me hear your
voice. Tell me all you wish, but speak to me; in the name of Heaven,
speak to me!"
"What shall I say?" I replied, submissively.
"What matters!" she cried, clasping her hands in supplication; "what
matters! only speak to me, drive from me the thoughts which possess
me, have pity, or, rather, be pitiless,—accuse me, overwhelm me, tell me
I am a thankless, selfish woman, base enough not to have the courage
to be grateful," she continued, with increasing excitement, as if a secret
long suppressed was now escaping her. "Do not soften your reproaches,
for you cannot tell how deeply your resignation wounds me, you cannot
tell how I long to find you less generous. For what can be said of a
woman who meets a true, discreet friend, and for six months permits
him to surround her with the most delicate, most assiduous, and
respectful attentions, sees him devote himself to the least whims of her
poor, suffering child, and who, one day, in all thanklessness, and for the
idlest and most puerile of motives, coldly dismisses this friend? And this
is not all. When this woman, in a terrible dilemma, again has need of
him,—for she knows he alone can save her child's life,—she forthwith
recalls him, well aware that she can demand everything from the self-
denial of this brave heart; and he, sacrificing all, instantly returns to
draw this child from the very jaws of death!"
"Hold, I pray you! Let us not recall these sad memories, let us only
think of our present happiness," said I.
But Catherine appeared not to hear me, and continued with an ever
increasing excitement which alarmed me:
"This friend, so good, so noble, has he ever attempted by a single
word to speak of his admirable conduct? He has been the protecting
genius of this woman and her child when both were suffering; and when
he has saved them,—for to save the child is to save the mother,—he
goes, proudly, silent, and reserved, happy doubtless in the good he has
done, but seeming to fear the thanklessness or disdain the gratitude he
has inspired."
Catherine's voice was growing more and more broken and gasping. I
was almost frenzied by her words, but they seemed to me drawn from
her by feverish excitation, and contrasted so forcibly with her habitual
reserve that I feared her reason, until now so strong and clear, had
yielded to the tardy reaction of the terrible experiences which had
shaken her for the past six weeks.
"Catherine, Catherine!" I exclaimed. "You are too passionately
devoted to your child for me ever to have doubted of your gratitude,—
my dearest, most precious reward."
Catherine heard my reply, for she alluded to my words as she
continued in a still more passionate accent:
"Oh, yes, yes; tell me, then, that the intoxicating, invincible sentiment
that invades me at this moment is gratitude; tell me that nothing is
more sacred, more holy and legitimate, than what I feel. A woman has
certainly the right to devote her life to him who has restored her child to
her, more especially when he, as generous as he is considerate, has
never attempted to say one word of his hopes; therefore, is it not for
her—for her—to come to him, and ask with joy, with pride, How can I
ever reward so much love?"
"By returning it!" I exclaimed.
"By confessing that I have always returned it," said Catherine, in a
subdued voice.
And her hands languorously fell into mine.
THE GROVE, 16th May, 18—.
Woe! Woe!
Since yesterday I have not seen her. Doctor Ralph arrived last night.
He found her in great danger. He attributed this devouring fever, this
terrible delirium, to reaction from the anguish which the unfortunate
woman had repressed during her child's illness.
He does not know all.
Ah, her remorse must be terrible! How she must suffer, and I am not
there, by her side,—and I cannot be there.
Ah, yes, I love her, I love her with all my strength. This intoxicating
memory, which yesterday made me almost frenzied with love, to-day I
curse it!
The sight of Irene hurts me. This morning the child came towards
me, and I repulsed her. She is fateful to her mother, as, perhaps, she will
be fateful to myself.
Doctor Ralph has just left me; there is no change for the better.
I observed a strange difference in him. This morning, on his arrival,
he gave me his hand as usual cordially; the austere expression of his
face generally assumed a look of benevolence on meeting me. This
evening I gave him my hand, he did not grasp it. His glance seemed to
me severe, interrogative. After having briefly informed me of the state of
Catherine's health, he coldly left the room.
Can Catherine have betrayed herself in the wanderings of fever?
This thought is dreadful. Happily, there is near her no one but Irene's
nurse and Doctor Ralph.
But what matter! what matter! This nurse is only a servant, and this
doctor is but a stranger! And is she, so proud, because heretofore she
had a right to be so, condemned henceforth to blush before these
people!
If she has spoken, she is not aware of it, perhaps may never know it,
but they know it, they, perhaps, have her secret and mine.
If with a word one could annihilate two persons at once, I believe I
would utter that word.
THE GROVE, 17th May, 18—.
What is to be done, what will become of us, if Catherine so rapidly
gets worse? Doctor Ralph will no longer take the sole responsibility, he
will call in some consulting physicians, and then—
I cannot continue to write, my sobs stifle me.
This morning something very strange happened.
When the doctor announced to me that Catherine was worse, I came
back here in the chalet; I wished to write down what I felt, for I cannot
and will not confide to any one my joys and sorrows; so, when my heart
overflows with grief or happiness, it is a great relief to me silently to
confide to this journal.
When I heard of Catherine's renewed danger, my sufferings were so
great that I wished to write, that is, to pour out my anguish.
This was impossible. I could only trace with a trembling hand the few
lines at the head of this page, but was soon interrupted by my tears.
Then I went out into the park.
There, for the first time, I regretted—oh, bitterly regretted—that I
possessed neither religious faith nor hope.
I might have prayed for Catherine.
There is certainly nothing more heartrending than to recognise the
utter futility of addressing prayers to Heaven for a beloved being whom
you fear to lose. In prayer you have some minutes of hope, you are
fulfilling a duty, your sorrow at least has a language, which you believe
is not quite barren.
But not to be able to say to any human or superhuman power, "Save
her!" It is terrible.
I so painfully felt this helplessness, that in despair I fell on my knees,
without having consciousness to whom my prayer was addressed. But
firmly convinced, in that momentary hallucination, that my voice would
be heard, I cried aloud: "Save her! Save her!" Then, in spite of myself, I
experienced a glimmer of hope, I felt the consciousness of a duty
fulfilled.
Later I blushed for what I called my weakness, my puerility.
Since my mind could not grasp, could not believe, the assertions
which constitute the various human religions, what God was I imploring?
What power had succeeded in tearing from me this prayer, this last
cry, this the last utterance of despair?
The crisis which the doctor feared did not take place.
Catherine is no better, but she is not worse, and yet her delirium
continues.
Doctor Ralph's coldness towards me is still excessive.
Since her mother's illness, Irene has given frequent proofs of
tenderness and feeling, which, though childlike, are serious and resolute
like her character.
This morning she said to me: "My mother suffers very much, does
she not?"
"Very much, my poor Irene."
"When a child is suffering, her mother comes to suffer in her stead,
so that the little one may not suffer any more, is it not so?" she inquired,
gravely.
Astonished at this reasoning, I looked at her attentively without
replying. She continued:
"I wish to suffer in my mother's place, take me to the doctor."
This childish trait, which, under other circumstances, would have
made me smile, gave me a heart pang, and I kissed Irene to conceal my
tears.
THE GROVE, 17th May, 18—.
There is hope; the delirium ceases; an alarming prostration has
followed. Doctor Ralph dreaded the heat of her fevered blood. Now he
fears excessive languor, heart failure.
Her consciousness has returned. Her first utterance was her child's
name.
The nurse told me that the doctor had not yet allowed Irene to go
near her mother.
Twenty times have I been on the point of asking Madame Paul if
Catherine had inquired after me, but I dared not.
THE GROVE, 18th May, 18—.
To-day, for the first time, Doctor Ralph permitted the nurse to take
Irene to her mother.
I waited with anxious and irritable impatience for the moment when I
would see Irene, hoping from her to have some particulars about her
mother, perhaps a word, a remembrance, from Catherine.
Once returned to consciousness, I know not what course Madame de
Fersen will take towards me.
During the paroxysm of remorseful despair which follows a first fault,
a woman often hates the man to whom she has succumbed; she
overwhelms him with reproaches as violent as her regrets, as vehement
as her sorrow; it is on him alone the sole responsibility weighs for their
guilt; she is not his accomplice, but his victim.
If her soul has remained pure, notwithstanding that for a moment
she was involuntarily led astray, she takes the sincere resolution never
again to see the man who has seduced her, and to have to weep over
one sole betrayal, one sole defeat.
To this resolution she at first remains faithful.
She seeks, not to excuse, but to redeem her error, by the rigorous
fulfilment of her duties; but the remembrance of her fault is there, ever
there.
The more noble the heart, the more austere the conscience, so will
the remorse be the more implacable. Then, alas! she suffers terribly, the
poor creature, for she stands alone, and is compelled in secret to devour
her tears, while to the world she still wears a smile.
Sometimes, again, she becomes frightened at her isolation, at that
wordless concentration of her grief, and she resigns herself to ask for
comfort and strength of the man who is the cause of her fall. She then
implores him, for the sake of her remorse, to forget a moment of
madness, and to be for her no more than the truest of friends, the
confidant of the sorrows he has brought upon her. But, alas! almost
always the unhappy woman has still more tears to shed.
Man, with the coarser instincts of his sex, does not realise the
sublime struggle which woman endures between love and duty. The
incessant torture, the menacing terrors aroused in her by the
remembrance of outraged religion and family honour, these dreadful
tortures are treated by man as ridiculous whims, as childish scruples, or
the absurd influence of the confessional.
If the struggle is prolonged, if the unhappy woman passes her life in
efforts to conceal a sorrow caused by her dishonour, and valiantly resists
the commission of a second fault, the man is irritated, and revolts
against these pruderies which wound his self-love and his eager and
brutal passion to the quick; for one last time he reviles her virtue, her
sorrows, and her courage by saying to this miserable woman that her
return to high principles is somewhat tardy. Frenzied by a base desire for
revenge, he at once rushes with his cynical nature to make a notorious
display of some other intrigue.
He has been loved, he is still beloved! A virtuous and beautiful
woman has jeopardised, for his sake, her happiness, her future, and that
of her children! while he basely recoils from the least sacrifice.
How comes it that this man is so worthless, and yet so worshipped?
Because woman loves man more for the qualities she attributes to him,
and with which her sensitive nature adorns him, than for those he really
possesses.
If, on the contrary, by a rare exception, a man realises all that is
saintly and beautiful in this remorse, if he endeavours to comfort the
sorrow of which he is the origin, the woman's gentleness and
resignation may prove for her another pitfall.
Catherine,—will she be pursued by incessant remorse?
Like those women who, from an insatiable yearning for sympathy, or,
with the chastity of sorrow, conceal their woes, and make only a display
of their joys, will Catherine leave me in ignorance of the anguish she
suffers?
Knowing her as I do, I believe, after I have seen Irene, and gathered
from her the substance of her conversation with her mother, I shall be
able to divine Catherine's sentiments towards me.
Hence I look forward with eager impatience to the child's visit.
Heaven be praised! I see her running, holding in her hand a bouquet
of roses.
My heart did not deceive me; Catherine sends it to me.
She forgives me my happiness.
[6]Arthur, according to his custom, introduces here some
fragments from his journal, interrupted after leaving Khios, and
doubtless, resumed on his arrival at the Grove. The preceding
chapters are intended to fill the gap separating the two periods,
during which time Arthur appears to have neglected to keep his
memorandum.
CHAPTER XXV
A WOMAN IN POLITICS
Here come to an end the fragments of the journal I formerly
wrote at the Grove.
During the four months which followed Catherine's confession of
her love, and which we passed in this total isolation, my life was so
engrossed by the delights of our ever growing love that I had
neither time nor inclination to make a record of emotions so
entrancing.
Catherine confessed to me that she had felt greatly attracted to
me ever since our departure from Khios.
I asked her why she had treated me so harshly on one occasion,
when she had requested me not to see her little girl any more. She
answered that her despair at feeling herself at the mercy of the
affection I inspired, added to her jealousy and grief when she saw
me smitten by so giddy a woman as Madame de V——, had alone
decided her to put an end to the mysterious intimacy of which Irene
was the bond, however painful to her was this determination.
Later on, when she learned of the termination of my supposed
intrigue with Madame de V——, and finding that absence, instead of
diminishing, only increased the power I had gained over her, she
endeavoured to renew our former relations. Moreover, Irene
commenced to be seriously affected by my absence. "Love is so
inexplicable in its contrasts and its sensitiveness," said Catherine to
me, "that this very reason, added to your seeming coldness and
disdain, made me hesitate frankly to come to you, fearing that this
step might have appeared to you simply dictated by my anxiety for
my child's health.
"The condition of that poor child became so much worse that I
resolved to conquer my timidity and tell you all at that ball at the
Tuileries, but your greeting was so freezing, your departure so
abrupt, that it became impossible for me. The next day I wrote to
you; you did not answer. It was not, alas! until Irene's life was
despaired of that I dared once more to write to you at Havre! God
only knows with what admirable generosity you responded."
After the first bitterness of her remorse, Catherine's love for me
became calm, dignified, almost serene.
One felt that, having exercised all her might to resist an
unconquerable passion, this woman was prepared to endure with
courageous resignation the consequences of her weakness.
The four months we spent at the Grove were for me, for her, the
ideal of happiness.
But wherefore speak of happiness? This is now but Dead Sea
ashes!
What matter, alas! Let me continue the sad task I have imposed
upon myself.
When I was able to snatch some moments from the love which
engrossed me, I wrote to M. de Sérigny to thank him for his good
intentions towards me, which I had learned from the article in the
official newspaper, and informed him that I would be absent for
some months yet, that I was unable to disclose to him my place of
abode, but begged him, in case any one inquired of him for me, to
answer in such a way as might lead people to infer that I was in a
foreign country.
In the month of September Catherine heard that her husband
would return towards the close of the year, and informed me that
she intended returning to Paris.
Catherine's intention surprised and grieved me.
We had considerably discussed whether or not I should resume
the duties I had taken upon me with M. de Sérigny.
Catherine had persistently urged me to do so.
I vainly represented to her that those hours devoted to
uncongenial work would be stolen from our love, and that I should
find very tedious an occupation which I had sought simply as a
distraction to my grief. In vain I told her that all the correspondence
with which I was entrusted treated of the most futile subjects, and
in no way interested me.
To this she replied that at no distant period questions of the
greatest importance would necessarily be discussed in high political
spheres, and that I would then regret having abandoned that
position. She felt so proud, so happy, of the distinction drawn upon
me by the king's recognition of my merits, she said, she so gloried in
my success, that I ended by promising to do as she wished.
It was therefore decided between us that I should resume my
position with M. de Sérigny.
To avoid returning to Paris at the same time as Madame de
Fersen, and in order that people might suppose I had been travelling
for some time, I left the Grove for London, and came back to Paris,
where I found Catherine on my arrival, after fourteen days' sojourn
in London.
M. de Sérigny had ably fulfilled my wishes, and in society it was
generally supposed that an important foreign mission had been the
cause of my absence from home.
The minister seemed quite pleased at having me once more
sharing his labours; for the king, he told me, had frequently inquired
as to the period of my return, expressing his regret that the briefing
of despatches was no longer made by me.
To the eyes of the world, I did not at first visit Madame de Fersen
more assiduously than before our sojourn at the Grove; but little by
little my visits became more frequent without being so noticeably.
My character as an ambitious man, wholly absorbed by state
affairs, and Madame de Fersen's high reputation were too firmly
established in public opinion for society, so constant to its routine
habits, not to accept this situation; and appearances very contrary to
these ideas would have been needed to make it change its point of
view towards us.
The impenetrable mystery surrounding our love redoubled it.
I frequently regretted our radiant days at the Grove,—days so
calmly happy, so peaceful,—but on the other hand, in Paris, when I
exchanged with Catherine a tender glance, unperceived by all, I felt
that joyful pride which one always experiences when in possession
of a secret at once formidable and enticing, from which depends the
honour, the existence, and the future of the woman beloved.
Some time before his departure, M. de Fersen had confided to me
that his wife had become indifferent to political matters, which until
then had engaged her attention to a great extent.
After returning to Paris I noticed, with astonishment, that
Catherine by degrees resumed her former relations.
Her salon, where I visited assiduously, was, as formerly, the
habitual meeting-place of the corps diplomatique. Before long,
subjects which were spoken of daily became so serious that, with
the exception of the ministers and some influential speakers of the
two chambers, the elegant and frivolous French society disappeared
almost entirely from the gatherings at Madame de Fersen's.
Although serious, these discussions had no true importance;
either they rose so high as to become abstract and impracticable
theories, or they descended to such paltry and positive interests that
they became frivolous and narrow.
The discussions were as infinite and barren as ever on this well-
worn theme: "Would the Restoration resist or yield to democratic
influence?" etc.
Catherine always surprised me by the subtlety of her intellect and
the liberal tendencies of her convictions. One of her great triumphs
was in demonstrating the advantages which France would derive by
preferring the Russian to the English alliance. When I complimented
her on this subject, she laughingly told me that I was France, and
that the sole secret of her eloquence was that.
I might as well have answered that she was my diplomacy; for to
please her I conquered my profound aversion to the European
gossip of the diplomats who habitually met at her house, and I
persevered with my work under M. de Sérigny. Perhaps, also, I
remained in this position from a feeling of pride, which I would not
acknowledge, and which, no doubt, the marked distinction with
which the king honoured me had given rise to, as well as from the
sort of importance which it gave me in the world. Thanks also to my
duties, my assiduous presence at Madame de Fersen's might be
attributed to purely political associations.
What charmed me in Catherine was, perhaps, less the influence
which she possessed over those surrounding her, than the exquisite
grace with which she renounced this highly esteemed influence with
me. This woman, with a strong, lofty, even judicial mind, who was
listened to with rare deference, whose least words were heard with
respect, showed herself in our intimacy what she had been at the
Grove,—kindly, simple, and gay, of an effusive tenderness, I might
almost say of a submission full of grace and consideration, always
placing her triumphs at my feet, and laughing with me at their
conceit.
Then, for the sake of our love, I would implore her to abandon
this life so uselessly employed.
On this subject alone, did I find Catherine ever intractable. She
would set forth that M. de Fersen would return to Paris; that she had
been guilty of a fault, a grave fault, and that she should at least
atone for it by devoting herself to her husband's wishes. Before his
departure he had bid her most expressly to maintain, and even to
extend, the relations which she had established; and she was
obeying his injunctions more to satisfy her conscience than for her
own pleasure.
As much as I, she regretted the former conversations of the
saloon on board the frigate, and, above all, the four months spent at
the Grove: this period of the heart's paradise, as she called it, those
priceless days which shine but once, and never return in life,—no
more than youth returns.
There is nothing more exclusive, more madly absolute than
passion. While acknowledging the truth of Catherine's observations,
I could not avoid feeling wretched at these obligations imposed upon
her by remorse for a fault which I had caused her to commit.
Catherine, however, showed herself so tender, so considerate!
With an incredible tact, she found means to speak to me covertly of
ourselves, even in the midst of apparently serious conversations, and
thus won me to bear in patience the obstacles to our love.
There is nothing, in fact, so delightful as this conventional talk, by
means of which lovers can speak of themselves, their hopes, and
their memories, in the midst of the gravest company. Nothing
amused me more than to see the most solemn men innocently
taking part in our ambiguous conversations.
But these people often made me pay cruelly for these mysterious
joys. They robbed me almost entirely of Catherine's society of an
evening, for they generally met at her house; and frequently of a
morning a letter from one or the other, asking for an interview with
Madame de Fersen, disarranged all our plans.
Catherine suffered from these obstacles as much as I, but how
could it be avoided? Under what pretext could she refuse the
request for an interview? I, who had carried to the most scrupulous
sensitiveness the fear of compromising in the slightest degree her
reputation, could I encourage her in so perilous a step?
No, certainly not; but I suffered cruelly from the thousand
obstacles ever recurring which continually irritated the jealous
impatience of my heart.
Our happiness at the Grove had been so perfect! Enchanting
season, lovely country, complete isolation, mysterious and extreme
freedom, everything had been so beautifully arranged by chance
that the comparison of that past with the present was a continuous
source of irritation.
These regrets did not prevent my enjoying the delightful moments
that remained to us. I had perfect faith in Madame de Fersen's love;
my attacks of distrust of myself and others yielded to the influence
of her noble character, and the conviction that I had this time
conducted myself towards Catherine as few men would have
conducted themselves in my place, and that I, therefore, was
deserving of all her tenderness.
I felt so sure of myself that I ventured on certain analytical
thoughts which I would formerly have dreaded. In a word, I had
fruitlessly sought the hidden motives of Madame de Fersen's love;
and I confess that, seeing her high rank, her great influence, her
wealth and position, I could not, in spite of my inventive shrewdness
and the resources of my suspicious mind, I could not, I say, discover
what interest Catherine could have in pretending to love me.
CHAPTER XXVI
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!
ebookgate.com

Programming in C 2nd Edition Safari download pdf

  • 1.
    Visit https://ebookgate.com todownload the full version and explore more ebooks Programming in C 2nd Edition Safari _____ Click the link below to download _____ https://ebookgate.com/product/programming-in-c-2nd- edition-safari/ Explore and download more ebooks at ebookgate.com
  • 2.
    Here are somerecommended products that might interest you. You can download now and explore! Programming with ANSI C 2nd ed Edition Trivedi https://ebookgate.com/product/programming-with-ansi-c-2nd-ed-edition- trivedi/ ebookgate.com C for business programming 2nd ed Edition Molluzzo https://ebookgate.com/product/c-for-business-programming-2nd-ed- edition-molluzzo/ ebookgate.com Programming Principles and Practices using C 2nd Edition Bjarne Stroustrup https://ebookgate.com/product/programming-principles-and-practices- using-c-2nd-edition-bjarne-stroustrup/ ebookgate.com Programming in Objective C 4th Edition Stephen Kochan https://ebookgate.com/product/programming-in-objective-c-4th-edition- stephen-kochan/ ebookgate.com
  • 3.
    Programming in ANSIC 6th Edition E. Balagurusamy https://ebookgate.com/product/programming-in-ansi-c-6th-edition-e- balagurusamy/ ebookgate.com Programming in Scala 2nd 2nd Edition Martin Odersky https://ebookgate.com/product/programming-in-scala-2nd-2nd-edition- martin-odersky/ ebookgate.com Mobile Computing 1st edition Edition Safari https://ebookgate.com/product/mobile-computing-1st-edition-edition- safari/ ebookgate.com Separation Process Engineering Second Edition Safari https://ebookgate.com/product/separation-process-engineering-second- edition-safari/ ebookgate.com Programming in Java 2nd edition Edition Choudhary https://ebookgate.com/product/programming-in-java-2nd-edition-edition- choudhary/ ebookgate.com
  • 6.
    Programming in C++ SecondEdition Ashok Namdev Kamthane Associate Professor Department of Electronics and Telecommunication Engineering Shri Guru Gobind Singhji Institute of Engineering and Technology Nanded, Maharashtra
  • 7.
    Copyright © 2013Dorling Kindersley (India) Pvt. Ltd. Licensees of Pearson Education in South Asia No part of this eBook may be used or reproduced in any manner whatsoever without the publisher’s prior written consent. This eBook may or may not include all assets that were part of the print version. The publisher reserves the right to remove any material in this eBook at any time. ISBN 9788131791448 eISBN 9789332520288 Head Office: A-8(A), Sector 62, Knowledge Boulevard, 7th Floor, NOIDA 201 309, India Registered Office: 11 Local Shopping Centre, Panchsheel Park, New Delhi 110 017, India
  • 8.
    PrEfAcE xv About thEAuthor xvii 1. iNtroductioN to c++ 1 2. bASicS of c++ 21 3. iNPut ANd outPut iN c++ 33 4. c++ dEclArAtioNS 99 5. dEciSioN StAtEmENtS 161 6. coNtrol looP StructurES 187 7. fuNctioNS iN c++ 203 8. clASSES ANd objEctS 257 9. coNStructorS ANd dEStructorS 345 10. oPErAtor ovErloAdiNg ANd tyPE coNvErSioN 395 11. iNhEritANcE 441 12. ArrAyS 511 Brief Contents
  • 9.
    iv Brief Contents 13.PoiNtErS 531 14. c++ ANd mEmory modElS 577 15. biNdiNg, PolymorPhiSmS, ANd virtuAl fuNctioNS 603 16. APPlicAtioNS with filES 639 17. gENEric ProgrAmmiNg with tEmPlAtES 697 18. worKiNg with StriNgS 731 19. ExcEPtioN hANdliNg 759 20. ovErviEw of StANdArd tEmPlAtE librAry 785 21. AdditioNAl iNformAtioN About ANSi ANd turbo-c++ 817 22. c++ grAPhicS 843 APPENdicES 869 iNdEx 879
  • 10.
    Preface xv About theAuthor xvii 1. iNtroductioN to c++ 1 1.1 Differences between C and C++ 1 1.2 Evolution of C++ 2 1.3 The ANSI Standard 2 1.4 The Object Oriented Technology 2 1.5 Disadvantage of Conventional Programming 4 1.6 Programming Paradigms 5 1.7 Preface to Object Oriented Programming 6 1.8 Key Concepts of Object Oriented Programming 7 1.9 Advantages of OOP 15 1.10 Object Oriented Languages 16 1.11 Usage of OOP 17 1.12 Usage of C++ 18 Summary 18 Exercises 19 2. bASicS of c++ 21 2.1 Introduction 21 2.2 Steps to Create and Execute a C++ Program 21 2.3 Flowchart for Creating a Source File, Compiling, Linking and Executing in C++ 22 2.4 C++ Environments 23 2.5 Typical C++ Environment (Borland C++) 24 2.6 Structure of a C++ Program 27 2.7 Illustrative Simple Program in C++ without Class 28 2.8 Header Files and Libraries 29 Summary 30 Exercises 31 Contents
  • 11.
    vi Contents 3. iNPutANd outPut iN c++ 33 3.1 Introduction 33 3.2 Streams in C++ and Stream Classes 34 3.3 Pre-defined Streams 34 3.4 Buffering 35 3.5 Stream Classes 36 3.6 Formatted and Unformatted Data 37 3.7 Unformatted Console I/O Operations 38 3.8 Type Casting with the cout Statement 44 3.9 Member Functions of the istream Class 56 3.10 Formatted Console I/O Operations 59 3.11 Bit Fields 67 3.12 Flags without Bit Fields 70 3.13 Manipulators 71 3.14 User-defined Manipulators 74 3.15 Manipulator with One Parameter 76 3.16 Manipulators with Multiple Parameters 77 3.17 More Programs 79 Summary 87 Exercises 88 4. c++ dEclArAtioNS 99 4.1 Introduction 99 4.2 Tokens 100 4.3 Variable Declaration and Initialization 108 4.4 Data Types in C++ 115 4.5 Operators in C and C++ 129 4.6 Scope Access Operator 133 4.7 Namespace 133 4.8 Memory Management Operators 137 4.9 Comments 141 4.10 Comma Operator 142 4.11 Comma in Place of Curly Braces 143 4.12 More Programs 145 Summary 155 Exercises 156 5. dEciSioN StAtEmENtS 161 5.1 Introduction 161 5.2 The if Statement 162 5.3 Multiple ifs 165 5.4 The if-else Statement 167 5.5 Nested if-else Statements 169 5.6 The else-if Ladder 171 5.7 Unconditional Control Transfer Statements 175
  • 12.
    Contents vii 5.8 Theswitch Statement 177 5.9 Nested switch case 182 Summary 183 Exercises 184 6. coNtrol looP StructurES 187 6.1 Introduction 187 6.2 What Is a Loop? 187 6.3 The for Loop 188 6.4 Nested for Loops 191 6.5 The while Loop 192 6.6 The do-while Loop 195 6.7 The do-while Statement with while Loop 196 6.8 More Programs 197 Summary 199 Exercises 199 7. fuNctioNS iN c++ 203 7.1 Introduction 203 7.2 Parts of a Function 205 7.3 Passing Arguments 209 7.4 Lvalues and Rvalues 215 7.5 Return by Reference 216 7.6 Returning More Values by Reference 217 7.7 Default Arguments 218 7.8 const Arguments 222 7.9 Inputting Default Arguments 224 7.10 Inline Functions 225 7.11 Function Overloading 228 7.12 Principles of Function Overloading 230 7.13 Precautions with Function Overloading 234 7.14 Recursion 235 7.15 Library Functions 237 7.16 More Programs 241 Summary 252 Exercises 252 8. clASSES ANd objEctS 257 8.1 Introduction 258 8.2 Structure in C 259 8.3 Structure in C++ 261 8.4 Classes in C++ 262 8.5 Declaring Objects 263 8.6 The public Keyword 264
  • 13.
    viii Contents 8.7 Theprivate Keyword 265 8.8 The protected Keyword 266 8.9 Access Specifiers and Their Scope 267 8.10 Defining Member Functions 268 8.11 Characteristics of Member Functions 272 8.12 Outside Member Function as Inline 272 8.13 Rules for Inline Functions 274 8.14 Data Hiding or Encapsulation 274 8.15 Classes, Objects, and Memory 277 8.16 static Member Variables 280 8.17 static Member Functions 286 8.18 static Object 289 8.19 Array of Objects 290 8.20 Objects as Function Arguments 292 8.21 friend Functions 295 8.22 The const Member Functions 304 8.23 The Volatile Member Function 305 8.24 Recursive Member Function 306 8.25 Local Classes 307 8.26 empty, static, and const Classes 310 8.27 Member Function and Non-member Function 310 8.28 The main() Function as a Member Function 311 8.29 Overloading Member Functions 312 8.30 Overloading main() Functions 313 8.31 The main(), Member Function, and Indirect Recursion 314 8.32 Bit Fields and Classes 317 8.33 Nested Class 319 8.34 More Programs 320 Summary 339 Exercises 340 9. coNStructorS ANd dEStructorS 345 9.1 Introduction 346 9.2 Constructors and Destructors 348 9.3 Characteristics of Constructors and Destructors 349 9.4 Applications with Constructors 350 9.5 Constructors with Arguments (Parameterized Constructor) 353 9.6 Overloading Constructors (Multiple Constructors) 355 9.7 Array of Objects Using Constructors 359 9.8 Constructors with Default Arguments 360 9.9 Copy Constructors 361 9.10 The const Objects 363 9.11 Destructors 364 9.12 Calling Constructors and Destructors 367 9.13 Qualifier and Nested Classes 370
  • 14.
    Contents ix 9.14 AnonymousObjects 372 9.15 Private Constructors and Destructors 374 9.16 Dynamic Initialization Using Constructors 375 9.17 Dynamic Operators and Constructors 377 9.18 main() as a Constructor and Destructor 379 9.19 Recursive Constructors 380 9.20 Program Execution Before main() 381 9.21 Constructor and Destructor with Static Members 383 9.22 Local Versus Global Object 384 9.23 More Programs 385 Summary 392 Exercises 392 10. oPErAtor ovErloAdiNg ANd tyPE coNvErSioN 395 10.1 Introduction 395 10.2 The Keyword Operator 398 10.3 Overloading Unary Operators 400 10.4 Operator Return Type 403 10.5 Constraint on Increment and Decrement Operators 404 10.6 Overloading Binary Operators 405 10.7 Overloading with friend Function 409 10.8 Overloading Assignment Operator (=) 412 10.9 Type Conversion 414 10.10 Rules for Overloading Operators 422 10.11 One-Argument Constructor and Operator Function 424 10.12 Overloading Stream Operators 425 10.13 More Programs 427 Summary 438 Exercises 439 11. iNhEritANcE 441 11.1 Introduction 442 11.2 Reusability 442 11.3 Access Specifiers and Simple Inheritance 442 11.4 Protected Data with Private Inheritance 449 11.5 Types of Inheritance 454 11.6 Single Inheritance 456 11.7 Multilevel Inheritance 457 11.8 Multiple Inheritance 459 11.9 Hierarchical Inheritance 460 11.10 Hybrid Inheritance 462 11.11 Multipath Inheritance 465 11.12 Virtual Base Classes 466 11.13 Constructors, Destructors, and Inheritance 468 11.14 Object as a Class Member 483 11.15 Abstract Classes 489
  • 15.
    x Contents 11.16 QualifierClasses and Inheritance 489 11.17 Constructors in Derived Class 490 11.18 Pointers and Inheritance 491 11.19 Overloading Member Function 492 11.20 Advantages of Inheritance 494 11.21 Disadvantages of Inheritance 494 11.22 More Programs 494 Summary 505 Exercises 506 12. ArrAyS 511 12.1 Introduction 511 12.2 One-dimensional Array Declaration and Initialization 511 12.3 Characteristics of Arrays 512 12.4 Accessing Array Elements Through Pointers 515 12.5 Arrays of Pointers 516 12.6 Passing Array Elements to a Function 517 12.7 Passing Complete Array Elements to a Function 518 12.8 Initialization of Arrays Using Functions 519 12.9 Two-dimensional Arrays 520 12.10 Pointers and Two-dimensional Arrays 523 12.11 Three- or Multi-dimensional Arrays 524 12.12 Arrays of Classes 525 Summary 528 Exercises 529 13. PoiNtErS 531 13.1 Introduction 531 13.2 Features of Pointers 532 13.3 Pointer Declaration 533 13.4 Arithmetic Operations with Pointers 536 13.5 Pointer to Pointer 538 13.6 void Pointers 539 13.7 wild Pointers 540 13.8 Pointer to Class 542 13.9 Pointer to Object 544 13.10 The this Pointer 546 13.11 Pointer to Derived Classes and Base Class 550 13.12 Pointer to Members 554 13.13 Accessing Private Members with Pointers 561 13.14 Direct Access to Private Members 562 13.15 Addresses of Objects and void Pointers 564 13.16 More Programs 565 Summary 573 Exercises 573
  • 16.
    Contents xi 14. c++ANd mEmory modElS 577 14.1 Introduction 577 14.2 Memory Models 577 14.3 Dynamic Memory Allocation 581 14.4 The new and delete Operators 582 14.5 Heap Consumption 586 14.6 Overloading new and delete Operators 588 14.7 Overloading new and delete in Classes 592 14.8 Execution Sequence of Constructor and Destructor 595 14.9 Specifying Address of an Object 597 14.10 Dynamic Objects 598 14.11 Calling Convention 599 Summary 600 Exercises 601 15. biNdiNg, PolymorPhiSmS, ANd virtuAl fuNctioNS 603 15.1 Introduction 603 15.2 Binding in C++ 604 15.3 Pointer to Base and Derived Class Objects 609 15.4 Virtual Functions 612 15.5 Rules for Virtual Functions 613 15.6 Array of Pointers 615 15.7 Pure Virtual Functions 618 15.8 Abstract Classes 619 15.9 Working of Virtual Functions 621 15.10 Virtual Functions in Derived Classes 627 15.11 Object Slicing 629 15.12 Constructors and Virtual Functions 631 15.13 Virtual Destructors 632 15.14 Destructors and Virtual Functions 634 Summary 635 Exercises 635 16. APPlicAtioNS with filES 639 16.1 Introduction 639 16.2 File Stream Classes 641 16.3 Steps of File Operations 643 16.4 Checking for Errors 650 16.5 Finding End of a File 653 16.6 File Opening Modes 655 16.7 File Pointers and Manipulators 657 16.8 Manipulators with Arguments 661 16.9 Sequential Access Files 664 16.10 Binary and ASCII Files 666
  • 17.
    xii Contents 16.11 RandomAccess Operation 670 16.12 Error Handling Functions 674 16.13 Command-Line Arguments 679 16.14 Strstreams 680 16.15 Sending Output to Devices 682 16.16 More Programs 684 Summary 691 Exercises 692 17. gENEric ProgrAmmiNg with tEmPlAtES 697 17.1 Introduction 698 17.2 Need for Templates 698 17.3 Definition of Class Templates 698 17.4 Normal Function Templates 701 17.5 Working of Function Templates 704 17.6 Class Templates with More Parameters 704 17.7 Function Templates with More Arguments 705 17.8 Overloading of Template Functions 708 17.9 Member Function Templates 709 17.10 Recursion with Template Functions 710 17.11 Class Templates with Overloaded Operators 711 17.12 Class Templates Revisited 713 17.13 Class Templates and Inheritance 715 17.14 Bubble Sort Using Function Templates 717 17.15 Guidelines for Templates 718 17.16 Differences Between Templates and Macros 719 17.17 Linked Lists with Templates 720 17.18 More Programs 722 Summary 727 Exercises 728 18. worKiNg with StriNgS 731 18.1 Introduction 731 18.2 Moving From C String to C++ String 734 18.3 Declaring and Initializing String Objects 735 18.4 Relational Operators 738 18.5 Handling String Objects 740 18.6 String Attributes 743 18.7 Accessing Elements of Strings 747 18.8 Comparing and Exchanging 750 18.9 Miscellaneous Functions 752 18.10 More Programs 754 Summary 757 Exercises 757
  • 18.
    Contents xiii 19. ExcEPtioNhANdliNg 759 19.1 Introduction 759 19.2 Principles of Exception Handling 760 19.3 The Keywords try, throw, and catch 760 19.4 Guidelines for Exception Handling 761 19.5 Multiple catch Statements 765 19.6 Catching Multiple Exceptions 767 19.7 Re-throwing Exception 768 19.8 Specifying Exceptions 769 19.9 Exceptions in Constructors and Destructors 771 19.10 Controlling Uncaught Exceptions 773 19.11 Exceptions and Operator Overloading 774 19.12 Exceptions and Inheritance 776 19.13 Class Templates with Exception Handling 777 19.14 Guidelines for Exception Handling 778 19.15 More Programs 779 Summary 781 Exercises 782 20. ovErviEw of StANdArd tEmPlAtE librAry 785 20.1 Introduction to STL 785 20.2 STL Programing Model 786 20.3 Containers 786 20.4 Sequence Containers 787 20.5 Associative Containers 789 20.6 Algorithms 789 20.7 Iterators 794 20.8 Vectors 795 20.9 Lists 801 20.10 Maps 808 20.11 Function Objects 811 Summary 814 Exercises 815 21. AdditioNAl iNformAtioN About ANSi ANd turbo-c++ 817 21.1 Introduction 817 21.2 Innovative Data Types 818 21.3 New Type-casting Operators 821 21.4 The Keyword explicit 826 21.5 The Keyword mutable 827 21.6 Namespace Scope 828 21.7 Nested Namespaces 829 21.8 Anonymous Namespaces 830 21.9 The Keyword using 830
  • 19.
    xiv Contents 21.10 NamespaceAlias 835 21.11 The Standard Namespace std 835 21.12 ANSI and Turbo-C++ Keywords 836 21.13 ANSI and Turbo-C++ Header Files 839 21.14 C++ Operator Keywords 840 Summary 840 Exercises 841 22. c++ grAPhicS 843 22.1 Introduction 843 22.2 Computer Display Modes 844 22.3 Video Display and Display Adapters 844 22.4 Initilisation of Graphics 844 22.5 Few Additional Graphics Functions 846 22.6 Programs Using Library Functions 848 22.7 Working with Texts 856 22.8 Filling Patterns with Different Colors and Styles 858 22.9 Mouse Programming 862 22.10 Drawing Noncommon Figures 866 Summary 867 Exercises 867 Appendices 869 Index 879
  • 20.
    Programming in C++is meant for students pursuing various disciplines such as engineer- ing, science, computer application, and diploma courses. Students who are learning object- oriented programming (OOP) can also refer to this book. It covers the subject of C++ as per the syllabi prescribed by various branches of Indian universities, state board of technical educations, and the Department of Electronics and Accreditation of Computer Courses. Hence, this book can be adopted in engineering, degree as well as other courses that deal with this sub- ject. Written for beginners and for those who have some knowledge of C, the book will be espe- cially useful for students who are learning object-oriented programming. Designed to bridge the gap between theory and practice, the chapters have been presented using a systematic and lucid approach. Each topic is explained in an easy-to-understand manner with ample worked-out examples and programs. The book abounds with about 700 solved programs and as many as 300 exercises for the student’s benefit. The programmer can run the solved programs, see the output and appreciate the concepts of C++. The programs have been fully tested and executed with Borland’s Turbo C++ compiler version 3.00 and Visual C++ 6.0 compiler. The programs in Chapter 22 have been tested and compiled with Java Compiler version 2. This second edition has been thoroughly revised based on comments and responses received for the previous edition. All programming examples have been tested, compiled and executed. While utmost care has been taken at the time of writing this book, it is possible that errors and omissions may have inadvertently crept in. Such incongruities, if any, may please be pointed out. Suggestions and feedback are most welcome and may be directed to my e-mail address: ankamthane@gmail.com. AcKNowlEdgEmENtS I express my gratitude to the Minister for Technical and Medical Education of Maharashtra State, Honorable Shri D. P. Sawant, who complimented and felicitated me for writing technical books, while he was invited to our institute recently in the month of May 2013. He also encouraged me to write more books. I am grateful to Prof. B. M. Naik, Former Principal of S.G.G.S. Institute of Engineering and Technology, Nanded, who has always acted as a source of encouragement. His dynamism and leadership led me to write this book and I will never forget his support and words of wisdom. Preface
  • 21.
    xvi Preface Special thanksare due to the members of the board of governors of S.G.G.S. Institute of Engineering and Technology, who motivated me to write this book. I thank eminent industrialist Shri B. N. Kalyani, head of the Kalyani Group of Companies, for inspiring and complimenting me for authoring technical books. I am also obliged to Dr L. M. Waghmare, Director of our institute, for supporting and appreciating me while writing this book. I am indebted to all my colleagues, friends and students who helped me at the time of preparing the manuscript for this book. I acknowledge the support rendered by Dr S. V. Bonde, Dr P. D. Jadhav, Dr P. Pramanik, Dr P. S. Charpe, Dr B. M. Dabde, DrY.V. Joshi, Dr U.V. Kulkarni, Dr S. P. Kallurkar, Dr V. M. Nandedkar, Dr A. U. Digraskar, Dr R. S. Holambe, Dr B. M. Patre, Prof. R. K. Chavan, Dr J. V. L. Venkatesh, Prof. P. S. Nalawade, S. S. Hatkar, Dr R. C. Thool, Dr V. R. Thool, Dr D. D. Doye, Milind Bhalerao, Dr A. B. Gonde, Dr A. Chakraborthi, Dr A. V. Nandedkar, Dr P. B. Londhe, Dr R. R. Manthalkar, Dr S. S. Gajre, Prof. N. G. Megde, Dr A. S. Sontakke, Dr R. H. Chille, Dr L. M. Waikar and A. I. Tamboli of S.G.G.S. Institute of Engineering and Technology. I thank my friends Principal Prof. S. L. Kotgire and Prof. Balaji Bacchewar for their words of encouragement. M. M. Jahagirdar, L. M. Buddhewar, K. M. Buddhewar, D. V. Deshpande, S. R. Kokne, M. G. Damkondawar, Yeramwar, Pampatwar, D. R. Yerawar, S. R. Tumma, and S. R. Mana also helped me to a great extent while writing this book. I thank Pearson Education for publishing this book. In particular, I thank Ms V. Pavithra and Ms Neha Goomer for their help in seeing this book through production. In addition, I also thank Thomas Rajesh for his constant encouragement. I appreciate the help and support provided by all the students, faculty, and non-teaching staff of this institute as well as that of other friends who have directly or indirectly added value to this book. Thanks are also due to my wife, Surekha, who persistently supported me at all times. I am indebted to my sons Amol and Amit, daughter Sangita, as also my daughter-in-law Swarupa, who all played a key role in bringing this book to fruition. Swarupa was of immense help in drawing the figures in several chapters. I thank all of them. Ashok Namdev Kamthane
  • 22.
    Ashok Namdev Kamthaneobtained his M.E. (Electronics) degree from S.G.G.S. Institute of Engineering and Technology, Nanded.A meritorious student throughout his career, he has bagged a number of prizes including cash and medals for his distinct work in the academics. For his M. E. (Electronics) dissertation, he worked at the Bhabha Atomic Research Center, Mumbai. Associated with the teaching profession for the past 30 years, Kamthane was instrumental in the development of hardware and software using the 8051 (8-bit microcontroller) on Acoustic Transceiver System required in submarines. He has also worked at Melton as an executive. Currently Associate Professor at the Department of Electronics and Telecommunication Engineering in S.G.G.S Institute of Engineering and Technology, he has guided a number of undergraduate and postgraduate students in their projects and published a number of technical papers at both national and international conferences. About the Author
  • 23.
    This page isintentionally left blank.
  • 24.
    • • • • • • • • • • • • 1.1 Differences betweenC and C++ 1.2 Evolution of C++ 1.3 The ANSI Standard 1.4 The Object Oriented Technology 1.5 Disadvantage of Conventional Programming 1.6 Programming Paradigms 1.7 Preface to Object Oriented Programming 1.8 Key Concept of Object Oriented Programming 1.9 Advantages of OOP 1.10 Object Oriented Languages 1.11 Usage of OOP 1.12 Usage of C++ Introduction to C++ Chapter Outline 1.1 Differences between c anD c++ Some differences between C and C++ are as follows: (1) C is a procedure/function-oriented language and C++ language is driven by a procedure/ object. (2) Data is not protected in C, whereas data is secured in C++. Data hiding concept is absent in C. (3) C uses a top down approach while C++ uses a bottom up approach. The program is prepared step by step in C, and in C++ base elements are prepared first. (4) In C, we cannot give the same name to two functions in a program, whereas due to the function overloading feature, the above concept is possible in C++. One can initialize a number of functions with the same name, but with different arguments. The polymorphism feature is built in C++, which supports this concept. c H a P t e r 1
  • 25.
    2 Introduction toC++ (5) C uses printf() and scanf() functions to write and read the data respectively, while C++ uses cout and cin objects for output and input operations, respectively. Further, the cout uses << (insertion operator) and cin uses >> ( extraction operator). (6) C uses stdio.h file for input and output functions, whereas C++ uses iostream.h for these functions. (7) Constructor and destructors are absent in C and the same are provided in C++. (8) Inline functions are supported by C++, and the same are absent in C. Inline func- tions can be used as micros. They are stated by a word ‘inline’. 1.2 evolution of c++ C++ is an object oriented programming language and also con- sidered as an extension of C. Bjarne Stroustrup at AT&T Bell Laboratories in Murray Hill, New Jersey (USA) developed this language in the early 1980s. Stroustrup, a master of Simula67 and C, wanted to combine the features of both the languages and he developed a powerful language that supports object-ori- ented programming with features of C. The outcome was C++ as per Fig. 1.1.Various features were derived from Simula67 and algol68. Stroustrup called the new language ‘C with classes’. However, in 1983, the name was changed to C++. The thought of C++ came from the C increment operator ++. Rick Mascitti coined the term C++ in 1983. Therefore, C++ is an extension of C. C++ is a superset of C. All the concepts of C are applicable to C++ also. For developing complicated applications, object orient- ed language such as C++ is the most convenient and easy. Hence, a programmer must be aware of its features. 1.3 tHe ansi stanDarD The ANSI stands for American National Standards Institute. This Institute was founded in 1918. The main goal for establishing this Institute was to suggest, reform, recommend, and publish stan- dards for data processing in the USA. This committee sets up the standard in the computer industry. The recognized council working under the procedure of the American National Standards Institute (ANSI) has made an international standard for C++. The C++ standard is also referred to as ISO (International Standards Organization) standard. The process of standardization is gradual and the first draft of the planned ANSI standard was made on 25 January 1994. This book will continue to refer ANSI standard code, which is more commonly used. The ANSI standard is an attempt to ensure that the C++ is portable. 1.4 tHe object orienteD tecHnology Nature is composed of various objects. Living beings can be categorized into different objects. Let us consider an example of a teaching institute which has two different working sections – teaching and non-teaching. Further sub-grouping of teaching and non-teaching can be made for fig. 1.1 Evolution of C++ C SIMULA 67 C WITH CLASSES ALGOL 68 C++
  • 26.
    The Object OrientedTechnology 3 the coordination of management. The various departments of any organization can be thought of as objects working for certain goals and objectives. Usually an institute has faculty of different departments. The Director/Principal is a must for the overall management of the institute. The Academic Dean is responsible for the academics of the institute. The Dean for Planning should have the future plans of the institute and he/she must see how the infrastructure is utilized effectively. The Dean R&D should see research activities run in the institute forever. Besides teaching staff there must be laboratory staff for assistance in conducting practical ses- sions, and a site development section for beautification of the campus. The accounts department is also required for handling monetary transactions and salaries of the employees. The Sports sec- tion is entrusted the responsibility of sports activities. The Registrar for Administration and staff for dealing with administrative matters of the institute are also required. Each department has an in-charge who carries clear-cut given responsibilities. Every department has its own work as stat- ed above. When an institute’s work is distributed into departments as shown in Fig. 1.1, it is com- fortable to accomplish goals and objectives. The activities are carried on smoothly. The burden of one particular department has to be shared among different departments with personnel. The staff in the department is controlled properly and act according to the instructions laid down by the management. The faculty performs activities related to teaching. If the higher authority needs to know the details regarding the theory, practical, seminar and project loads of individuals of the de- partment, then a person from the department furnishes the same to the higher authority. This way some responsible person from the department accesses the data and provides the higher authority with the requisite information. It is also good to think that no unconnected person from another department reads the data or attempts to make any alteration that might corrupt the data. As shown in Fig. 1.2, an institute is divided into different departments such as library, classroom, computer laboratory, etc. Each department performs its own activities in association with the other departments. Each department may be considered as a module and it contains class and object in C++ language. This theory of class and object can be extended to every walk of life and can be implemented with software. In general, objects are in terms of entities. Class Room Computer Lab Library fig. 1.2 Relationship between different sections
  • 27.
    4 Introduction toC++ In a nutshell, in object oriented programming objects of a program interact by sending messages to each other. 1.5 DisaDvantage of conventional Programming Traditional programming languages such as COBOL, FORTRAN, C etc. are commonly known as procedure oriented languages. The program written in these languages consists of a sequence of instructions that tells the compiler or interpreter to perform a given task. Numerous functions are initiated by the user to perform a task. When a program code is large, it becomes inconve- nient to manage it. To overcome this problem, procedures or subroutines were adopted to make a program more understandable to the programmers. A program is divided into many functions. Main Function Function-A Function-D Function-F Function-G Function-H Function-E Function-B Function-C fig. 1.3 Flow of functions in non-OOP languages Each function can call another function, as shown in Fig. 1.3. Each function has its own task. If the program is too large the function also creates problems. In many programs, important data variables are declared as global. In case of programs containing several functions, every function can access the global data as per the simulation in Fig. 1.4. In huge programs it is difficult to know what data is used by which function. Due to this the program may contain several logical errors. Global Variables Global Variables Global variables Function A Local Variable Function B Local Variable Function C Local Variable Function D Local Variable fig. 1.4 Sharing of data by functions in non-OOP languages The following are the drawbacks observed in monolithic, procedure, and structured program- ming languages:
  • 28.
    Programming Paradigms 5 (1)Huge programs are divided into smaller programs known as functions. These functions can call one another. Hence security is not provided. (2) No importance is given to security of data and importance is laid on doing things. (3) Data passes globally from function to function. (4) Most function accesses global data. 1.6 Programming ParaDigms (1) monolithic Programming: (A) In these types of programming languages, theprogramiswrittenwithasinglefunction. A program is not divided into parts; hence it is named as monolithic programming. It is also called single thread execution. (B) When the program size increases it leads to difficulty. (C) In monolithic programming languages such as basic and assembly language, the data variables declared are global and the statements are written in sequence. (D) The program contains jump statements such as goto that transfers control to any statement as specified in it. Fig. 1.5 shows a program of monolithic type. The global data can be accessed from any portion of the program. Due to this reason the data is not fully protected. (E) The concept of sub-programs does not exist, and hence is useful for small programs. (2) Procedural/structured Programming (A) Sometimes known as modular programming. (B) Programs written are more efficient and easier to understand and modify. (C) The procedural/structured programming languages are similar to solving a prob- lem by human. In a nut shell, humans attempt a problem by adopting a sequence of operations. (D) It makes use of a top-down design model in which a program developer maps out the overall program structure into separate subsections. (E) Large size programs can be developed in structured programming such as Pascal and C. Programs are divided in multiple sub-modules. (F) Procedural/Structured programming languages such as FORTRAN, BASIC, AL- GOL, COBOL, C, etc., are divided into a number of segments called as subpro- grams. There is a main function and it invokes subprograms. Thus, it focuses on functions apart from data. Figure 1.6 describes a program of procedural/structured type. It shows different sub-programs accessing the same global data. Here also the programmer can observe the lack of secrecy. fig. 1.5 Program in monolithic programming 1 Statement 2 Statement 3 Statement 50 Statement 51 Statement 52 Statement 99 Statement 100 Statement goto 50 goto 1 GLOBAL DATA
  • 29.
    6 Introduction toC++ (G) The control of program can be transferred using unsafe goto statement. (H) This type of programming language uses different control structures that are as follows. • Decision/selection control statements • Iteration control statements • Jump control statements (I) Data are global and all the sub-programs share the same data, i.e. data are globally accessible to all functions. Thus, any function operates on the global data and this directs to loosing some vital information. We can conclude here that a module represents a function. (J) Procedural structured/programming languages permit data transfer through mes- sages by means of functions. (K) Least importance is given to the data in procedural/structured programming languages. (L) These languages are used for developing medium-sized software applications. (M) Complier and interpreter construction are easy and simple with this type of pro- gramming language. Furthermore, these compilers and interpreters need low memory to run on the computers. (N) It is difficult to implement simultaneous processes/parallelization. Modules GLOBAL DATA Local Data Local Data Local Data fig. 1.6 Program in procedural/structured programming 1.7 Preface to object orienteD Programming The prime factor in the design of object oriented programming approach is to rectify some of the faults observed in the procedure oriented languages. OOP acts with data as a critical com- ponent in program development. It does not allow the data to flow freely around the systems. It ties data to the functions that operate on it and prevents it from accidental change due to external functions. OOP permits us to analyze a problem into a number of items called objects and then assembles data and functions around these items as per Fig. 1.7. Following are the impressive characteristics of object-oriented programming:
  • 30.
    (1) OOP paysmore importance to data rather than function. (2) Programs are divided into classes and their member functions. (3) OOP follows a bottom-up approach. (4) New data items and functions can be comfortably added whenever essential. (5) Data is private and prevented from accessing external functions. (6) Objects communicate with each other through functions. Data variables Object A Object B Object C Member function Member function Member function Member function Member function Member function Data variables Data variables Data variables Data variables Data variables fig. 1.7 Relation between data and member function in OOP 1.8 Key concePts of object orienteD Programming Object oriented programming language is a feature that allows a mode of modularizing programs by forming ory area for data as well as functions that is used as object for making copies of modules as per requirement. There are several fundamental concepts in object oriented programming. They are shown in Fig. 1.8 and are discussed as follows. fig. 1.8 Concepts/elements of object oriented paradigm C++ Encapsulation Data abstraction Inheritance Polymorphism Delegation Genericity Key Concepts of Object Oriented Programming 7
  • 31.
    8 Introduction toC++ (1) objects Objects are primary run-time entities in object oriented programming. Objects are primary run-time entities in object-oriented programming. They may stand for a thing that makes sense in a specific application. Some examples are a spot, a person, any data item related to the program including user-defined data types. Programming issues are analyzed in terms of object and the type of transmission between them. Program objects must be selected like the items equivalent to actual world objects. Objects occupy space in memory. Every object has its own properties or features that illustrate what the object can do. An object is a specimen of a class. It can be singly recognized by its name. It declares the state that is shown by the data values of its characteristic at a specific time. The state of the object varies according to the pro- cedure used with it. It is called as the action of the object. The action of the object depends upon the member function defined within its class. Fig. 1.9 (a) shows some of the objects that we use in our daily life.  Telephone  Book  Computer  Watch Lock   Home  Trophy  Television  Bicycle  Ambulance fig. 1.9 (a) Commonly available objects fig. 1.9 (b) Representation of an object Object: City Data: Name_of_city Population Area Functions: Average age Literacy_rate Display Objects communicate with each other by sending messages. An object can be represented by Fig 1.9 (b). The name of the above object is city. Its data members are name_of_city, population, and area. The various functions associated with the city are average age, literacy_ rate, and display. (2) classes A class is grouping of objects that have the identical properties, common behavior, and shared relation- ship. A class binds the data and its related functions together. A class is the accomplishment of abstract data type. It defines the nature and methods that act on the data structure and abstract data type, respectively. Specimens are also called as objects. In other words, a class is a grouping of objects that have identical properties, common behavior, and shared relationship. For example, Tata’s Swift, Maruti’sAlto etc. are the members of a class car. The entire group of data and code of an object can be built as a user-defined data type us- ing class. Objects are nothing but variables of type class. Once a class has been declared, the programmer can create a number of objects associated with that class. The syntax used to create
  • 32.
    Key Concepts ofObject Oriented Programming 9 an object is similar to the syntax used to create an integer variable in C. A class is a model and not a true specimen of the object. Every object has its own value for each of its member variables. However, it shares the property names or operations with other instances of the class. Thus, classes define the characteristic and action of objects. Class: car Properties: company, model, color, and capacity Actions: Speed(), average() and break(). Class: computer Properties: Brand, resolution, price and size Action: processing(), display() and printing() Class: floppy Properties: company, size and capacity Action: storing(), protection(), and retrieving() fig. 1.10 Objects and their properties In Fig. 1.10 commonly useful classes are described with their properties and action they per- form. For example, a car has properties like company, model and color with which a car can be identified among a number of cars of other properties, and the actions like speed() and aver- age() describes its working. Class home { Telephone Book Computer Watch Lock } Class vehicle {} Class entertainment {     } fig. 1.11 Classes and their members Figure 1.11 describes the classes and related data that come under the different classes.  {      }
  • 33.
    10 Introduction toC++ (3) method An operation required for an object or entity when coded in a class is called a method. An operation required for an object or entity when coded in a class is called a method. The opera- tions that are required for an object are to be defined in the class. All objects in a class carry out certain common actions or operations. Each action needs an object that becomes a function in the class that defines it and is referred to as a method. In Fig. 1.12 the class and its associated data members and functions are shown in different styles. It is a frequent style of writing a class in the program. The class A contains private data members and public methods or member functions. Usually, the data members are declared private and methods or member functions are declared as public and they are available outside the class. The data member of any class uses its member functions or methods to perform operations. class A { private data member1; data member2; data member(n); public method1() { } method2() { } method_n() { } }; Members Methods or Member functions (a) Data member 1 Data member 2 Data member 3 : : Data member n Method 1 Method 2 Method 3 : : Method n Class A Data member 1 Data member 2 Class A Method 1 Method 2 Method n (b) fig. 1.12 (a) and (b) Representation of methods in different manners
  • 34.
    Key Concepts ofObject Oriented Programming 11 (4) Data abstraction Abstraction refers to the procedure of representing essential features without including the background details. Abstraction refers to the procedure of representing essential features without including the back- ground details. Classes use the theory of abstraction and are defined as a list of abstract properties such as size, cost, height, and few functions to operate on these properties. Data abstraction is the procedure of identifying properties and method related to a specific entity as applicable to the application. A powerful method to achieve abstraction is through the manipulation of hierarchical clas- sifications. It permits us the breaking of semantics of multiple systems into layers by separating them into multiple controllable parts. For example, a computer as shown in Fig. 1.13 is made of various parts such as CPU, keyboard, and so on. We think it as a single unit, but the single unit has several sub-units. They together do the single task. By assembling sub-parts we can build a single system. Hierarchical abstraction of complicated systems can also be used in computer software. The data from conventional procedure oriented programs can be converted by abstraction mechanism into its partial objects. A series of operation steps may develop a set of messages between these objects. Each object shows its own attributes. Data abstraction is used to define a data type available in the programming language, called as abstract data type (ADT). It consists of a set of values and a set of operations.  (a) Computer as single unit  (b) Different components of computer fig 1.13 Computer and its parts (5) encapsulation The packing of data and functions into a single component is known as encapsulation. C++ supports the features of encapsulation using classes. The packing of data and functions into a single component is known as encapsulation. The data is not reachable by the outside functions. Only those functions that are able to access the data are defined within the class. These functions prepare the interface between the object’s data and the program. With encapsulation we can accomplish data hiding. Data hiding is an important feature using which an object can be used without the user knowing how it works internally. In C++ the fundamental of encapsulation is class. A class defines the structure of data and member functions. It is common to all its objects. Class is a logical structure whereas object is
  • 35.
    12 Introduction toC++ a physical actuality. The goal of the class is to encapsulate complication. The class also has a mechanism for hiding the data. Each member in the class may be private or public. Any non- member function cannot access the data of the class. The public section of the class must be mindfully coded not to expose the inner details of the class. Figure 1.14 explains sections of encapsulation. class C κ Private Data Members υ Private methods Φ Public methods ι Public data members ι ι ι ι Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ υυυ υυυ υυυ υυυ κκκκκ κκκκκ κκκκκ κκκκκ Φ fig. 1.14 Encapsulation: Private and public sections (6) inheritance Inheritance is the method by which objects of one class get the properties of objects of another class. Inheritance is the method by which objects of one class get the properties of objects of another class. In object oriented programming inheritance provides the thought of reusability. The programmer can add new properties to the existing class without changing it. This can be achieved by deriving a new class from the existing one. The new class will pos- sess features of both the classes. The actual power of the inheritance is that it permits the programmer to reuse a class that is nearly, but not precisely, what he wants, and to tailor the class in such a manner that it does not bring any unwanted incidental re- sult into the rest of the class. Thus, inheritance is the feature that permits the reuse of an existing class to make a new class. Figure 1.15 shows an example of inheritance. In Fig. 1.15, red, yellow and blue are the main colors. The orange is created from the combi- nation of red and yellow, green is created from yellow and blue and violet is created from red and blue. The orange color has attributes of both red and yellow, which produces a new effect. Thus, many combinations are possible. (7) Polymorphism Polymorphism allows the same function to act in a different way in different classes. Red Yellow Blue Violet Orange Green Bluish brown Yellowish brown Reddish brown fig. 1.15 Inheritance
  • 36.
    Key Concepts ofObject Oriented Programming 13 Polymorphism makes it possible for the same functions to act differently on different classes as shown in Fig. 1.16. It is an important feature of OOP concept. It holds an ability to take more than one form. Polymorphism accomplishes an important part in allowing objects of different classes to share the same external interface. It is possible to code a non-specific (generi(c) interface to a set of associated actions. Line Display() Single Object Dash Object Dotted Object Display(dotted) Display(single) Display(dash) fig. 1.16 Polymorphism in OOP (8) Dynamic binding Binding means connecting one program to another program that is to be executed in reply to the call. Binding means connecting one program to another program that is to be executed in reply to the call. Dynamic binding is also known as late binding. The code present in the specified program is unknown till it is executed. It is analogous polymorphism. In Fig. 1.16 polymorphism allows the single object to invoke similar function from different classes. The program action is different in all the classes. At execution time, the code analogous to the object under the present reference will be executed. The reader is advised to refer polymor- phism chapter for more details. (9) message passing An object oriented programming includes objects. The objects communicate with one another. The programming with these objects should be followed with following steps. (1) Declaring classes that define objects and their actions. (2) Declaring objects from classes. (3) Implementing relation between objects. Data is transferred from one object to another object. A message for an object is the demand for implementation of the process. Message passing consists of indicating the name of the object, function, and required data elements (Fig. 1.17). Objects can be created, released, and interacted with each other. An object is workable, as long as it is active. In object oriented programming there is a panorama of independent objects that communicate with each other by swapping mes- sages. Objects invoke member functions. They also negate if the calling object is not a member of
  • 37.
    14 Introduction toC++ the same class. Thus a message is a solicitation to an object to call one of its member functions. A message contains name of the member function and parameters of the function. Execution of member function is just a response generated due to receipt of a message. It is possible when the function and the object are of the same class. Obj.Display (argument) Object Data Communication operator Message fig. 1.17 Message Passing (10) reusability Object oriented technology allows reusability of the classes by extending them to other classes using inheritance. Object oriented technology allows reusability of the classes by extending them to other class- es using inheritance. Once a class is defined, the other programmer can also use it in their programs. The programmer can also add new feature to the derived classes. The verified and checked qualities of base classes need not to be redefined. Thus, the reusability saves the time. In Fig. 1.18, class A is reused and class B is created. Again class B is reused and class C is created. CLASS A CLASS B CLASS C fig. 1.18 Reusability (11) Delegation In OOP, two classes can be joined in two ways: (a) Inheritance, (b) Delegation. Both these ways provide reusability of the class. In Inheritance one class can be derived from the other class. The relationship between these two classes is called as kind of relationship. For example if class Y is derived from class X, then class Y is known as kind of X. Figure 1.19 (a) explains this point.
  • 38.
    Advantages of OOP15 Class X//Base class Class Y//Derived class CLASS A { }; CLASS B { }; CLASS C { A a; // Object of class A as data member B b; // Object of class B as data member } (a) (b) fig. 1.19 Relationships between two classes: (a) Kind of relationship (Inheritance) (b) has a relationship (Delegation) The second type of relationship is has a relationship. When object of one class is used as data member in the other class, such composition of objects is known as delegation. As shown in Fig. 1.19 (b) class C has two data members. These two data members are objects of class A and B, such relationship between the classes in known as has a relationship. (12) genericity The software components of a program have more than one version depending on the data types of arguments. This feature allows declaration of variables without specifying exact data type. The compiler identifies the data type at run time. The programmer can create a function that can be used for any type of data. The template feature in C++ allows generic programming. 1.9 aDvantages of ooP Object oriented technology provides many advantages to the programmer and the user. This technology solves many problems related to software development, provides improved quality and low cost software. (1) Object oriented programs can be comfortably upgraded. (2) Using inheritance, we can eliminate redundant program code and continue the use of previously defined classes. (3) The technology of data hiding facilitates the programmer to design and develop safe programs that do not disturb code in other parts of the program. (4) The encapsulation feature provided by OOP languages allows programmer to define the class with many functions and characteristics and only few functions are exposed to the user. (5) All object oriented programming languages allows creating extended and reusable parts of programs. (6) Object oriented programming changes the way of thinking of a programmer. This re- sults in rapid development of new software in a short time. (7) Objects communicate with each other and pass messages.
  • 39.
    16 Introduction toC++ 1.10 object orienteD languages There are many languages which support object oriented programming. Tables 1.1 and 1.2 describe the OOP languages and features supported by them. table 1.1 Properties of pure OOP and object based languages Pure object oriented languages object based languages Properties java simula smalltalk eiffel java ada Encapsulation       Inheritance      No Multiple inheritance      No Polymorphism       Binding (Early and late) Both Both Late binding Early binding Both Early binding Genericity       Class libraries      Few Garbage collection       Persistence   Promised Less  Same as 3GL Concurrency   Less Promised  Hard table 1.2 Properties of extended traditional languages extended traditional languages Properties objective c c++ charm ++ objective Pascal turbo Pascal Encapsulation      Inheritance      Multiple inheritance    - - - - - - Polymorphism      Binding (Early and late) Both Both Both Late Early Genericity      Class libraries      Garbage collection      Persistence      Concurrency Poor Poor   
  • 40.
    The following arethe object-oriented languages, which are widely accepted by the pro- grammer. • C++ • Smalltalk • Charm ++ • Java smalltalK Smalltalk is a pure object oriented language. C++ makes few compromises to ensure quick per- formance and small code size. Smalltalk uses run-time binding. Smalltalk programs are con- sidered to be faster than the C++. Smalltalk needs longer time to learn than C++. Smalltalk programs are written using Smalltalk browser. Smalltalk uses dynamic objects and memory is allocated from free store. It also provides automatic garbage collection and memory is released when object is no longer in use. cHarm++ Charm ++ is also an object oriented programming language. It is a portable. The language pro- vides features such as inheritance, strict type checking, overloading, and reusability. It is de- signed in order to work efficiently with different parallel systems together with shared memory systems, and networking. java Java was developed by Patrick Naughton, James Gosling, ChrisWarth, Mike Sheridan and Ed Frank at Sun Microsystems. Java is an object oriented programming language and supports maximum OOP characteristics exist. Its statement structure is like C and C++, but it easier than C++. Java excludes few confusing and unsafe features of C and C++ like pointers. Java allows client/server programming. Java is used for Internet programming. The Java programs are downloaded by the client machines and executed on different types of hardware. This portability is achieved by translation of Java program to machine code using compiler and interpreter. The Java compiler converts the source program to JVM (Java virtual machine). The JVM is a dummy CPU. The compiler Java program is called as byte code. The Java interpreter translates byte code into the object code. Compiler and interpreter do the conversion of Java program to object code. 1.11 usage of ooP Object oriented technology is changing the style of software engineers to think, analyze, plan, and implement the software. The software developed using OOP technology is more efficient and easy to update. OOP languages have standard class library. The users in their program can reuse the standard class library. Thus, it saves lot of time and coding work. The most popular application of object oriented programming is windows. There are sev- Usage of OOP 17
  • 41.
    18 Introduction toC++ eral windowing software based on OOP technology. Following are the areas for which OOP is considered. (1) Simulation (2) Object oriented DBMS (3) Office automation software (4) Artificial Intelligence and expert systems (5) CAD/CAM software (6) Network programming & Internet applications (7) System software 1.12 usage of c++ C++ is a flexible language. Lengthy programs can be easily controlled by the use of C++. It permits us to create hierarchy -associated objects and libraries that can be useful to other pro- grammers. C++ helps the programmer to write bug-free program, which are easy to maintain. summary (1) C++ is an object oriented programming language invented by Bjarne Stroupstrup at AT&T Bell Laboratories. (2) The recognized council working under the procedure of theAmerican National Standard Institute (ANSI) has made an international standard for C++. (3) The disadvantage in conventional program- ming language is that the program written in these languages consists of a sequence of in- structions that tells the compiler or interpreter to perform a given task. When program code is large then it becomes inconvenient to man- age. (4) The prime factor in the design of object ori- ented programming approach is that to get back some of the faults found in the proce- dure oriented languages. (5) In monolithic programming languages such as basic and assembly language, the data variables declared are global and the state- ments are written in sequence. (6) In the procedural programming languages such as FORTRAN and COBOL, programs are divided into number of segments called as subprograms. Thus it focuses on functions apart from data. (7) Larger programs are developed in structured programming such as Pascal and C. Pro- grams are divided in multiple sub modules and procedures. (8) OOP acts with data as a critical component in the program development and does not let the data to flow freely around the systems. (9) Object: Objects are primary run-time enti- ties in an object-oriented programming. They may stand for a thing that makes sense in a specific application. (10) Class:A class is grouping of objects that have the identical properties, common behavior, and shared relationship. The entire group of data and code of an object cab be built as a user-defined data type using class. (11) Method: An operation required of an object or entity when coded in a class is called a method. (12) Data Abstraction: Abstraction directs to the procedure of representing essential features without including the background details. (13) Encapsulation: C++ supports the features of encapsulation using classes. The packing of data and functions into a single component is known as encapsulations. (14) Inheritance: Inheritance is the method by
  • 42.
    Exercises 19 eXercises (A) Answerthe following questions. which objects of one class get the proper- ties of objects of another class. In object ori- ented programming inheritance provides the thought of reusability. (15) Polymorphism: Polymorphism makes pos- sible the same functions to act differently on different classes. It is an important feature of OOP concept. (16) Object oriented technology allows reusabil- ity of the classes by extending them to other classes using inheritance. (17) The languages C++, Smalltalk, Eiffel and Java are widely used OOP languages. (18) Object oriented technology is changing the style of software engineers to think, analyze, plan and implements the software. The soft- ware developed using OOP technology is more efficient and easy to update. (19) C++ is a flexible language. Lengthy programs can be easily controlled by the use of C++. (1) Compare C and C++. (2) What is object oriented programming? (3) Explain the key concepts of OOP. (4) What is ANSI standard? (5) What are the disadvantages of conven- tional programming languages? (6) Explain the characteristics of monolithic programming languages. (7) Compare structured and procedural lan- guages. (8) List the disadvantages of procedural pro- gramming languages. (9) Explain evolution of C++. (10) List the names of popular OOP languages. (11) ListtheuniquefeaturesofanOOPparadigm. (12) What is an object and class? (13) How is data secured in OOP languages? (14) Compare and contrast OOP languages with procedure oriented languages. (15) Mention the types of relationships be- tween two classes. (16) What is structured oriented program- ming? Discuss its pros and cons. (17) How is global data shared in procedural programming? (18) Describe any two object oriented pro- gramming languages. (19) What are the differences between Java and C++? (20) Mention the advantages of OOP languages? (21) What do you mean by message passing? (22) Distinguish between inheritance and delegation. (23) Can we define member functions in private section? (24) Can we declare data member in the public section? (B) Answer the following by selecting the appropriate option. (1) Datahidingconceptissupportedbylanguage (a) C (b) Basic (c) Fortran (d) C++ (2) Function overloading means (a) different functions with different names (b) function names are same but same number of arguments (c) function names are same but differ­ ent number of arguments (d) none of the above (3) C++ language was invented by (a) Bjarne Stroupstrup (b) Dennis Ritche (c) Ken Thompson (d) none of the above (4) The languages COBOL and BASIC are commonly known as
  • 43.
    20 Introduction toC++ (a) procedure oriented languages (b) object oriented languages (c) low level languages (d) none of the above (5) A program with only one function is ob- served in (a) monolithic programming langu­ ages. (b) object oriented languages (c) structured programming languages (d) none of the above (6) The packing of data and functions into a single component is known as (a) encapsulation (b) polymorphism (c) abstraction (d) none of the above (7) The method by which objects of one class get the properties of objects of another class is known as (a) inheritance (b) encapsulations (c) abstraction (d) none of the above (8) The mechanism that allows same func- tions to act differently on different classes is known as (a) polymorphism (b) encapsulations (c) inheritance (d) none of the above (9) The existing class can be reused by (a) inheritance (b) polymorphism (c) dynamic binding (d) abstraction (10) Composition of objects in a class is known as (a) delegation (b) inheritance (c) polymorphism (d) none of the above (11) A class (a) binds the data and its related func­ tions together (b) data and their addresses (c) contains only functions (d) none of the above (12) The major drawback of procedural pro- gramming languages is (a) frequently invoking functions from main() (b) non security of data (c) non security of methods (d) none of the above
  • 44.
    C H AP T E R CHAPTER OuTlinE • • • • • • • • Basics of C++ 2.1 Introduction 2.2 Steps to Create and Execute a C++ Program 2.3 Flowchart for Creating a Source File, Compiling, Linking and Executing in C++ 2.4 C++ Environments 2.5 Typical C++ Environment (Borland C++) 2.6 Structure of a C++ Program 2.7 Illustrative Simple C++ Program without Class 2.8 Header Files and Libraries 2 2.1 inTRODuCTiOn A programmer must know rules and steps to develop programs with C++. Programs given in this book are developed using Borland’s C++ IDE compiler version 3.0. Let us try to follow the steps for creating, compiling and running programs under Borland’s C++ IDE compiler. 2.2 STEPS TO CREATE AnD EXECuTE A C++ PROGRAM For creating and executing a C++ program, one must follow various phases. The C++ program is created with an editor and saved with extension .cpp. Following this step, compilation and execution operations are to be performed. The following phases are essential in ‘C++’ when a program is to be executed in MS-DOS mode. (1) Create (2) Save (3) Compile (4) Execute.
  • 45.
    22 Basics ofC++ We would now see the steps in each phase. (1) Steps for creation of a C++ program (a) Open the Turbo C++ editor. In this book, the path selected for opening the C++ edi- tor is C:TURBOC3TCBIN. Executable file TC is to be clicked in BIN file to open the window of C++. (b) In the Edit menu section with alt+f, select the New option. A new file is selected with this procedure. (c) The program should be written in ‘C++’ editor. (2) Saving a C++ program (a) Save the program using the Save option in the file menu with extension .cpp. The reader may create his/her own folder where programs are to be stored. The file name does not necessarily include extension “.cpp.” The default extension is “.cpp.” The user can also specify his/her own extension. The C++ program includes preprocessor directives. (3) Compilation of a C++ program (a) The source program contains statements that are to be translated into object codes. These object codes are used for execution by the computer. So, compile the source code with alt+c keys. (b) If the program contains errors, the programmer should correct it using C++ editor. (c) If there is no error in the program, compilation proceeds and the translated program is stored in another file with the same file name and with extension “.obj.” This object file is stored on a secondary storage device such as the disk. (4) Linking and running/execution of a C++ program (a) The linking is also an essential process. It puts together all the program files and functions that are required by the program. For example, if the programmer is us- ing pow() function, then the object code of this function should be brought from math.h library of the system and linked to the main() program. After linking, the program code is stored on the disk. The program code generated is called the execut- able code. (b) Run the executable code file with alt+r, in case of no errors. In case there are errors, correct the program, and follow steps (1), (2), (3), and (4). 2.3 FlOWCHART FOR CREATinG A SOuRCE FilE, COMPilinG, linKinG AnD EXECuTinG in C++ The following steps are necessary for execution of a program in C++. • Write the code for a program and save it • Compile the program with a compiler • Link the program with library functions • Run the program. A flowchart for implementing the aforesaid steps is given in Figure 2.1
  • 46.
    C++ Environments 23 Openany text editor Write the code for the program Compile the program No Yes Correct the code Link with library Run the program Syntax Error / s? Save the file with .cpp as an extension Figure 2.1 Flowchart for creating a C++ program, compiling and linking The process of compiling, linking and running a program in C++ is elaborated in the following section. 2.4 C++ EnViROnMEnTS C++ programs can be implemented on different operating systems such as UNIX, Linux, Win- dows, and DOS, etc. C++ programs executed under DOS environment can also run successfully under Windows, because we have to follow the same programming rules on both platforms. Only the C++ execution environments are different. Various types of C++ compilers are described below. (1) GNU C++: The GNU C++ is a compiler and it is available in the source code form. It is available in different versions. (2) NDP C++: NDP C++ is also a C++ compiler, i.e. compatible with AT&T C++ 2.0 for DOS,UNIX , Sun OS, etc. (3) Oregon C++: Oregon C++ is a C++ compiler compatible with AT&T C++ 2.0 for a variety of UNIX systems. (4) Zortech C++ Version 2.1: This compiler has been developed for MS-DOS, OS/2, and UNIX. (5) Borland C++: Borland C++ compiler is a combination of two compilers. They areANSI standard C compiler and C++ compiler. It runs on MS-DOS. Borland C++ includes Tur- bo Assembler, Turbo Debugger, and Turbo Profiler. In the following section, brief information for creating, compiling, and executing C++ programs are described using Borland C++ compiler.
  • 47.
    24 Basics ofC++ 2.5 TYPiCAl C++ EnViROnMEnT (BORlAnD C++) In this section, brief information is given about the different platforms for C++ implementation, and execution of C++ programs using Borland C++ compiler under the Windows platform is described. STEP 1: OPEn AnY TEXT EDiTOR Unix/Linux platform: Use text editors such as Gedit, Kwrite, Medit, ed, VI, etc. Windows platform: Use text editors such as Notepad, Wordpad, etc. Alternately, one can use integrated Borland C++ compiler, which supports its own text editor. Once Turbo C++ is installed, it automatically creates a directory turboc3 and subdirectory bin. Follow the path c:turboc3 and click the executable file tc. One can use desktop shortcut for turboc3. Turbo C++ screen appears, which is blank initially and has a menu bar at the top, which is shown as follows. STEP 2: WRiTE THE CODE FOR THE PROGRAM Write the code to fulfill the requirements of the program, if possible using the proper syntax and indentation using an editor.
  • 48.
    Typical C++ Environment(Borland C++) 25 Alternatively, create a source program using integrated Turbo C++ editor. Go to the File menu and select New. The file name NONAME00.CPP appears on the screen at the centre of the window. Check whether your source program is typed correctly. If mistakes are found, correct them. STEP 3: SAVE THE FilE WiTH .CPP AS An EXTEnSiOn
  • 49.
    26 Basics ofC++ Now press F2 to save your program or use Save option with .cpp extension. You can change the file name and save it using the Save option in File menu. In the following window the file is saved with ABC.CPP. STEP 4: COMPilE THE PROGRAM Unix/Linux platform: Open the terminal window; change the working directory to the directory where the program file is stored. Compile the program using the command: g++ filename.cpp It will display the errors and warnings. If there are any errors and warnings, correct them and save the corrected file again. After successful compilation, file a.out will be created in the same directory. Windows platform: Use IDE such as Turbo C++. From the File menu, open the program file and compile it using ‘Compile’option in Com- pile menu or use Alt+F9. It will display the errors and warnings. If there are any errors or warnings, correct them and save the corrected file again, compile again. If program is correct, then the window shows: • Warnings: 0 • Errors: 0 After successful compilation, a file filename.obj will be created in the same directory. The fol- lowing window shows the compilation of a program named ABC.CPP.
  • 50.
    Random documents withunrelated content Scribd suggests to you:
  • 51.
    "I have toldyou, madame," said the doctor, showing a vial containing a dark liquid, "this potion will restore this child to consciousness, will light up the faint spark of intelligence which still remains, perhaps. Then the sight of the person who exercises on her so strange an influence may work a miracle, for, alas! madame, nothing but a miracle can bring your child back to life." "I know it, I know it," said Catherine, choking back her tears, "I am prepared for the worst. But, tell me, the potion,—what effect will it have?" "I can answer for its immediate effects; but not for the consequences that may follow." "What is to be done? Mon Dieu! what is to be done?" cried Catherine, in accents of anguish. "Do not hesitate, madame," I said; "since all hope is gone, accept the only chance that remains!" "I am of the same opinion, do not hesitate, madame," said Frank, who shared our emotion. "Proceed, monsieur," whispered Madame de Fersen, in an accent of desperate determination; and she knelt down by her child's cot. Her lips moved in prayer. She, Frank, and I fixed upon the doctor sorrowing and apprehensive looks. He alone was calm, as with slow and silent steps he approached Irene's bedside. At the sight of his tall figure, his austere countenance, his long white hair, his peculiar garb, one might have supposed him a man gifted with some occult power, ready to perform by a potion some mysterious charm. He poured into a golden spoon a few drops of the liquid contained in the vial. Madame de Fersen took it, and approached the spoon to the child's lips.
  • 52.
    But her handtrembled to such an extent that the liquid was spilled. "I am afraid," said she, with a frightened look. She gave back the spoon to the doctor. He filled it once more, and with a firm hand put it to Irene's lips. The child swallowed it without reluctance. It is impossible to express the intense alarm, the mortal anguish, with which we watched the effects of the potion. The doctor himself, eagerly bending over the bed, watched Irene's face with anxious eyes. Soon the potion began to work. By degrees, Irene began moving her arms and hands, and her cheeks assumed a faint tinge of colour. Several times she quickly turned her head on her pillow, moaned piteously, closed her eyes, and then opened them. The lamp was in front of her, and the bright light seemed painful, for she covered her eyes with her hands. "She sees! she sees!" cried the doctor, with an alacrity that seemed to us of good omen. "She is saved!" exclaimed Catherine, clasping her hands, as if in thanks to Heaven. "No rash expectation, madame!" said Doctor Ralph, austerely and almost harshly. "I have already told you this semblance of life is deceptive. It is like galvanism which gives motion to a dead body, and a breath may snap the invisible cord which binds this child to life." Then, turning to me, he added: "It will be your turn, monsieur, presently to endeavour to strengthen that feeble thread. I solemnly declare, if that child lives, which, alas! I scarcely dare to hope, it is to you she will owe it, for known science does not work such miracles." "God alone can work them," said Frank, in a solemn voice. "Or certain mysterious and magnetic influences which one must concede without understanding them," added the doctor.
  • 53.
    The stimulus ofthe potion upon Irene became more and more apparent. Two or three times she sighed deeply, held forth her arms, and then murmured, in a feeble voice: "Mother! Arthur!" "Now," said the doctor, "take one of the child's hands in yours, monsieur, and let the other be in her mother's; come as close to her as possible, and call her, softly, slowly, so that the sound may have time to reach her feeble hearing." I took hold of one of Irene's hands, her mother held the other. Her hand was cold and moist. I leaned over Irene. Her big eyes, looking still larger since her illness, wandered around as if in search of some one. "Irene—Irene—I am here," I said, in a low voice. "Irene—my child—your mother is here also," said Catherine, with an accent of passionate and fearful anxiety impossible to describe. At first the child did not seem to hear us. "Irene—it is your friend—it is Arthur and your mother. Do you not hear her?" "Your mother—mon Dieu! your mother is near you!" repeated Catherine. This time the child's look no longer wandered. She moved her head suddenly, as if a sound from afar had reached her. "How is her hand?" inquired the doctor, in a whisper. "Still cold," I answered. "Still cold," rejoined the mother. "That is bad, you are not yet en rapport,—continue." "Irene—dear child—angel—do you hear me? It is I—Arthur," I whispered. Irene raised her eyes, and met mine fastened on her. I had often heard magnetic attraction spoken of, and this time I experienced its action and reaction.
  • 54.
    I fixed aneager and despairing glance upon Irene. By degrees, as if her eyes took life from mine, they lost their dullness, they became clear, bright, beaming with intelligence. On her countenance, returning to life, I could follow the progress of her thoughts, of her awakening mind. She threw out her arms, and an angelic smile lighted on her lips. Too weak to raise her head, she sought her mother with her glance. Catherine bent over the bed, still holding, as I did, one of Irene's hands. After looking at us for a moment, the child gently brought together her mother's hand and mine; her eyes suffused with tears, and she wept freely. When my hand touched Catherine's, my heart received an electric shock. For a moment I heard no more, I saw no more. I held Catherine's and Irene's hands in mine, and became unconscious of the contact. It seemed to me that a flood of electricity surrounded us, and blended us in one. This impression was deep, inexplicable, almost painful. When I regained consciousness, I heard the doctor exclaiming, "She has shed tears! she is saved!" "You have given her back to me," said Catherine, falling on her knees before me. CHAPTER XXIII THE GROVE This healing crisis saved Irene. During the month of convalescence I left her neither by day nor by night.
  • 55.
    In the earlydays of spring, Doctor Ralph urged Madame de Fersen to go to the country with her daughter, and recommended the vicinity of Fontainebleau. Madame de Fersen having seen a very pretty cottage, called the Grove, had secured it, and the necessary repairs having been made, it was decided we should take up our residence there the first days of May. If my continuous abode at Madame de Fersen's house had been known, it would have provoked the most odious comments. Consequently, the morning after the crisis, which had proved so favourable to Irene, I told her mother that she must forbid access to her apartment to every one, with the exception of the doctor, the nurse, and one of her maids, on whose discretion she could rely. I had occupied during Irene's illness a vacant entresol, of which the windows opened on an uninhabited piece of ground, thus my return to Paris and my presence at Catherine's house was unknown to every one. Madame de Fersen took to Fontainebleau only the same people who had been in attendance on her during her little girl's illness, the nurse and two maids. The rest of the household remained in Paris. She asked me to follow her to the Grove in two days. She took her departure. The next morning I received from her most detailed instructions about finding my way to the small park gate at the Grove. At the appointed hour I was at that gate; I knocked, and it was opened. The sun was about setting, but it still threw some warm rays across the green lacework and violet clusters of an arbour of glycynia, under which Catherine was waiting for me with Irene, whose hand she was holding. Was it intentional, or was it mere chance? I know not, but like the day when for the first time I saw her on board the Russian frigate, Catherine wore a gauzy white gown and a lace head-dress ornamented with a spray of red geranium.
  • 56.
    The trials throughwhich she had passed had made her fall away, but she was still beautiful, and even more lovely than beautiful. Her figure, as heretofore, was elegant and stately; her countenance noble, gracious, and pensive; her large, soft eyes of a perfect blue were fringed with long, dark lashes; the heavy tresses of her jet black hair framed her brow, lofty and sad, and her face paled by sorrow. Irene, like her mother, was dressed in white; her long dark hair was tied with ribbons and fell to her waist, and her lovely face, though still pensive and sad, showed scarcely any traces of her recent sufferings. Catherine's first impulse was to take her child in her arms, and, placing her in mine, she said, with great emotion, "Is she not now your Irene also?" And amid her tears her eyes shone with joy and gratitude. There are emotions which one cannot attempt to describe, for they are as vast as the infinite. This first outburst of happiness passed, Madame de Fersen said to me, "Now I must show you to your apartment." I offered Catherine my arm, Irene took my hand, and allowed them to lead me. For some time we kept silent. After following a long avenue, rapidly becoming dark as the sun sank below the horizon, we came to a clearing on the outskirts of the wood. "Here is your cottage," said Madame de Fersen. My cottage was a sort of Swiss chalet, half hidden in a mass of pink acacias, of linden-trees and lilacs. It was built on the edge of a small lake, on a foundation of great boulders of that flinty rock found in the neighbourhood of Fontainebleau. This structure having been erected as a point of observation, every advantage had been taken to make the most of its charming position. A thick carpet of periwinkles, of ivy, of moss, and wild strawberry covered almost entirely the whitish rocks, and from each cranny
  • 57.
    sprouted a tuftof iris, of rhododendron, or heather. On the other side of the lake a beautiful lawn, surrounded by the woods, rose in a gentle incline up to the front of the house occupied by Madame de Fersen, and which might be seen from a distance. The sight was limited on all sides by a ring of verdure, formed by the thick woods surrounding the high walls of the park, and hiding them completely. One might have wished more variety in the prospect; but as our life at the Grove was to be surrounded by the most profound mystery, this extensive and impenetrable barrier of leafage was very precious. After a few minutes we reached the foot of the steps leading to the cottage. Madame de Fersen drew a small key from her belt and opened the front door. At a glance I saw that she had been the presiding genius in the arrangement of the two rooms. Everything was of excessive but elegant simplicity. I found flowers on every side; also a piano, a painter's easel, and some books which she had heard me mention as my favourites. Pointing out to me an ebony cabinet frame with doors richly inlaid with mother-of-pearl, Madame de Fersen asked me to open it. On one side I found the exquisite sketch which Frank had made of the dying Irene, and on the other side a recent portrait of Irene also painted by Frank. I took Catherine's hand and carried it to my lips, with a feeling of inexpressible gratitude. She herself pressed her hand to my lip with an impulse full of tenderness. She then turned and passionately embraced her child. I closed the panel, still more touched by this mark of Catherine's remembrance, for I had expressed to her my views regarding portraits exposed to the gaze of all. When we left the cottage, the purple and gold of the dying sun was mirrored in the bosom of the lake. The acacias were dropping their roseate and fragrant petals. No sound was heard; on all sides the horizon was bounded by dark masses of verdure; we found ourselves in
  • 58.
    the midst ofthe most profound solitude, the most peaceful, the most mysterious. Impressed by the sight of this sad and touching picture, Catherine leaned on the balcony of the chalet, and remained a few minutes plunged in reverie. Irene sat at her feet, and began to gather roses and honeysuckle to make a bouquet. I leaned against the door, and could not help feeling a pang of anguish as I looked upon Madame de Fersen. I was going to pass long days near this woman, so passionately loved, and delicacy forbade my speaking one word of this deep and ardent love, which circumstances recently had combined to increase. I knew not if I was beloved, or, rather, I despaired of being loved; it seemed to me that fate, which had brought Madame de Fersen and me together, by the death-bed of her child, during a month of terrible anguish, had been too tragic to end in so tender a sentiment. I was absorbed in these sad thoughts, when Madame de Fersen made a quick movement, as if she were aroused from a dream, and said to me, "Pardon me, but it is so long since I breathed air so fragrant and invigorating that I selfishly enjoy this lovely nature." Irene divided her bouquet in two, gave one half to her mother, the other to me, and we then started towards the house. We reached it after a long walk, for the park was very extensive. CHAPTER XXIV DAYS OF SUNSHINE THE GROVE, 10th May, 18—.[6]
  • 59.
    It is eleveno'clock; I have just left Madame de Fersen. Here am I in the chalet, which, henceforward, I am to occupy near her! I experience a strange emotion. Events have succeeded each other with such rapidity, my heart has been torn by such conflicting passions, that I feel the necessity of reviewing my memories, my desires, and my hopes. I therefore resume my journal, interrupted after my departure from Khios. My thoughts press so confusedly upon my brain that I hope to clear them by writing. I act like those who, unable to make a mental calculation, are obliged to have recourse to pencil and paper. What for me will be the end of this love? Doctor Ralph has formally declared to Madame de Fersen that, for a long time yet, my presence is indispensable to Irene's perfect recovery, and that, for two or three months longer, it was absolutely necessary to soothe the child's imagination, and not give her the slightest shock or the least sorrow, these emotions being the more dangerous for her in that they were so profoundly concentrated. Doctor Ralph attributes the attraction which I have for Irene to magnetic and mysterious affinities and he cites many examples, both among human beings and animals. He is unable, however, to offer any explanation of this. As I said, this attraction places me in a singular position. The effect of my presence or absence upon this child is a proven and undeniable fact. For the past year Irene has had three or four attacks, sometimes slight, others serious and almost fatal, whose sole origin was her grief at not seeing me, and, above all, at not seeing me near her mother; for the nurse has since told me that even our meetings at the Tuileries did not quite satisfy Irene, who pined for the time spent on board the frigate. My presence, therefore, is, one may say, the tie that binds Irene to life. Were it not for my love, my passion for Catherine, were it not for the deep interest her child inspires in me, this imperious obligation to remain
  • 60.
    ever at Irene'sside would be both painful and embarrassing. But I worship her mother! When I compare other passions which I have experienced to that which she inspires, I find this the truest of all; and, seeing her daily, brought near her by the most startling and mysterious circumstances, most apt to bring the most passive love to a point of exaltation, I still must be silent; Catherine for me must be sacred as a sister, as a friend! Can I, in the name of my past devotedness, in the name of the fatal influence I exercise over Irene, approach Catherine, professing my love, and expressing my hopes? It would be base, it would be despicable. And if the unhappy mother were to think—oh, Heaven!—that I demanded her love as the price for my presence near her child! Ah, this thought is horrible! My resolution is taken, irrevocably taken. Never shall a word of love pass my lips. THE GROVE, 11th May, 18—. My best deeds bring me bad luck,—one reason the more for keeping silent. This morning the newspapers were brought in. Madame de Fersen opened one, and began to read. All at once she ceased to read, I saw her shiver and blush deeply; then, with an expression of dumb surprise, lowering her hands to her knees, she shook her head, as if she were saying, "Is this really possible!" Looking at me with eyes filled with tears, she quickly rose, and left the room. Not knowing what might have caused this keen emotion, I picked up the newspaper, and the following lines soon explained to me Madame de Fersen's dismay.
  • 61.
    "It is wellknown that a month ago the firm —— & Co. failed for a sum amounting to several millions. The head of the firm secretly embarked for the United States. A few creditors, warned by alarming rumours as to the solvency of the firm, were in time to withdraw a portion of their funds. M. Dumont, business agent of M. le Comte de ——, involved in this bankruptcy to the amount of one hundred and fifty thousand francs, has not been equally fortunate; although he had come to Havre to ward off this disaster, he was not provided with the necessary papers, and as the bankruptcy was considered fraudulent, he laid his complaint before the district attorney, but in view of the assets amounting to scarcely eighty thousand francs, the numerous creditors of the firm —— must look upon their funds as lost." Madame de Fersen knew of my hurried departure for Havre, for her courier had overtaken me before I reached that town. I had returned immediately, and the date of my return coincided with that of the bankruptcy. It was therefore evident to Catherine that my eagerness to return to the dying Irene was the sole cause of the severe loss I had sustained. Thus now, more than ever, should I appear to demand a reward for my sacrifices. While mechanically skimming the newspaper, beneath the article which I have quoted, I came upon the following paragraph, which also concerned me. The paper which I was reading was a semi-official journal, and might be considered well informed. "Many changes are imminent in our corps diplomatique. Among those mentioned as likely to be called to a prominent position in foreign affairs is M. le Comte Arthur de ——, who, though still young, has strong claims to this favour on account of his travels, his researches, and the conscientious work to which he has devoted himself for some time past, as chief secretary of his Excellency the Minister of Foreign Affairs. These particulars, for whose accuracy we can vouch, prove clearly that when high birth and the advantages of fortune accompany an eminent and
  • 62.
    recognised capacity, everythingmay be expected from the favours of the king's ministry." This article evidently emanated from the office of M. de Sérigny, who thought, perhaps, that it would give me pleasure if, during my absence, he asked the king some favour for me. I must confess, this piece of news left me indifferent, and I went in search of Catherine. I found her in an avenue of the park. "I know all," she said, holding out her hand. "Another sacrifice," she continued, raising her eyes to heaven. "And I, what have I done for him?" These words went to my heart, and produced so great, so sweet an emotion, that, in spite of myself, my hopes once more were aroused, but, controlling my thoughts, and wishing to change the subject, I said: "Do you not congratulate me on my future successes?" She looked at me in amazement. "What successes?" "Have you not read to-day's paper?" "Yes, I have. But of what success are you speaking?" "They say in this paper that very soon I shall be called to a very important position at the Foreign Office." Catherine, without appearing to have heard me, replied: "Will you make me a promise?" "What is it?" "I shall send Irene to you to the chalet, but I do not wish to see you to-day. You will not be vexed with me?" she said, sadly, to me, holding out her hand. "No, certainly not," I said, much surprised, however, at this sudden determination.
  • 63.
    THE GROVE, 13thMay, 18—. How long is it since this journal was interrupted? I know not. I cannot remember. Besides, what do I know now? What do I remember? All that has happened, is it not a dream, a dream so dazzling that I ask myself where is the limit of reality? Where ends the dream? Where commences the awakening? Dream, memory, awakening! These are vain words, and faded, which I used before this day. I wish now for new words to describe what I had never before felt. Not only does it seem to me impossible to use the words of other days to describe my feelings of to-day, it seems to me a blasphemy, a profanation. Am I not the dupe of a delusion? Is it I, my own self, who is writing this at the Grove, in the chalet? Yes, yes, it is my own self. I am looking at the clock which points to the hour of five. I see the lake reflecting the rays of the sun. I hear the trees rustling in the breeze. I scent the fragrance of the flowers, and in the distance I see her dwelling,—hers. It is not, then, a dream? Let me see, let me gather my thoughts, let me go back step by step to the source of that torrent of happiness which intoxicates me. What day is this? I know not. Ah, yes, it is Sunday. She went to mass this morning, and there she wept, she wept abundantly. Blessed be those precious tears! But when did we receive those papers? Ah, here they are,—it was the day before yesterday. The day before yesterday! 'Tis strange! If years had passed since that day it would not seem to me further away! Between the past of yesterday, which was almost indifferent to us, and the present to-day, which is all in all to us, is there not the distance
  • 64.
    of centuries? Yes, itwas the day before yesterday that Catherine begged me to leave her to herself. I obeyed her wishes, but felt very sad. Irene came to play on the steps of the chalet. The dinner bell sounded. Instead of appearing at table, as usual, Catherine sent word begging me to dine by myself, for she was suffering. In the evening the air was sultry. Catherine came down to the parlours. I found her looking very pale. "I am stifling," she said, "I am restless, nervous, agitated, the weather is so stormy." She then asked me to give her my arm, as she was going to walk in the park. Contrary to her custom, she requested Madame Paul, Irene's nurse, to follow us with the little girl. We followed the winding avenue of the woods, and soon came upon the arbour, covered with glycynia, where she had waited for me with Irene the first day of my arrival at the Grove. I know not whether it was emotion, or fatigue, or indisposition, but Catherine complained of feeling tired, and seated herself on a bench. The sun had just set; the sky was covered with clouds, gilded by the last rays of the sun. Almost continuously the entire hemisphere was illumined with vivid flashes of summer lightning, which Irene watched with a curious and tranquil air. Catherine did not speak, and seemed deeply absorbed. Twilight had begun to darken the woods, when Irene, who was resting on her nurse's lap, fell asleep. "Madame," said Madame Paul, "Mlle. Irene is falling asleep, and the doctor was very particular that she should not be exposed to the damp evening air." "Let us go home," said Catherine, as she rose.
  • 65.
    She felt soweak that she leaned on my arm with her whole weight. We walked a few steps, but very slowly; Madame Paul was in front with Irene. Suddenly I felt Catherine giving way, and she said, in a broken voice, "I cannot take another step, I am prostrated." "Just make an effort," I said to her, "to reach the chalet, which is close at hand, and you can rest on the bench at the door." "But, Irene!" she exclaimed, anxiously. A turn in the road hid the nurse, who was already some way in advance. I supported Catherine, and a few seconds later she was seated at the entrance of the chalet. The threatening clouds had dispersed; at our feet we saw the lake reflecting the stars as they made their appearance; the perfume of flowers, rendered more acute by the warm and sultry weather, permeated the atmosphere; there was not a breath of air, not a sound. The night was so soft, so balmy and clear, that in the uncertain light I could perfectly distinguish Catherine's features. My whole being seemed concentrated in my heart, which was beating violently. Like Catherine, I felt overpowered, unnerved, by the warm, perfumed air which surrounded us. Madame de Fersen was seated, resting on cushions, her head leaning on her hands. The calm was so intense that I could hear Catherine's panting breath. I fell into a deep reverie, at once sad and blissful. Never, perhaps, would I have a more favourable opportunity to unbosom myself to Catherine; but my scruples, and the dread of seeming to ask reward for a service rendered, kept me silent. Suddenly she exclaimed: "I implore you, do not leave me to my thoughts; let me hear your voice. Tell me all you wish, but speak to me; in the name of Heaven,
  • 66.
    speak to me!" "Whatshall I say?" I replied, submissively. "What matters!" she cried, clasping her hands in supplication; "what matters! only speak to me, drive from me the thoughts which possess me, have pity, or, rather, be pitiless,—accuse me, overwhelm me, tell me I am a thankless, selfish woman, base enough not to have the courage to be grateful," she continued, with increasing excitement, as if a secret long suppressed was now escaping her. "Do not soften your reproaches, for you cannot tell how deeply your resignation wounds me, you cannot tell how I long to find you less generous. For what can be said of a woman who meets a true, discreet friend, and for six months permits him to surround her with the most delicate, most assiduous, and respectful attentions, sees him devote himself to the least whims of her poor, suffering child, and who, one day, in all thanklessness, and for the idlest and most puerile of motives, coldly dismisses this friend? And this is not all. When this woman, in a terrible dilemma, again has need of him,—for she knows he alone can save her child's life,—she forthwith recalls him, well aware that she can demand everything from the self- denial of this brave heart; and he, sacrificing all, instantly returns to draw this child from the very jaws of death!" "Hold, I pray you! Let us not recall these sad memories, let us only think of our present happiness," said I. But Catherine appeared not to hear me, and continued with an ever increasing excitement which alarmed me: "This friend, so good, so noble, has he ever attempted by a single word to speak of his admirable conduct? He has been the protecting genius of this woman and her child when both were suffering; and when he has saved them,—for to save the child is to save the mother,—he goes, proudly, silent, and reserved, happy doubtless in the good he has done, but seeming to fear the thanklessness or disdain the gratitude he has inspired." Catherine's voice was growing more and more broken and gasping. I was almost frenzied by her words, but they seemed to me drawn from her by feverish excitation, and contrasted so forcibly with her habitual reserve that I feared her reason, until now so strong and clear, had
  • 67.
    yielded to thetardy reaction of the terrible experiences which had shaken her for the past six weeks. "Catherine, Catherine!" I exclaimed. "You are too passionately devoted to your child for me ever to have doubted of your gratitude,— my dearest, most precious reward." Catherine heard my reply, for she alluded to my words as she continued in a still more passionate accent: "Oh, yes, yes; tell me, then, that the intoxicating, invincible sentiment that invades me at this moment is gratitude; tell me that nothing is more sacred, more holy and legitimate, than what I feel. A woman has certainly the right to devote her life to him who has restored her child to her, more especially when he, as generous as he is considerate, has never attempted to say one word of his hopes; therefore, is it not for her—for her—to come to him, and ask with joy, with pride, How can I ever reward so much love?" "By returning it!" I exclaimed. "By confessing that I have always returned it," said Catherine, in a subdued voice. And her hands languorously fell into mine. THE GROVE, 16th May, 18—. Woe! Woe! Since yesterday I have not seen her. Doctor Ralph arrived last night. He found her in great danger. He attributed this devouring fever, this terrible delirium, to reaction from the anguish which the unfortunate woman had repressed during her child's illness. He does not know all. Ah, her remorse must be terrible! How she must suffer, and I am not there, by her side,—and I cannot be there. Ah, yes, I love her, I love her with all my strength. This intoxicating memory, which yesterday made me almost frenzied with love, to-day I curse it!
  • 68.
    The sight ofIrene hurts me. This morning the child came towards me, and I repulsed her. She is fateful to her mother, as, perhaps, she will be fateful to myself. Doctor Ralph has just left me; there is no change for the better. I observed a strange difference in him. This morning, on his arrival, he gave me his hand as usual cordially; the austere expression of his face generally assumed a look of benevolence on meeting me. This evening I gave him my hand, he did not grasp it. His glance seemed to me severe, interrogative. After having briefly informed me of the state of Catherine's health, he coldly left the room. Can Catherine have betrayed herself in the wanderings of fever? This thought is dreadful. Happily, there is near her no one but Irene's nurse and Doctor Ralph. But what matter! what matter! This nurse is only a servant, and this doctor is but a stranger! And is she, so proud, because heretofore she had a right to be so, condemned henceforth to blush before these people! If she has spoken, she is not aware of it, perhaps may never know it, but they know it, they, perhaps, have her secret and mine. If with a word one could annihilate two persons at once, I believe I would utter that word. THE GROVE, 17th May, 18—. What is to be done, what will become of us, if Catherine so rapidly gets worse? Doctor Ralph will no longer take the sole responsibility, he will call in some consulting physicians, and then— I cannot continue to write, my sobs stifle me. This morning something very strange happened. When the doctor announced to me that Catherine was worse, I came back here in the chalet; I wished to write down what I felt, for I cannot
  • 69.
    and will notconfide to any one my joys and sorrows; so, when my heart overflows with grief or happiness, it is a great relief to me silently to confide to this journal. When I heard of Catherine's renewed danger, my sufferings were so great that I wished to write, that is, to pour out my anguish. This was impossible. I could only trace with a trembling hand the few lines at the head of this page, but was soon interrupted by my tears. Then I went out into the park. There, for the first time, I regretted—oh, bitterly regretted—that I possessed neither religious faith nor hope. I might have prayed for Catherine. There is certainly nothing more heartrending than to recognise the utter futility of addressing prayers to Heaven for a beloved being whom you fear to lose. In prayer you have some minutes of hope, you are fulfilling a duty, your sorrow at least has a language, which you believe is not quite barren. But not to be able to say to any human or superhuman power, "Save her!" It is terrible. I so painfully felt this helplessness, that in despair I fell on my knees, without having consciousness to whom my prayer was addressed. But firmly convinced, in that momentary hallucination, that my voice would be heard, I cried aloud: "Save her! Save her!" Then, in spite of myself, I experienced a glimmer of hope, I felt the consciousness of a duty fulfilled. Later I blushed for what I called my weakness, my puerility. Since my mind could not grasp, could not believe, the assertions which constitute the various human religions, what God was I imploring? What power had succeeded in tearing from me this prayer, this last cry, this the last utterance of despair? The crisis which the doctor feared did not take place.
  • 70.
    Catherine is nobetter, but she is not worse, and yet her delirium continues. Doctor Ralph's coldness towards me is still excessive. Since her mother's illness, Irene has given frequent proofs of tenderness and feeling, which, though childlike, are serious and resolute like her character. This morning she said to me: "My mother suffers very much, does she not?" "Very much, my poor Irene." "When a child is suffering, her mother comes to suffer in her stead, so that the little one may not suffer any more, is it not so?" she inquired, gravely. Astonished at this reasoning, I looked at her attentively without replying. She continued: "I wish to suffer in my mother's place, take me to the doctor." This childish trait, which, under other circumstances, would have made me smile, gave me a heart pang, and I kissed Irene to conceal my tears. THE GROVE, 17th May, 18—. There is hope; the delirium ceases; an alarming prostration has followed. Doctor Ralph dreaded the heat of her fevered blood. Now he fears excessive languor, heart failure. Her consciousness has returned. Her first utterance was her child's name. The nurse told me that the doctor had not yet allowed Irene to go near her mother. Twenty times have I been on the point of asking Madame Paul if Catherine had inquired after me, but I dared not. THE GROVE, 18th May, 18—.
  • 71.
    To-day, for thefirst time, Doctor Ralph permitted the nurse to take Irene to her mother. I waited with anxious and irritable impatience for the moment when I would see Irene, hoping from her to have some particulars about her mother, perhaps a word, a remembrance, from Catherine. Once returned to consciousness, I know not what course Madame de Fersen will take towards me. During the paroxysm of remorseful despair which follows a first fault, a woman often hates the man to whom she has succumbed; she overwhelms him with reproaches as violent as her regrets, as vehement as her sorrow; it is on him alone the sole responsibility weighs for their guilt; she is not his accomplice, but his victim. If her soul has remained pure, notwithstanding that for a moment she was involuntarily led astray, she takes the sincere resolution never again to see the man who has seduced her, and to have to weep over one sole betrayal, one sole defeat. To this resolution she at first remains faithful. She seeks, not to excuse, but to redeem her error, by the rigorous fulfilment of her duties; but the remembrance of her fault is there, ever there. The more noble the heart, the more austere the conscience, so will the remorse be the more implacable. Then, alas! she suffers terribly, the poor creature, for she stands alone, and is compelled in secret to devour her tears, while to the world she still wears a smile. Sometimes, again, she becomes frightened at her isolation, at that wordless concentration of her grief, and she resigns herself to ask for comfort and strength of the man who is the cause of her fall. She then implores him, for the sake of her remorse, to forget a moment of madness, and to be for her no more than the truest of friends, the confidant of the sorrows he has brought upon her. But, alas! almost always the unhappy woman has still more tears to shed. Man, with the coarser instincts of his sex, does not realise the sublime struggle which woman endures between love and duty. The incessant torture, the menacing terrors aroused in her by the
  • 72.
    remembrance of outragedreligion and family honour, these dreadful tortures are treated by man as ridiculous whims, as childish scruples, or the absurd influence of the confessional. If the struggle is prolonged, if the unhappy woman passes her life in efforts to conceal a sorrow caused by her dishonour, and valiantly resists the commission of a second fault, the man is irritated, and revolts against these pruderies which wound his self-love and his eager and brutal passion to the quick; for one last time he reviles her virtue, her sorrows, and her courage by saying to this miserable woman that her return to high principles is somewhat tardy. Frenzied by a base desire for revenge, he at once rushes with his cynical nature to make a notorious display of some other intrigue. He has been loved, he is still beloved! A virtuous and beautiful woman has jeopardised, for his sake, her happiness, her future, and that of her children! while he basely recoils from the least sacrifice. How comes it that this man is so worthless, and yet so worshipped? Because woman loves man more for the qualities she attributes to him, and with which her sensitive nature adorns him, than for those he really possesses. If, on the contrary, by a rare exception, a man realises all that is saintly and beautiful in this remorse, if he endeavours to comfort the sorrow of which he is the origin, the woman's gentleness and resignation may prove for her another pitfall. Catherine,—will she be pursued by incessant remorse? Like those women who, from an insatiable yearning for sympathy, or, with the chastity of sorrow, conceal their woes, and make only a display of their joys, will Catherine leave me in ignorance of the anguish she suffers? Knowing her as I do, I believe, after I have seen Irene, and gathered from her the substance of her conversation with her mother, I shall be able to divine Catherine's sentiments towards me. Hence I look forward with eager impatience to the child's visit.
  • 73.
    Heaven be praised!I see her running, holding in her hand a bouquet of roses. My heart did not deceive me; Catherine sends it to me. She forgives me my happiness.
  • 74.
    [6]Arthur, according tohis custom, introduces here some fragments from his journal, interrupted after leaving Khios, and doubtless, resumed on his arrival at the Grove. The preceding chapters are intended to fill the gap separating the two periods, during which time Arthur appears to have neglected to keep his memorandum. CHAPTER XXV A WOMAN IN POLITICS Here come to an end the fragments of the journal I formerly wrote at the Grove. During the four months which followed Catherine's confession of her love, and which we passed in this total isolation, my life was so engrossed by the delights of our ever growing love that I had neither time nor inclination to make a record of emotions so entrancing. Catherine confessed to me that she had felt greatly attracted to me ever since our departure from Khios. I asked her why she had treated me so harshly on one occasion, when she had requested me not to see her little girl any more. She answered that her despair at feeling herself at the mercy of the affection I inspired, added to her jealousy and grief when she saw me smitten by so giddy a woman as Madame de V——, had alone decided her to put an end to the mysterious intimacy of which Irene was the bond, however painful to her was this determination. Later on, when she learned of the termination of my supposed intrigue with Madame de V——, and finding that absence, instead of
  • 75.
    diminishing, only increasedthe power I had gained over her, she endeavoured to renew our former relations. Moreover, Irene commenced to be seriously affected by my absence. "Love is so inexplicable in its contrasts and its sensitiveness," said Catherine to me, "that this very reason, added to your seeming coldness and disdain, made me hesitate frankly to come to you, fearing that this step might have appeared to you simply dictated by my anxiety for my child's health. "The condition of that poor child became so much worse that I resolved to conquer my timidity and tell you all at that ball at the Tuileries, but your greeting was so freezing, your departure so abrupt, that it became impossible for me. The next day I wrote to you; you did not answer. It was not, alas! until Irene's life was despaired of that I dared once more to write to you at Havre! God only knows with what admirable generosity you responded." After the first bitterness of her remorse, Catherine's love for me became calm, dignified, almost serene. One felt that, having exercised all her might to resist an unconquerable passion, this woman was prepared to endure with courageous resignation the consequences of her weakness. The four months we spent at the Grove were for me, for her, the ideal of happiness. But wherefore speak of happiness? This is now but Dead Sea ashes! What matter, alas! Let me continue the sad task I have imposed upon myself. When I was able to snatch some moments from the love which engrossed me, I wrote to M. de Sérigny to thank him for his good intentions towards me, which I had learned from the article in the official newspaper, and informed him that I would be absent for
  • 76.
    some months yet,that I was unable to disclose to him my place of abode, but begged him, in case any one inquired of him for me, to answer in such a way as might lead people to infer that I was in a foreign country. In the month of September Catherine heard that her husband would return towards the close of the year, and informed me that she intended returning to Paris. Catherine's intention surprised and grieved me. We had considerably discussed whether or not I should resume the duties I had taken upon me with M. de Sérigny. Catherine had persistently urged me to do so. I vainly represented to her that those hours devoted to uncongenial work would be stolen from our love, and that I should find very tedious an occupation which I had sought simply as a distraction to my grief. In vain I told her that all the correspondence with which I was entrusted treated of the most futile subjects, and in no way interested me. To this she replied that at no distant period questions of the greatest importance would necessarily be discussed in high political spheres, and that I would then regret having abandoned that position. She felt so proud, so happy, of the distinction drawn upon me by the king's recognition of my merits, she said, she so gloried in my success, that I ended by promising to do as she wished. It was therefore decided between us that I should resume my position with M. de Sérigny. To avoid returning to Paris at the same time as Madame de Fersen, and in order that people might suppose I had been travelling for some time, I left the Grove for London, and came back to Paris, where I found Catherine on my arrival, after fourteen days' sojourn in London. M. de Sérigny had ably fulfilled my wishes, and in society it was generally supposed that an important foreign mission had been the
  • 77.
    cause of myabsence from home. The minister seemed quite pleased at having me once more sharing his labours; for the king, he told me, had frequently inquired as to the period of my return, expressing his regret that the briefing of despatches was no longer made by me. To the eyes of the world, I did not at first visit Madame de Fersen more assiduously than before our sojourn at the Grove; but little by little my visits became more frequent without being so noticeably. My character as an ambitious man, wholly absorbed by state affairs, and Madame de Fersen's high reputation were too firmly established in public opinion for society, so constant to its routine habits, not to accept this situation; and appearances very contrary to these ideas would have been needed to make it change its point of view towards us. The impenetrable mystery surrounding our love redoubled it. I frequently regretted our radiant days at the Grove,—days so calmly happy, so peaceful,—but on the other hand, in Paris, when I exchanged with Catherine a tender glance, unperceived by all, I felt that joyful pride which one always experiences when in possession of a secret at once formidable and enticing, from which depends the honour, the existence, and the future of the woman beloved. Some time before his departure, M. de Fersen had confided to me that his wife had become indifferent to political matters, which until then had engaged her attention to a great extent. After returning to Paris I noticed, with astonishment, that Catherine by degrees resumed her former relations. Her salon, where I visited assiduously, was, as formerly, the habitual meeting-place of the corps diplomatique. Before long, subjects which were spoken of daily became so serious that, with the exception of the ministers and some influential speakers of the two chambers, the elegant and frivolous French society disappeared almost entirely from the gatherings at Madame de Fersen's.
  • 78.
    Although serious, thesediscussions had no true importance; either they rose so high as to become abstract and impracticable theories, or they descended to such paltry and positive interests that they became frivolous and narrow. The discussions were as infinite and barren as ever on this well- worn theme: "Would the Restoration resist or yield to democratic influence?" etc. Catherine always surprised me by the subtlety of her intellect and the liberal tendencies of her convictions. One of her great triumphs was in demonstrating the advantages which France would derive by preferring the Russian to the English alliance. When I complimented her on this subject, she laughingly told me that I was France, and that the sole secret of her eloquence was that. I might as well have answered that she was my diplomacy; for to please her I conquered my profound aversion to the European gossip of the diplomats who habitually met at her house, and I persevered with my work under M. de Sérigny. Perhaps, also, I remained in this position from a feeling of pride, which I would not acknowledge, and which, no doubt, the marked distinction with which the king honoured me had given rise to, as well as from the sort of importance which it gave me in the world. Thanks also to my duties, my assiduous presence at Madame de Fersen's might be attributed to purely political associations. What charmed me in Catherine was, perhaps, less the influence which she possessed over those surrounding her, than the exquisite grace with which she renounced this highly esteemed influence with me. This woman, with a strong, lofty, even judicial mind, who was listened to with rare deference, whose least words were heard with respect, showed herself in our intimacy what she had been at the Grove,—kindly, simple, and gay, of an effusive tenderness, I might almost say of a submission full of grace and consideration, always placing her triumphs at my feet, and laughing with me at their conceit.
  • 79.
    Then, for thesake of our love, I would implore her to abandon this life so uselessly employed. On this subject alone, did I find Catherine ever intractable. She would set forth that M. de Fersen would return to Paris; that she had been guilty of a fault, a grave fault, and that she should at least atone for it by devoting herself to her husband's wishes. Before his departure he had bid her most expressly to maintain, and even to extend, the relations which she had established; and she was obeying his injunctions more to satisfy her conscience than for her own pleasure. As much as I, she regretted the former conversations of the saloon on board the frigate, and, above all, the four months spent at the Grove: this period of the heart's paradise, as she called it, those priceless days which shine but once, and never return in life,—no more than youth returns. There is nothing more exclusive, more madly absolute than passion. While acknowledging the truth of Catherine's observations, I could not avoid feeling wretched at these obligations imposed upon her by remorse for a fault which I had caused her to commit. Catherine, however, showed herself so tender, so considerate! With an incredible tact, she found means to speak to me covertly of ourselves, even in the midst of apparently serious conversations, and thus won me to bear in patience the obstacles to our love. There is nothing, in fact, so delightful as this conventional talk, by means of which lovers can speak of themselves, their hopes, and their memories, in the midst of the gravest company. Nothing amused me more than to see the most solemn men innocently taking part in our ambiguous conversations. But these people often made me pay cruelly for these mysterious joys. They robbed me almost entirely of Catherine's society of an evening, for they generally met at her house; and frequently of a morning a letter from one or the other, asking for an interview with Madame de Fersen, disarranged all our plans.
  • 80.
    Catherine suffered fromthese obstacles as much as I, but how could it be avoided? Under what pretext could she refuse the request for an interview? I, who had carried to the most scrupulous sensitiveness the fear of compromising in the slightest degree her reputation, could I encourage her in so perilous a step? No, certainly not; but I suffered cruelly from the thousand obstacles ever recurring which continually irritated the jealous impatience of my heart. Our happiness at the Grove had been so perfect! Enchanting season, lovely country, complete isolation, mysterious and extreme freedom, everything had been so beautifully arranged by chance that the comparison of that past with the present was a continuous source of irritation. These regrets did not prevent my enjoying the delightful moments that remained to us. I had perfect faith in Madame de Fersen's love; my attacks of distrust of myself and others yielded to the influence of her noble character, and the conviction that I had this time conducted myself towards Catherine as few men would have conducted themselves in my place, and that I, therefore, was deserving of all her tenderness. I felt so sure of myself that I ventured on certain analytical thoughts which I would formerly have dreaded. In a word, I had fruitlessly sought the hidden motives of Madame de Fersen's love; and I confess that, seeing her high rank, her great influence, her wealth and position, I could not, in spite of my inventive shrewdness and the resources of my suspicious mind, I could not, I say, discover what interest Catherine could have in pretending to love me. CHAPTER XXVI
  • 81.
    Welcome to ourwebsite – the ideal destination for book lovers and knowledge seekers. With a mission to inspire endlessly, we offer a vast collection of books, ranging from classic literary works to specialized publications, self-development books, and children's literature. Each book is a new journey of discovery, expanding knowledge and enriching the soul of the reade Our website is not just a platform for buying books, but a bridge connecting readers to the timeless values of culture and wisdom. With an elegant, user-friendly interface and an intelligent search system, we are committed to providing a quick and convenient shopping experience. Additionally, our special promotions and home delivery services ensure that you save time and fully enjoy the joy of reading. Let us accompany you on the journey of exploring knowledge and personal growth! ebookgate.com