Starting out with c++ early objects

1.3K 520 1
Starting out with c++   early objects

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Đây là quyển sách tiếng anh về lĩnh vực công nghệ thông tin cho sinh viên và những ai có đam mê. Quyển sách này trình về lý thuyết ,phương pháp lập trình cho ngôn ngữ C và C++.

Unprecedented Praise for Starting Out with C++ I want to tell you that I believe your C++ text is the most thorough one available. I have used 5 different ones since 1992 and every one assumes the students know things that they do not. You cover every detail. Thank you. —David McLeod, Belmont Technical College, OH The students have found your book to be easy to read and understand—a great accomplishment. —Al Cawns, Webster University, MO I listen to what students say about the books I select. Their response to Gaddis is unusually positive. They really like the book. —Jeffrey A. Kent, Los Angeles Valley College, CA Greetings, I’m using your book in an introductory course in C++ at University of Texas at Dallas. Your book is GREAT!! It abstracts the complexity of C++ down to the core con- cepts that we can build on. Thanks! —Jim Burke, student …just wanted to tell you that your book has made a lot of difference in my life. Your book is absolutely “Awesome.” You have a lot of examples in the book which help a lot. Thanks again! —Saud Faisal, student I have adopted and am currently teaching from the Gaddis second edition textbook. This is by far the best C++ book that I have taught with. —Deedee Herrera, Dodge City CC, KS I like it better than the one we are using for our second semester C++ course. —Dr. Ron Bass, Austin Community College, TX I took a good look at your 2nd edition as I revised my class to use it and I think you did a super job. Moving recursion and splitting the chapter on arrays made a great book even better. Congratulations! —Carol Schwab, Webster University, MO I have adopted this book for courses at both Inver Hills Community College and Century College in Minnesota this semester. I have not been disappointed. It works for me. —Ray Larson, Century College, MN This book is very, very exhaustive in its coverage. I didn’t even go through a part of it. But aside from its bulk, it was a very good introduction to programming. Gaddis does an excellent job of showing how to program step-by-step, and makes it easy to teach yourself. The book also contains a quick reference section where you can look up frequently used commands without having to find them in the text. This book is highly recommended for beginning (and even continuing) programmers. —Reviewer from The University of Texas at Dallas Learned quite a bit from this textbook needed for my C++ class in college. I was pleasantly surprised at how well writ- ten this book was, considering the topic it is covering. Great Book! I’m keeping mine seeing as it will come in handy with my future programming endeavors. Too bad other text- books aren’t as well written. —Craig Croteau, Dunedin, FL I used this book for the first semester of college C++. It is an excellent textbook. Some C++ textbooks have large amounts of text with few examples, making them very hard to read and understand. This book is filled with examples in short sections about specific C++ elements. I have kept it as a reference as infor- mation is easy to find and the examples make it easy to understand and implement. I have two other books on C++, but if I were teaching a C++ class, I would use this book. —Karen Ryberg, Bismarck, ND GaddA2005.book Page i Friday, September 16, 2005 11:52 AM The book itself is fantastic. Everything is laid out in an easy to read fashion. Truly a C++ beginners book.…Thanks for writing a book that was so educational Tony! —Student from Dover, NH This book is just amazing.…It goes in-depth on almost everything in C++. It’ll teach you pretty much everything you need except the most advanced topics. Its a tough book since it covers so much, but it’s definitely worth the time and money if you’re willing to invest in it. —A reader Gaddis is an extraordinary writer. Gaddis’ text is working much better than I expected. The ancillary materials espe- cially the test bank and Power Point presentations add greatly to our ability to do some solid, diverse, and effective teaching. —George Harrison, Norfolk State University, VA Could you please tell me when “Starting Out with Java” by Tony Gaddis will be available for purchase? I am a sopho- more at Augusta State University, and my school’s first pro- gramming class uses “Starting out with C++.” I am transferring to UGA and their first class teaches JAVA. So I have to teach it to myself. I love your C++ book—it makes everything so easy to understand, and I know that I can’t go wrong with the JAVA text. —Christopher Savage, student I’ve never seen a beginners C++ book that is as well struc- tured and reader-friendly as this one. If you are in the mar- ket for an intro to C++ book, look no further. —A reader I have found the Gaddis book to be a wonderful textbook for our students. It is highly readable, and I am pleased that most students are actually reading the text . —Brenda Boyce, C++ Instructor Beginners using the Linux operating system and compiling with gcc will not have a problem with the examples in this book. I like the fact that the author even explains how to compile programs under Linux, which helped me out a lot, being a beginner myself. —Justin Sinclair, San Francisco, CA As an instructor in the community-college system, I have stu- dents with wide-ranging abilities—from remedial to advanced. Though I haven’t had time to study the whole book (yet), it has many good features, all of which I can’t list. The most important to me is how the book proceeds. Though this book is exhaustive (i.e., covers each of its topics very thoroughly), it goes step-by-step to teach the basics of the programming process in an organized fashion. Such a pro- gressive approach is MUCH better than a “here’s EVERY- THING on one topic” approach (see any book by the Deitels); beginning students don’t NEED to know the details. Any pro- gramming instructor who thinks about how he/she learned will recognize that he/she learned broad, general basics and only picked up the details through practice. …Mr. Gaddis’ book is the BEST I’ve seen in years. —Reviewer, Wake Technical Community College Gaddis’ book is a good, solid book and teachers should be successful using it. Students in our Bachelors program find the book clear, easy to follow and therefore, they like it very much. —An instructor from Touro College, NY This is an excellent book for those looking to learn the C++ language. It starts off with the absolute basics and goes through medium-level OOP programming. —Reviewer from Dallas, TX My students say Gaddis is the best thing they’ve seen since sliced bread. —Tom Gilman, College of the Desert GaddA2005.book Page ii Friday, September 16, 2005 11:52 AM Early Objects 5th Edition Tony Gaddis Judy Walters Godfrey Muganda GaddA2005.book Page iii Friday, September 16, 2005 11:52 AM Publisher Greg Tobin Senior Acquisitions Editor Michael Hirsch Editorial Assistant Lindsey Triebel Managing Editor Patty Mahtani Cover Designer Joyce Cosentino Wells Media Producer Bethany Tidd Marketing Manager Michelle Brown Marketing Assistant Dana Lopreato Senior Manufacturing Buyer Caroline Fell Text Design, Composition Stephen Adams Proofreader Kristin Furino Production Coordination Mario M. Rodriguez Access the latest information about Addison-Wesley titles from our World Wide Web site: http://www.aw-bc.com/computing Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trade- marks. Where those designations appear in this book, and Addison-Wesley was aware of a trademark claim, the designations have been printed in initial caps or all caps. The programs and applications presented in this book have been included for their instructional value. They have been tested with care but are not guaranteed for any particular purpose. The publisher does not offer any warran- ties or representations, nor does it accept any liabilities with respect to the programs or applications. Library of Congress Cataloging-in-Publication Data Gaddis, Tony. Starting out with C++ : early objects / Tony Gaddis, Judy Walters, Godfrey Muganda 5th ed. p. cm. ISBN 0-321-38348-6 1. C++ (Computer program language) I. Walters, Judy. II. Muganda, Godfrey. III. Title. QA76.73.C153G33 2005b 005.13'3 dc22 2005022443 Copyright © 2006 Pearson Education, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior writ- ten permission of the publisher. Printed in the United States of America. For information on obtaining permis- sion for use of material in this work, please submit a written request to Pearson Education, Inc., Rights and Contracts Department, 75 Arlington Street, Suite 300, Boston, MA 02116, fax your request to 617-848-7047, or e-mail at http://www.pearsoned.com/legal/permissions.htm. ISBN 0-321-38348-6 1 2 3 4 5 6 7 8 9 10—CRW—09 08 07 06 05 GaddA2005.book Page iv Friday, September 16, 2005 11:52 AM v Contents at a Glance CHAPTER 1 Introduction to Computers and Programming 1 CHAPTER 2 Introduction to C++ 29 CHAPTER 3 Expressions and Interactivity 79 CHAPTER 4 Making Decisions 167 CHAPTER 5 Looping 255 CHAPTER 6 Functions 313 CHAPTER 7 Introduction to Classes and Objects 391 CHAPTER 8 Arrays 477 CHAPTER 9 Searching and Sorting Arrays 567 CHAPTER 10 Pointers 607 CHAPTER 11 More About Classes and Object-Oriented Programming 657 CHAPTER 12 More About Characters, Strings, and the string Class 761 CHAPTER 13 Advanced File and I/O Operations 821 CHAPTER 14 Recursion 889 CHAPTER 15 Polymorphism, Virtual Functions, and Multiple Inheritance 917 CHAPTER 16 Exceptions, Templates, and the Standard Template Library (STL) 957 CHAPTER 17 Linked Lists 1009 CHAPTER 18 Stacks and Queues 1055 CHAPTER 19 Binary Trees 1095 Appendix A The ASCII Character Set 1121 Appendix B Operator Precedence and Associativity 1125 Appendices on the accompanying student CD Appendix C An Object-Oriented System Development Primer Appendix D Using UML in Class Design (NEW) Appendix E Namespaces Appendix F Passing Command Line Arguments Appendix G Header File and Library Function Reference Appendix H Binary Numbers and Bitwise Operations Appendix I C++ Casts and Run-Time Type Identification Appendix J Multi-Source File Programs Appendix K Introduction to Microsoft Visual C++ 6.0 Appendix L Introduction to Borland C++ Builder 5.0 Appendix M Introduction to Microsoft Visual C++ .NET Appendix N .NET and Managed C++ (NEW) Appendix O Introduction to Flowcharting Appendix P Answers to Checkpoints Appendix Q Answers to Odd-Numbered Review Questions GaddA2005.book Page v Friday, September 16, 2005 11:52 AM GaddA2005.book Page vi Friday, September 16, 2005 11:52 AM vii Contents Preface xv CHAPTER 1 Introduction to Computers and Programming 1 1.1 Why Program? 1 1.2 Computer Systems: Hardware and Software 2 1.3 Programs and Programming Languages 6 1.4 What Is a Program Made of? 12 1.5 Input, Processing, and Output 16 1.6 The Programming Process 18 1.7 Procedural and Object-Oriented Programming 22 1.8 Case Studies 24 1.9 Review Questions and Exercises 25 CHAPTER 2 Introduction to C++ 29 2.1 The Parts of a C++ Program 29 2.2 The cout Object 33 2.3 The #include Directive 37 2.4 Standard and Prestandard C++ 39 2.5 Variables, Constants, and the Assignment Statement 40 2.6 Identifiers 45 2.7 Integer Data Types 47 2.8 The char Data Type 52 2.9 The C++ string Class 56 2.10 Floating-Point Data Types 57 2.11 The bool Data Type 61 2.12 Determining the Size of a Data Type 62 2.13 More on Variable Assignments and Initialization 63 2.14 Scope 64 2.15 Arithmetic Operators 65 2.16 Comments 68 2.17 Focus on Software Engineering: Programming Style 70 2.18 Case Studies 72 2.19 Review Questions and Exercises 72 CHAPTER 3 Expressions and Interactivity 79 3.1 The cin Object 79 3.2 Mathematical Expressions 85 3.3 Implicit Type Conversion 93 GaddA2005.book Page vii Friday, September 16, 2005 11:52 AM Contents viii 3.4 Explicit Type Conversion 95 3.5 Overflow and Underflow 98 3.6 Named Constants 101 3.7 Multiple and Combined Assignment 107 3.8 Formatting Output 111 3.9 Working with Characters and String Objects 121 3.10 Using C-Strings 128 3.11 More Mathematical Library Functions 133 3.12 Introduction to Files 138 3.13 Focus on Object-Oriented Programming: Member Functions 146 3.14 Focus on Debugging: Hand Tracing a Program 147 3.15 Green Fields Landscaping Case Study—Part 1 149 3.16 Additional Case Studies 152 3.17 Review Questions and Exercises 152 CHAPTER 4 Making Decisions 167 4.1 Relational Operators 167 4.2 The if Statement 173 4.3 The if/else Statement 183 4.4 The if/else if Statement 186 4.5 Menus 192 4.6 Nested if Statements 194 4.7 Logical Operators 198 4.8 Checking Numeric Ranges with Logical Operators 206 4.9 Validating User Input 207 4.10 More About Variable Definitions and Scope 209 4.11 Comparing Characters and Strings 215 4.12 The Conditional Operator 219 4.13 The switch Statement 223 4.14 Enumerated Data Types 232 4.15 Testing for File Open Errors 235 4.16 Focus on Testing and Debugging: Validating Output Results 236 4.17 Green Fields Landscaping Case Study—Part 2 239 4.18 Additional Case Studies 243 4.19 Review Questions and Exercises 243 CHAPTER 5 Looping 255 5.1 The Increment and Decrement Operators 255 5.2 Introduction to Loops: The while Loop 260 5.3 Counters 264 5.4 Letting the User Control the Loop 266 5.5 Keeping a Running Total 268 5.6 Sentinels 269 5.7 Using a Loop to Read Data From a File 271 GaddA2005.book Page viii Friday, September 16, 2005 11:52 AM Contents ix 5.8 The do-while and for Loops 274 5.9 Deciding Which Loop to Use 284 5.10 Nested Loops 285 5.11 Breaking Out of a Loop 288 5.12 The continue Statement 290 5.13 Focus on Software Engineering: Using Loops for Data Validation 292 5.14 Focus on Testing and Debugging: Creating Good Test Data 295 5.15 Central Mountain Credit Union Case Study 298 5.16 Additional Case Studies 303 5.17 Review Questions and Exercises 303 CHAPTER 6 Functions 313 6.1 Modular Programming 313 6.2 Defining and Calling Functions 314 6.3 Function Prototypes 322 6.4 Sending Data into a Function 324 6.5 Passing Data by Value 328 6.6 The return Statement 332 6.7 Returning a Value from a Function 334 6.8 Returning a Boolean Value 338 6.9 Using Functions in a Menu-Driven Program 340 6.10 Local and Global Variables 343 6.11 Static Local Variables 349 6.12 Default Arguments 353 6.13 Using Reference Variables as Parameters 357 6.14 Overloading Functions 365 6.15 The exit() Function 369 6.16 Stubs and Drivers 373 6.17 Little Lotto Case Study 376 6.18 Additional Case Studies 381 6.19 Review Questions and Exercises 381 CHAPTER 7 Introduction to Classes and Objects 391 7.1 Combining Data into Structures 391 7.2 Accessing Structure Members 394 7.3 Initializing a Structure 398 7.4 Nested Structures 402 7.5 Structures as Function Arguments 406 7.6 Returning a Structure from a Function 410 7.7 Unions 413 7.8 Abstract Data Types 417 7.9 Object-Oriented Programming 419 7.10 Introduction to Classes 423 7.11 Introduction to Objects 425 GaddA2005.book Page ix Friday, September 16, 2005 11:52 AM Contents x 7.12 Defining Member Functions 427 7.13 Focus on Software Engineering: Design Considerations 434 7.14 Using a Constructor with a Class 439 7.15 Overloading Constructors 440 7.16 Destructors 443 7.17 Input Validation Objects 447 7.18 Using Private Member Functions 451 7.19 Home Software Company OOP Case Study 454 7.20 Focus on Software Engineering: Object-Oriented Analysis 461 7.21 Additional Case Studies 464 7.22 Review Questions and Exercises 464 CHAPTER 8 Arrays 477 8.1 Arrays Hold Multiple Values 477 8.2 Accessing Array Elements 479 8.3 Inputting and Displaying Array Contents 481 8.4 Array Initialization 487 8.5 Processing Array Contents 493 8.6 Using Parallel Arrays 502 8.7 The typedef Statement 506 8.8 Arrays as Function Arguments 507 8.9 Two-Dimensional Arrays 516 8.10 Arrays with Three or More Dimensions 524 8.11 Vectors 528 8.12 National Commerce Bank Case Study 540 8.13 Arrays of Structures 543 8.14 Arrays of Class Objects 547 8.15 Additional Case Studies 555 8.16 Review Questions and Exercises 556 CHAPTER 9 Searching and Sorting Arrays 567 9.1 Focus on Software Engineering: Introduction to Search Algorithms 567 9.2 Demetris Leadership Center Case Study—Part 1 574 9.3 Focus on Software Engineering: Introduction to Sorting Algorithms 581 9.4 Demetris Leadership Center Case Study—Part 2 589 9.5 Sorting and Searching Vectors 596 9.6 Additional Case Studies 601 9.7 Review Questions and Exercises 602 CHAPTER 10 Pointers 607 10.1 Getting the Address of a Variable 607 10.2 Pointer Variables 609 10.3 The Relationship Between Arrays and Pointers 613 10.4 Pointer Arithmetic 617 10.5 Initializing Pointers 619 GaddA2005.book Page x Friday, September 16, 2005 11:52 AM [...]... course: Starting Out with C++: Control Structures through Objects (formerly called the “Standard Version”); Starting Out With C++: Early Objects (formerly called the “Alternate Version”); Starting Out with C++: Brief Version The following chart will help you determine which book is right for your course From Control Structures through Objects Brief Version Early Objects LATE INTRODUCTION OF OBJECTS. .. Accompany Starting Out with C++: Early Objects, 5th Edition, co-authored by Judy Walters, Dean Defino, and Michael Bardzell Textbook Web site A Web site for the Starting Out With C++ series of books is located at the following URL: http://www.aw.com/gaddisbooks GaddA2005.book Page xxv Friday, September 16, 2005 11:52 AM Preface Which Gaddis C++ book is right for you? The Starting Out with C++ Series... xv Friday, September 16, 2005 11:52 AM Preface Welcome to Starting Out with C++: Early Objects, 5th edition In previous editions this book was called Alternate Version of Starting Out With C++ This book is intended for use in a twosemester C++ programming sequence, or an accelerated one-semester course Students new to programming, as well those with prior course work in other languages, will find this... file, with numbering starting from page 1 This will make it easier for students to locate appendix information Two new appendices have been added: – Using UML in Class Design – NET and Managed C++ A UML icon has been added throughout the text where appropriate to refer students to the contents of the new appendix New and improved Programming Challenges have been added throughout the book Beginning with. .. charts and pseudocode are also presented Chapter 2: Introduction to C++ This chapter gets the student started in C++ by introducing the basic parts of a C++ program, data types, variable definitions, assignment statements, constants, comments, program output, and simple arithmetic operations The C++ string class is presented and string objects are used from this point on in the book as the primary method... sends to the outside world It might be a sales report, a list of names, or a graphic image The information is sent to an output device, which formats and presents it Common output devices are monitors, printers, and speakers Output sent to a monitor is sometimes called “soft copy,” while output sent to a printer is called “hard copy.” Disk drives and CD burners can also be considered output devices... INTRODUCTION OF OBJECTS Classes are introduced in Chapter 7, after control structures and functions, but before arrays and pointers Their use is then integrated into the remainder of the text Advanced OOP topics, such as inheritance and polymorphism, are covered in Chapters 11 and 15 USE OF C-STRINGS Null-terminated C-strings are used throughout, with the C++ string class covered briefly USE OF STRING OBJECTS. .. want to thank our long-time friend and mentor Richard Jones for his guidance and expertise over the many editions of this book You are all great people to work with! About the Authors Tony Gaddis is the principal author of the Starting Out with series of textbooks Tony teaches computer science courses at Haywood Community College in North Carolina He is a highly acclaimed instructor who was previously... implementation files Appendix K: Introduction to Microsoft Visual C++ 6.0 A tutorial on how to start a project using Microsoft Visual C++, compile and run a program, save source files, and more The Visual C++ 6.0 getline() bug is documented and a solution provided Appendix L: Introduction to Borland C++ Builder 5.0 A tutorial on how to start a Borland C++ Builder project, compile and run a program, save source... rate; pay = hours * rate; cout . AM xv Preface Welcome to Starting Out with C++: Early Objects, 5th edition. In previous editions this book was called Alternate Version of Starting Out With C++. This. liabilities with respect to the programs or applications. Library of Congress Cataloging-in-Publication Data Gaddis, Tony. Starting out with C++ : early objects

Ngày đăng: 19/03/2014, 14:13

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan