ebook img

C++ How to Program PDF

1065 Pages·2014·14.239 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 C++ How to Program

Continued from Back Cover ONLINE ACCESS ❝It’s great that the text introduces object-oriented programming early. The car analogy was well-thought out. Meticulous treatment of control structures. The virtual function figure and corresponding explanation in the Polymorphism chapter is thorough and truly commendable.~ —Gregory Dai, eBay Thank you for purchasing a new copy of C++ How to Program, Ninth Edition. Your textbook includes twelve months of prepaid access to the book’s Companion Website. This prepaid ❝The example-driven presentation is enriched by the optional OO design case study that contextualizes the material in a software subscription provides you with full access to the following student support areas: engineering project.~ —Gavin Osborne, Saskatchewan Institute of Applied Science and Technology ❝The Object-Oriented Programming: Inheritance chapter is well done. Excellent introduction to polymorphism.~ • VideoNotes are step-by-step video tutorials specifically designed to enhance the programming —David Topham, Ohlone College concepts presented in this textbook ❝The overview of computing is about the right depth and breadth for an intro course.~ • Premium Web Chapters and Appendices —Robert C. Seacord, Secure Coding Manager at SEI/CERT, author of Secure Coding in C and C++ • Source Code ❝Thorough and detailed coverage of exceptions from an object-oriented point of view.~ —Dean Mathias, Utah State University ❝Introducing the UML early is a great idea.~ —Raymond Stephenson, Microsoft ❝Good use of diagrams, especially of the activation call stack and recursive functions.~ —Amar Raheja, California State Polytechnic University, Pomona ❝Terrific discussion of pointers—the best I have seen.~ —Anne B. Horton, Lockheed Martin ❝I especially value the code examples and diagrams. Great coverage of OOP. Nice detail in [Intro to Classes]—students can learn so much Use a coin to scratch off the coating and reveal your student access code. from it; I love that every line of code is explained and that UML class diagrams are given. I really like the Structured Programming Summary. Do not use a knife or other sharp object as it may damage the code. Good visuals provided for what’s going on in memory [for pass-by-value and pass-by-reference]. The [Inheritance] examples nicely reinforce the concepts. I love the description of [a possible] polymorphic video game.~ —Linda M. Krause, Elmhurst College ❝A good whirlwind tour [in Chapter 1] of what computers are, the history of the computer industry and some high-level introductory material To access the C++ How to Program, Ninth Edition, Companion Website for the first time, you on C++. [Chapter 2] is a gentle introduction to C++ that gradually gets soon-to-be programmers learning just enough to be able to do interest- will need to register online using a computer with an Internet connection and a web browser. The ing things right away. The [Chapter 3, Introduction to Classes, Objects and Strings] examples are solid.~—Dean Michael Berris, Google process takes just a couple of minutes and only needs to be completed once. ❝A good control statements chapter; the discussions of increment ops, {} initialization and floating point data formatting are excellent; novices 1. Go to http://www.pearsonhighered.com/deitel/ will benefit from these sections. The discussion about stack memory, storage classes and the function call mechanism is great. I enjoyed the recursion section. The pointers and arrays chapter manages to explain something that’s quite difficult to teach: the elusive nature of pointers. 2. Click on Companion Website. [Classes: A Deeper Look; Throwing Exceptions] is good and well-focused. The operator overloading chapter explains the topic clearly and builds 3. Click on the Register button. a convincing, realistic class [Array] that demonstrates the capabilities of OOD and C++. [Inheritance] is short, to the point and very clear. [Standard Library Containers] is excellent, up to date, accurate, concise and readable; I really enjoyed it.~ 4. On the registration page, enter your student access code* found beneath the scratch-off panel. —Danny Kalev, C++ expert, Certified System Analyst and former member of C++ Standards Committee Do not type the dashes. You can use lower- or uppercase. ❝Clearly explains control structures. The [Functions] code examples exemplify the chapter content; the discussion was very good and the exer- 5. Follow the on-screen instructions. If you need help at any time during the online registration cises had good variation in difficulty. [Arrays and Vectors] was really good; I like the idea of std::array [instead of built-in arrays] by default. process, simply click the Need Help? icon. [Exception Handling] was short, sweet, to the point and accurate.~ —James McNellis, Microsoft 6. Once your personal Login Name and Password are confirmed, you can begin using the C++ ❝An accurate and complete C++ book that everybody can understand. A ‘must-have.’ Novices and advanced programmers will find this book How to Program Companion Website! an excellent tool for learning C++. Really fun and interesting exercises (Knight’s Tour, Eight Queens, etc.). Easy-to-understand string examples and interesting exercises. I especially liked the Quicksort explanation. The Simpletron exercises are brilliant.~ To log in after you have registered: —José Antonio González Seco, Parliament of Andalusia You only need to register for this Companion Website once. After that, you can log in any time at ❝I really like the Making a Difference exercises. The [dice and card games] get students excited.~ —Virginia Bailey, Jackson State University http://www.pearsonhighered.com/deitel/ by providing your Login Name and Password when ❝Provides a complete basis of fundamental instruction in all core aspects of C++. A solid overview of Stream I/O.~ prompted. —Peter DePasquale, The College of New Jersey ❝Great coverage of polymorphism and how the compiler implements polymorphism ‘under the hood.’~ —Ed James-Beckham, Borland *Important: The access code can only be used once. This subscription is valid for twelve months upon activation and is not transferable. If this access code has already been revealed, it may ❝A nice introduction to searching and sorting, and Big-O.~ —Robert Myers, Florida State University no longer be valid. If this is the case, you can purchase a subscription by going to http:// ❝Will get you up and running quickly with the [smart pointers] and regular expression libraries.~ —Ed Brey, Kohler Co. www.pearsonhighered.com/deitel/ and following the on-screen instructions. ❝The most thorough C++ treatment I’ve seen. Replete with real-world case studies covering the full software development lifecycle. Code examples are extraordinary!~—Terrell Hull, Logicalis Integration Solutions D e i t e l ® S e r i e s P a g e HowToProgramSeries SimplyVisualBasic2010:AnApp-Driven AndroidHowtoProgram Approach,4/E CHowtoProgram,7/E VisualBasic®2012HowtoProgram C++HowtoProgram,9/E VisualBasic®2010HowtoProgram C++HowtoProgram,LateObjectsVersion,7/E VisualC#®2012HowtoProgram,5/E Java™HowtoProgram,9/E VisualC#®2010HowtoProgram,4/E Java™HowtoProgram,LateObjectsVersion,8/E Internet&WorldWideWebHowtoProgram,5/E Deitel®DeveloperSeries VisualBasic®2012HowtoProgram C++forProgrammers,2/E VisualC#®2012HowtoProgram,3/E AndroidforProgrammers:AnApp-Driven VisualC++®2008HowtoProgram,2/E Approach SmallJava™HowtoProgram,6/E C#2010forProgrammers,3/E SmallC++HowtoProgram,5/E DiveInto®iOS6:AnApp-DrivenApproach iOS6forProgrammers:AnApp-DrivenApproach SimplySeries Java™forProgrammers,2/E SimplyC++:AnApp-DrivenTutorialApproach JavaScriptforProgrammers SimplyJava™Programming:AnApp-Driven LiveLessonsVideoLearningProducts TutorialApproach SimplyVisualBasic®2010,4/E:AnApp-Driven www.deitel.com/books/LiveLessons/ TutorialApproach Android®AppDevelopmentFundamentals C++Fundamentals CourseSmartWebBooks C#Fundamentals www.deitel.com/books/CourseSmart/ iOS6AppDevelopmentFundamentals C++HowtoProgram,7/E,8/E&8/E Java™Fundamentals SimplyC++:AnApp-DrivenTutorialApproach JavaScriptFundamentals Java™HowtoProgram,7/E,8/E&9/E VisualBasicFundamentals ToreceiveupdatesonDeitelpublications,ResourceCenters,trainingcourses,partneroffersandmore, pleaseregisterforthefreeDeitel®BuzzOnlinee-mailnewsletterat: www.deitel.com/newsletter/subscribe.html andjointheDeitelcommunitiesonTwitter® @deitel Facebook® facebook.com/DeitelFan andGoogle+ gplus.to/deitel Tocommunicatewiththeauthors,sende-mailto: [email protected] ForinformationongovernmentandcorporateDive-Into®Serieson-siteseminarsofferedbyDeitel& Associates,Inc.worldwide,visit: www.deitel.com/training/ orwriteto [email protected] ForcontinuingupdatesonPrenticeHall/Deitelpublicationsvisit: www.deitel.com www.pearsonhighered.com/deitel/ VisittheDeitelResourceCentersthatwillhelpyoumasterprogramminglanguages,softwaredevelop- ment,AndroidandiPhone/iPadappdevelopment,andInternet-andweb-relatedtopics: www.deitel.com/ResourceCenters.html cpphtp9_titlepages.fm Pageiii Friday,January4,2013 6:37AM Paul Deitel Deitel & Associates, Inc. Harvey Deitel Deitel & Associates, Inc. VicePresidentandEditorialDirector:MarciaJ.Horton ExecutiveEditor:TracyJohnson AssociateEditor:CaroleSnyder DirectorofMarketing:ChristyLesko MarketingManager:YezanAlayan MarketingAssistant:JonBryant DirectorofProduction:ErinGregg ManagingEditor:ScottDisanno AssociateManagingEditor:RobertEngelhardt OperationsSpecialist:LisaMcDowell ArtDirector:AnthonyGemmellaro CoverDesign:AbbeyS.Deitel,HarveyM.Deitel,AnthonyGemmellaro CoverPhotoCredit:©Shutterstock/SeanGladwell MediaProjectManager:RenataButera Creditsandacknowledgmentsborrowedfromothersourcesandreproduced,withpermission,inthistextbookappear onpagevi. Theauthorsandpublisherofthisbookhaveusedtheirbesteffortsinpreparingthisbook.Theseeffortsincludethe development,research,andtestingofthetheoriesandprogramstodeterminetheireffectiveness.Theauthorsandpub- lishermakenowarrantyofanykind,expressedorimplied,withregardtotheseprogramsortothedocumentation containedinthisbook.Theauthorsandpublishershallnotbeliableinanyeventforincidentalorconsequentialdam- agesinconnectionwith,orarisingoutof,thefurnishing,performance,oruseoftheseprograms. Copyright©2014,2012,2010PearsonEducation,Inc.,publishingas PrenticeHall. Allrightsreserved.Manufac- turedintheUnitedStatesofAmerica.ThispublicationisprotectedbyCopyright,andpermissionshouldbeobtained fromthepublisherpriortoanyprohibitedreproduction,storageinaretrievalsystem,ortransmissioninanyformor byanymeans,electronic,mechanical,photocopying,recording,orlikewise.Toobtainpermission(s)tousematerial fromthiswork,pleasesubmitawrittenrequesttoPearsonEducation,Inc.,OneLakeStreet,UpperSaddleRiver,New Jersey07458,oryoumayfaxyourrequestto201-236-3290. Manyofthedesignationsbymanufacturersandsellerstodistinguishtheirproductsareclaimedastrademarks.Where thosedesignationsappearinthisbook,andthepublisherwasawareofatrademarkclaim,thedesignationshavebeen printedininitialcapsorallcaps. LibraryofCongressCataloging-in-PublicationDataonfile. 10 9 8 7 6 5 4 3 2 1 ISBN-10: 0-13-337871-3 ISBN-13: 978-0-13-337871-9 In memory of Dennis Ritchie, creator of the C programming language— one of the key languages that inspired C++. PaulandHarveyDeitel Trademarks DEITEL,thedouble-thumbs-upbugandDIVEINTOareregisteredtrademarksofDeitelandAssociates, Inc. CarnegieMellonSoftwareEngineeringInstitute™isatrademarkofCarnegieMellonUniversity. CERT®isregisteredintheU.S.PatentandTrademarkOfficebyCarnegieMellonUniversity. Microsoft®andWindows®areregisteredtrademarksoftheMicrosoftCorporationintheU.S.A.and othercountries.ScreenshotsandiconsreprintedwithpermissionfromtheMicrosoftCorporation.This bookisnotsponsoredorendorsedbyoraffiliatedwiththeMicrosoftCorporation. UNIXisaregisteredtrademarkofTheOpenGroup. Throughoutthisbook,trademarksareused.Ratherthanputatrademarksymbolineveryoccurrenceof atrademarkedname,westatethatweareusingthenamesinaneditorialfashiononlyandtothebenefit ofthetrademarkowner,withnointentionofinfringementofthetrademark. Contents Chapters24–26 andAppendicesF–KarePDFdocumentspostedonlineatthebook’s CompanionWebsite,whichisaccessiblefromwww.pearsonhighered.com/deitel. Preface xxi 1 Introduction to Computers and C++ 1 1.1 Introduction 2 1.2 ComputersandtheInternetinIndustryandResearch 2 1.3 HardwareandSoftware 5 1.3.1 Moore’sLaw 6 1.3.2 ComputerOrganization 6 1.4 DataHierarchy 7 1.5 MachineLanguages,AssemblyLanguagesandHigh-LevelLanguages 9 1.6 C++ 10 1.7 ProgrammingLanguages 11 1.8 IntroductiontoObjectTechnology 14 1.9 TypicalC++DevelopmentEnvironment 17 1.10 Test-DrivingaC++Application 19 1.11 OperatingSystems 25 1.11.1 Windows—AProprietaryOperatingSystem 25 1.11.2 Linux—AnOpen-SourceOperatingSystem 26 1.11.3 Apple’sOSX;Apple’siOSforiPhone®,iPad®and iPodTouch®Devices 26 1.11.4 Google’sAndroid 27 1.12 TheInternetandWorldWideWeb 27 1.13 SomeKeySoftwareDevelopmentTerminology 29 1.14 C++11andtheOpenSourceBoostLibraries 31 1.15 KeepingUptoDatewithInformationTechnologies 32 1.16 WebResources 33 2 Introduction to C++ Programming; Input/Output and Operators 38 2.1 Introduction 39 viii Contents 2.2 FirstPrograminC++:PrintingaLineofText 39 2.3 ModifyingOurFirstC++Program 43 2.4 AnotherC++Program:AddingIntegers 44 2.5 MemoryConcepts 48 2.6 Arithmetic 49 2.7 DecisionMaking:EqualityandRelationalOperators 53 2.8 Wrap-Up 57 3 Introduction to Classes, Objects and Strings 66 3.1 Introduction 67 3.2 DefiningaClasswithaMemberFunction 67 3.3 DefiningaMemberFunctionwithaParameter 70 3.4 DataMembers,setMemberFunctionsandgetMemberFunctions 74 3.5 InitializingObjectswithConstructors 79 3.6 PlacingaClassinaSeparateFileforReusability 83 3.7 SeparatingInterfacefromImplementation 87 3.8 ValidatingDatawithsetFunctions 92 3.9 Wrap-Up 97 4 Control Statements: Part 1; Assignment, ++ and -- Operators 104 4.1 Introduction 105 4.2 Algorithms 105 4.3 Pseudocode 106 4.4 ControlStructures 107 4.5 ifSelectionStatement 110 4.6 if…elseDouble-SelectionStatement 112 4.7 whileRepetitionStatement 116 4.8 FormulatingAlgorithms:Counter-ControlledRepetition 118 4.9 FormulatingAlgorithms:Sentinel-ControlledRepetition 124 4.10 FormulatingAlgorithms:NestedControlStatements 134 4.11 AssignmentOperators 139 4.12 IncrementandDecrementOperators 140 4.13 Wrap-Up 143 5 Control Statements: Part 2; Logical Operators 157 5.1 Introduction 158 5.2 EssentialsofCounter-ControlledRepetition 158 5.3 forRepetitionStatement 159

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.