Preface – Object-Oriented Programming with ANSI and Turbo C++

Preface

This book is meant for students of various disciplines such as Engineering, Science, Computer Application, and Diploma courses etc. An attempt has been made to cover the subject of C++ as per the syllabi of different branches of various universities. In view of this, the book can be adopted in one semester of engineering as well as in degree and other courses. Object-Oriented Programming with ANSI and Turbo C++ has been written for beginners, those who have some knowledge of C, and it will be a useful text for the students who are learning the OOP subject. This book is for all those who want to learn and expand their knowledge of C++ object-oriented programming.

The chapters are planned in a systematic way. In order to bridge the gap between theory and practical, each concept is explained in an easy-to-understand manner supported with numerous worked-out examples and programs. The book contains about 500 solved illustrative problems and as many as 250 exercises. The programmer can run the solved programs, see the output, and enjoy the concepts of C++.

The programs in the chapters 1 to 14 are fully tested and executed with Borland Turbo C++ compiler version 3.00 and the programs in the chapters 15 to 18 are executed with Visual C++ 6.0 compiler. The programs in chapters 19 are tested and compiled with Java compiler version 2.

BOOK ORGANIZATION

The first chapter describes the evolution of C++ language, object-oriented programming and related concepts and describes the disadvantages of conventional programming languages and the applications of C++ languages. In this chapter, all-important features of C++ are elaborated. It covers the important features of C++ such as inheritance, polymorphism, reusability, classes and objects. The presentation of object-oriented languages is given in this chapter.

After being acquainted with the idea of object-oriented paradigms in the first chapter, the reader can follow the most basic input and output functions of C++ language in Chapter 2. The streams, I/O functions, stream classes, buffer, typecasting, formatted and unformatted data, and functions are explained with figures. Most of the concepts are supported with programs. This makes the reader/programmer understand them perfectly. In addition, manipulators are discussed and how to create user-defined manipulators is presented in this chapter.

Chapter 3 explains various details of the language that are useful to write a program. This chapter covers data types, keywords, pointers etc. New operators provided by the C++ language such as new, delete, scope access operator and reference variables are explained. How to use these operators is dealt with in this chapter.

The fourth chapter is essential for learning C++ for those who have no prior knowledge of C. In this chapter the decision making statements such as if( ) and switch( ), and jumping statements such as goto, break, continue etc. are described together with examples. The looping statements such as for( ), while( ) and do-while( ) are also described. The readers who have the knowledge of C language can skip this chapter.

The behaviour of function in C++ is different than in C. Chapter 5 is essential for the programmers to learn the new behaviour of C++ functions. The C++ function supports inline mechanism, default arguments and overloading. All these concepts are explained with ample examples.

The sixth chapter deals with the basic concept of object-oriented programming. The structures and classes used for encapsulation of data and functions are explained with their differences. The access specifiers private, public, and protected with their uses are explained in a systematic way and with simple procedure. The member function, static member function, friend function, object as function arguments etc. are discussed.

Chapter 7 explains the special member function constructors and destructors. The characteristics of constructors and destructors are listed. The constructors also support various properties of functions such as overloading, default arguments etc. The advanced concepts such as nested, qualifier classes, nameless objects, dynamic initialization, const objects, copy constructor etc. are dealt with in addition to how to make explicit call to constructors and destructors.

Chapter 8 presents you with another most important feature of C++ language, i.e. operator overloading. It contains overloading of unary and binary operators, rules for operator overloading, and various examples of operator overloading with friend functions. The type conversion from basic to class type, class type to basic, and class type to another class type is explained with suitable examples.

Another important concept of OOP, i.e. inheritance is covered in Chapter 9. The effect of private, public, and protected access specifiers in inheritance is explained. How to derive a new class from existing class is the main idea of inheritance. Types of inheritance and execution sequence of constructors and destructors in inheritance are illustrated. In addition, virtual classes, abstract classes, advantages and disadvantages are discussed.

Chapter 10 covers one of the puzzling but interesting topics: pointers and arrays. Arrays are nothing but pointers. The different types of pointers such as void pointer, this pointer and wild pointer are explained. The behaviour of pointers with base and derived class objects are narrated. The arrays, array of objects and initialization of arrays using function are explained. This chapter is intended for both the beginners and advanced level students.

The eleventh chapter narrates how to make memory management with C++. The new and delete operators are explained in detail. Overloading of new and delete operators with classes are explained. The memory models, heap, constructors and destructors, creating object at given address, dynamic objects and calling conventions are illustrated with suitable examples.

Early and late binding, polymorphism, and virtual functions are dealt with in Chapter 12 in addition to rules for virtual functions, array of pointers, pure virtual functions, abstract classes and working of virtual function, virtual table and void pointers. Also, object slicing and virtual destructors are discussed with suitable examples.

The disk file operations are explained in the thirteenth chapter. The sequential and random file operations, file opening modes, file manipulators, ASCII and binary files are discussed. The various supporting stream classes with member functions are explained. Checking errors during file operation, strstreams, error trapping functions, command line arguments and sending output to various devices are discussed with examples.

Chapter 14 contains advanced topics of C++—how to perform generic programming with classes, normal functions and member functions with one or more parameters. Need of template, working of template, template based inheritance, linked list with template and other related concepts are discussed.

