1038

Click here to load reader

Object Oriented Programming in C++ by Robert Lafore (4th Edition)

Embed Size (px)

DESCRIPTION

Object Oriented Programming in C++ by Robert Lafore (4th Edition) Note: I share this book for educational purpose only. If you really like this book please buy it and help the authors, they deserve it. All The Best. :) If this book is helpful to you then don't forget to like, share and comment. Facebook: www.facebook.com/pran93

Citation preview

  • 1.Object-Oriented Programming in C++,Fourth EditionRobert Lafore800 East 96th St., Indianapolis, Indiana 46240 USA

2. Copyright 2002 by Sams PublishingAll rights reserved. No part of this book shall be reproduced, stored in aretrieval system, or transmitted by any means, electronic, mechanical, photo-copying,recording, or otherwise, without written permission from the pub-lisher.No patent liability is assumed with respect to the use of the informationcontained herein. Although every precaution has been taken in the preparationof this book, the publisher and author assume no responsibility for errors oromissions. Nor is any liability assumed for damages resulting from the use ofthe information contained herein.International Standard Book Number: 0-672-32308-7Library of Congress Catalog Card Number: 2001094813Printed in the United States of AmericaFirst Printing: December 200104 03 02 01 4 3 2 1TrademarksAll terms mentioned in this book that are known to be trademarks or servicemarks have been appropriately capitalized. Sams Publishing cannot attest tothe accuracy of this information. Use of a term in this book should not beregarded as affecting the validity of any trademark or service mark.Warning and DisclaimerEvery effort has been made to make this book as complete and as accurate aspossible, but no warranty or fitness is implied. The information provided is onan as is basis. The author and the publisher shall have neither liability norresponsibility to any person or entity with respect to any loss or damagesarising from the information contained in this book.EXECUTIVE EDITORMichael StephensACQUISITIONS EDITORMichael StephensMANAGING EDITORMatt PurcellPROJECT EDITORSAngela BoleyChristina SmithINDEXERRebecca SalernoPROOFREADERMatt WynaldaTECHNICAL EDITORMark CashmanTEAM COORDINATORPamalee NelsonMEDIA DEVELOPERDan ScherfINTERIOR DESIGNERGary AdairCOVER DESIGNERAlan ClementsPAGE LAYOUTAyanna Lacey 3. OverviewIntroduction 11 The Big Picture 92 C++ Programming Basics 293 Loops and Decisions 754 Structures 1315 Functions 1616 Objects and Classes 2157 Arrays and Strings 2638 Operator Overloading 3199 Inheritance 37110 Pointers 42911 Virtual Functions 50312 Streams and Files 56713 Multifile Programs 63314 Templates and Exceptions 68115 The Standard Template Library 72516 Object-Oriented Software Development 801A ASCII Chart 849B C++ Precedence Table and Keywords 859C Microsoft Visual C++ 863D Borland C++Builder 871E Console Graphics Lite 881F STL Algorithms and Member Functions 895G Answers to Questions and Exercises 913H Bibliography 977Index 981 4. ContentsIntroduction 11 The Big Picture 9Why Do We Need Object-Oriented Programming? ..............................10Procedural Languages ......................................................................10The Object-Oriented Approach ........................................................13Characteristics of Object-Oriented Languages......................................16Objects ..............................................................................................16Classes ..............................................................................................18Inheritance ........................................................................................18Reusability ........................................................................................21Creating New Data Types ................................................................21Polymorphism and Overloading ......................................................21C++ and C..............................................................................................22Laying the Groundwork ........................................................................23The Unified Modeling Language (UML)..............................................23Summary................................................................................................25Questions................................................................................................252 C++ Programming Basics 29Getting Started ......................................................................................30Basic Program Construction ..................................................................30Functions ..........................................................................................31Program Statements..........................................................................32Whitespace........................................................................................33Output Using cout ................................................................................33String Constants................................................................................34Directives ..............................................................................................35Preprocessor Directives ....................................................................35Header Files......................................................................................35The using Directive..........................................................................36Comments ..............................................................................................36Comment Syntax ..............................................................................36When to Use Comments ..................................................................37Alternative Comment Syntax ..........................................................37Integer Variables ....................................................................................38Defining Integer Variables................................................................38Declarations and Definitions ............................................................40Variable Names ................................................................................40Assignment Statements ....................................................................40 5. Integer Constants ..............................................................................41Output Variations ..............................................................................41The endl Manipulator ......................................................................41Other Integer Types ..........................................................................42Character Variables ................................................................................42Character Constants..........................................................................43Initialization......................................................................................44Escape Sequences ............................................................................44Input with cin ........................................................................................45Variables Defined at Point of Use ....................................................47Cascading