ebook img

Programming in C++, 2nd Edition PDF

904 Pages·2013·4.837 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Programming in C++, 2nd Edition

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 Brief Contents 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 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 Contents 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 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

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.