Chapter 15 contains one of the unique features provided by very few languages including C++. This chapter explains the exception handling mechanism with try, catch and throw blocks. This chapter guides how to throw and re-throw exceptions. Multiple catch statements, specifying exceptions, exception handling with inheritance and template are explained with examples.

The sixteenth chapter covers how to manipulate string with string class and its member functions. The string classes contain several member functions for performing string operations such as copying, deleting, searching, comparing etc.

The standard template library and its associated components are covered in Chapter 17. This chapter explains containers, lists, vectors, algorithms, iterators and maps with suitable examples. It lists all operations supported by this library.

Chapter 18 discusses some of the unique features of ANSI and TURBO C++. The new data type bool and wchar_t are discussed with examples. The new typecasting operators are explained with appropriate examples. The new concepts namespace, mutable and explicit keywords are explained. It also lists the keywords and the header file names of ANSI and Turbo C++. The use of pascal and cdecl are explained with suitable examples.

The nineteenth chapter is designed for learning basics of Java programming language. In this chapter evolution of Java, Java technology, data types, classes, methods and applets are briefly described. The reader will find this chapter useful.

ACKNOWLEDGEMENTS

I express my deep sense of gratitude to the Minister for Higher and Technical Education of Maharashtra, Honourable Dilip Walse-Patil who complimented me for writing books while he was here in Nanded for the distribution of gold medals to the outstanding students and teachers of this college on 26th August 2002.

My sincere thanks to Prof. N.B. Pasalkar, Chairman of S.G.G.S. College of Engineering and Technology, Nanded who is also the Director of Technical Education, Maharashtra State, the Board of Governors of this college, Dr.M.B. Kinhalkar (Former Home Minister of Maharashtra), Dr. J.G. Wadekar, Dr. V.A. Hambire and the Principal, Dr. T.R. Sontakke for inspiring me to write this book. I am thankful to them for their constructive suggestions on my previous book Programming with ANSI and Turbo C.

In addition, I would like to thank all those who have encouraged me to write this book, especially Prof. B.M. Naik, Former Principal of S.G.G.S. College of Engineering and Technology, Nanded who is a source of inspiration.

I am grateful to all my colleagues, friends and students who helped me in preparing the manuscript of this book. My sincere thanks to Vice Principal of S.G.G.S. College Professor S.G. Kahalekar and Professors Dr. P.D. Jadhav, Dr. P. Pramanik, Dr. P.S. Charpe, Dr. B.M. Dabde, Dr. U.V. Kulkarni, Dr. S.P. Kallurkar, Dr. V.M. Nandedkar, Dr. A.U. Digraskar, Dr. R.S. Holambe, Dr. B.M Patre, R.K. Chavan, J.V.L. Venkatesh, Dr. R.S. Bichkar, Dr. Y.V. Joshi , Madam S.S. Kandhare, P.S. Nalawade, S.S. Hatkar, R.C. Thool, Narayan Patil, A.V. Nandedkar, A.B.Gonde, S.V.Bonde, P.B. Londhe, S.S.Gajre, M.B Kokre, Trupti Deshmukh, Sanjay Sarda, Miss Priyanka Agrawal, R.R. Manthalkar, Prof. N.G. Megde, A.S. Sontakke, Deepak Bacchewar, Dr. L.M. Waghmare, Dr. R.H. Chille and A.I. Tamboli for reviewing and suggesting changes in the book. I am also thankful to my friends Prof. S.L. Kotgire and Balaji Bacchewar for checking the contents of text. Mr. S.G. Ipte, Mr. M.M. Jahagirdar, Mr. R.M. Medabalmewar, Mr. L.M. Buddhewar, Mr. K.M Buddhewar, Mr. D.V. Deshpande, Mr. Kokne S.R., Mr. Damkondawar M.G., Mr. Yeramwar, Mr. Tumma S.R., Mr. Mana S.R., Mr. V.U. Ranveer and Mr. U.M. Rachaotkar. This list will not complete without mentioning my students Anil Kadam, Arup Datta, Nitin Ganveer, Rahul Kabra, Tawri Sandesh, Kulkarni Mayur, Binu John, Jagdale Sujeet, Bakshi Onkar, Muttepawar Rahul, Kulkarni Prasanna, Ballewar, Miss S.Soni and Miss Gayatri Raghvan who went through the manuscript and suggested modifications.

My special thanks go to Mr. Santosh S. Partani and Balaji Jadhav for the earnest efforts made during preparation of this book. They pointed out the critical issues while writing the book. Their thorough reviewing of topics and modifications suggested by them in the programs was of great help in writing this book. Without their involvement, this book would not have been possible. I thank them once again for their aggressive efforts in typing the book.

I am thankful to my Editor Sanjay K. Singh for his specific inputs and bringing this book out in a record time and Kumar Sidharth for error free proofs. Also, I express my thanks to Madam Anuradha of Nalanda English School who went through the manuscript and suggested improvements.

Last, but not the least, my thanks to my wife Surekha for her patience and support while writing this book. My sons Amol, Amit and daughter Sangita were also a great help and extended support to me all the times.

Ashok N. Kamthane