Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 3.186 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
3.186
Dung lượng
16,73 MB
Nội dung
C++ How to Program, Fifth Edition By H M Deitel - Deitel & Associates, Inc., P J Deitel - Deitel & Associates, Inc Publisher : Prentice Hall Pub Date : January 05, 2005 Print ISBN-10 : 0-13-185757-6 eText ISBN-10 : 0-13-186103-4 Print ISBN-13 : 978-0-13-185757-5 Table of eText ISBN-13 : 978-0-13-186103-9 • Pages : 1536 Contents • Index Best-selling C++ text significantly revised to include new early objects coverage and new streamlined case studies C++ How to Program, Fifth Edition By H M Deitel - Deitel & Associates, Inc., P J Deitel - Deitel & Associates, Inc Publisher : Prentice Hall Pub Date : January 05, 2005 Print ISBN-10 : 0-13-185757-6 eText ISBN-10 : 0-13-186103-4 Table of • Contents Print ISBN-13 : 978-0-13-185757-5 eText ISBN-13 : 978-0-13-186103-9 • Index Pages : 1536 Copyright Deitel® Books, Cyber Classrooms, Complete Training Courses and WebBased Training Courses published by Prentice Hall Preface Features of C++ How to Program, 5/e Teaching Approach Tour of the Book Object-Oriented Design of an ATM with the UML: A Tour of the Optional Software Engineering Case Study Software Bundled with C++ How to Program, 5/e Teaching Resources for C++ How to Program, 5/e C++ Multimedia Cyber Classroom, 5/e, Online C++ in the Lab CourseCompassSM, WebCT™ and Blackboard™ PearsonChoices The Deitel® Buzz Online Free E-mail Newsletter Acknowledgments About the Authors About Deitel & Associates, Inc Before You Begin Resources on the CD That Accompanies C++ How to Program, Fifth Edition iv ii xxiii xxiii xxvii xxxi xliv xlvi xlix xlix xlix li lii liii liii lvi lvii lix lix Copying and Organizing Files Copying the Book Examples from the CD Changing the Read-Only Property of Files Chapter 1 Introduction to Computers, the Internet and World Wide Web Section 1.1 Introduction Section 1.2 What Is a Computer? Section 1.3 Computer Organization Section 1.4 Early Operating Systems Section 1.5 Personal, Distributed and Client/Server Computing Section 1.6 The Internet and the World Wide Web Section 1.7 Machine Languages, Assembly Languages and High-Level Languages Section 1.8 History of C and C++ Section 1.9 C++ Standard Library Section 1.10 History of Java Section 1.11 FORTRAN, COBOL, Pascal and Ada Section 1.12 Basic, Visual Basic, Visual C++, C# and NET Section 1.13 Key Software Trend: Object Technology Section 1.14 Typical C++ Development Environment Section 1.15 Notes About C++ and C++ How to Program, 5/e Section 1.16 Test-Driving a C++ Application Section 1.17 Software Engineering Case Study: Introduction to Object Technology and the UML (Required) Section 1.18 Wrap-Up Section 1.19 Web Resources Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Chapter 2 Introduction to C++ Programming Section 2.1 Introduction Section 2.2 First Program in C++: Printing a Line of Text Section 2.3 Modifying Our First C++ Program Section 2.4 Another C++ Program: Adding Integers Section 2.5 Memory Concepts Section 2.6 Arithmetic Section 2.7 Decision Making: Equality and Relational Operators Section 2.8 (Optional) Software Engineering Case Study: Examining the lix lx lx 5 6 8 10 11 11 12 15 16 22 27 27 29 31 33 34 34 36 37 37 41 42 46 48 51 ATM Requirements Document Section 2.9 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Chapter 3 Introduction to Classes and Objects Section 3.1 Introduction Section 3.2 Classes, Objects, Member Functions and Data Members Section 3.3 Overview of the Chapter Examples Section 3.4 Defining a Class with a Member Function Section 3.5 Defining a Member Function with a Parameter Section 3.6 Data Members, set Functions and get Functions Section 3.7 Initializing Objects with Constructors Section 3.8 Placing a Class in a Separate File for Reusability Section 3.9 Separating Interface from Implementation Section 3.10 Validating Data with set Functions Section 3.11 (Optional) Software Engineering Case Study: Identifying the Classes in the ATM Requirements Document Section 3.12 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Chapter 4 Control Statements: Part 1 Section 4.1 Introduction Section 4.2 Algorithms Section 4.3 Pseudocode Section 4.4 Control Structures Section 4.5 if Selection Statement Section 4.6 if else Double-Selection Statement Section 4.7 while Repetition Statement Section 4.8 Formulating Algorithms: Counter-Controlled Repetition Section 4.9 Formulating Algorithms: Sentinel-Controlled Repetition Section 4.10 Formulating Algorithms: Nested Control Statements Section 4.11 Assignment Operators 56 65 65 67 68 69 70 74 75 75 77 77 81 84 91 95 99 105 110 118 118 121 121 122 122 124 125 125 126 127 131 132 137 139 145 156 161 Section 4.12 Increment and Decrement Operators 161 Section 4.13 (Optional) Software Engineering Case Study: Identifying Class Attributes in the ATM System 165 Section 4.14 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Chapter 5 Control Statements: Part 2 Section 5.1 Introduction Section 5.2 Essentials of Counter-Controlled Repetition Section 5.3 for Repetition Statement Section 5.4 Examples Using the for Statement Section 5.5 while Repetition Statement Section 5.6 switch Multiple-Selection Statement Section 5.7 break and continue Statements Section 5.8 Logical Operators Section 5.9 Confusing Equality (==) and Assignment (=) Operators Section 5.10 Structured Programming Summary Section 5.11 (Optional) Software Engineering Case Study: Identifying Objects' States and Activities in the ATM System Section 5.12 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Chapter 6 Functions and an Introduction to Recursion Section 6.1 Introduction Section 6.2 Program Components in C++ Section 6.3 Math Library Functions Section 6.4 Function Definitions with Multiple Parameters Section 6.5 Function Prototypes and Argument Coercion Section 6.6 C++ Standard Library Header Files Section 6.7 Case Study: Random Number Generation Section 6.8 Case Study: Game of Chance and Introducing enum Section 6.9 Storage Classes Section 6.10 Scope Rules 169 170 172 173 174 177 185 186 186 188 193 197 199 209 211 216 217 222 226 228 230 230 231 233 238 239 240 241 243 248 250 252 258 262 265 Section 6.11 Function Call Stack and Activation Records 268 Section 6.12 Functions with Empty Parameter Lists Section 6.13 Inline Functions 272 273 Section 6.14 References and Reference Parameters Section 6.15 Default Arguments Section 6.16 Unary Scope Resolution Operator Section 6.17 Function Overloading Section 6.18 Function Templates Section 6.19 Recursion Section 6.20 Example Using Recursion: Fibonacci Series Section 6.21 Recursion vs Iteration Section 6.22 (Optional) Software Engineering Case Study: Identifying Class Operations in the ATM System Section 6.23 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Chapter 7 Arrays and Vectors Section 7.1 Introduction Section 7.2 Arrays Section 7.3 Declaring Arrays Section 7.4 Examples Using Arrays Section 7.5 Passing Arrays to Functions Section 7.6 Case Study: Class GradeBook Using an Array to Store Grades Section 7.7 Searching Arrays with Linear Search Section 7.8 Sorting Arrays with Insertion Sort Section 7.9 Multidimensional Arrays Section 7.10 Case Study: Class GradeBook Using a Two-Dimensional Array Section 7.11 Introduction to C++ Standard Library Class Template vector Section 7.12 (Optional) Software Engineering Case Study: Collaboration Among Objects in the ATM System Section 7.13 Wrap-Up Summary Terminology Self-Review Exercises 275 280 282 283 286 288 292 295 298 305 306 309 311 313 316 326 327 328 329 330 346 351 358 359 362 365 372 377 385 385 387 388 Answers to Self-Review Exercises 389 Exercises Recursion Exercises 390 400 vector Exercises Chapter 8 Pointers and Pointer-Based Strings Section 8.1 Introduction Section 8.2 Pointer Variable Declarations and Initialization Section 8.3 Pointer Operators Section 8.4 Passing Arguments to Functions by Reference with Pointers Section 8.5 Using const with Pointers Section 8.6 Selection Sort Using Pass-by-Reference Section 8.7 sizeof Operators Section 8.8 Pointer Expressions and Pointer Arithmetic Section 8.9 Relationship Between Pointers and Arrays Section 8.10 Arrays of Pointers Section 8.11 Case Study: Card Shuffling and Dealing Simulation Section 8.12 Function Pointers Section 8.13 Introduction to Pointer-Based String Processing Section 8.14 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Special Section: Building Your Own Computer More Pointer Exercises String-Manipulation Exercises Special Section: Advanced String-Manipulation Exercises A Challenging String-Manipulation Project Chapter 9 Classes: A Deeper Look, Part 1 Section 9.1 Introduction Section 9.2 Time Class Case Study Section 9.3 Class Scope and Accessing Class Members Section 9.4 Separating Interface from Implementation Section 9.5 Access Functions and Utility Functions Section 9.6 Time Class Case Study: Constructors with Default Arguments Section 9.7 Destructors Section 9.8 When Constructors and Destructors Are Called 400 401 402 403 404 407 411 418 421 424 427 431 432 438 443 454 455 456 457 459 461 464 469 474 475 479 480 481 482 487 489 491 493 499 500 Section 9.9 Time Class Case Study: A Subtle TrapReturning a Reference 503 to a private Data Member Section 9.10 Default Memberwise Assignment Section 9.11 Software Reusability Section 9.12 (Optional) Software Engineering Case Study: Starting to Program the Classes of the ATM System Section 9.13 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Chapter 10 Classes: A Deeper Look, Part 2 Section 10.1 Introduction Section 10.2 const (Constant) Objects and const Member Functions Section 10.3 Composition: Objects as Members of Classes Section 10.4 friend Functions and friend Classes Section 10.5 Using the this Pointer Section 10.6 Dynamic Memory Management with Operators new and delete Section 10.7 static Class Members Section 10.8 Data Abstraction and Information Hiding Section 10.9 Container Classes and Iterators Section 10.10 Proxy Classes Section 10.11 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Chapter 11 Operator Overloading; String and Array Objects Section 11.1 Introduction Section 11.2 Fundamentals of Operator Overloading Section 11.3 Restrictions on Operator Overloading Section 11.4 Operator Functions as Class Members vs Global Functions Section 11.5 Overloading Stream Insertion and Stream Extraction Operators Section 11.6 Overloading Unary Operators Section 11.7 Overloading Binary Operators 506 508 509 516 517 519 519 520 520 523 524 524 534 541 545 550 552 558 561 562 565 566 567 568 569 569 571 572 573 574 576 577 581 581 Section 11.8 Case Study: Array Class Section 11.9 Converting between Types Section 11.10 Case Study: String Class Section 11.11 Overloading ++ and -Section 11.12 Case Study: A Date Class Section 11.13 Standard Library Class string Section 11.14 explicit Constructors Section 11.15 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Chapter 12 Object-Oriented Programming: Inheritance Section 12.1 Introduction Section 12.2 Base Classes and Derived Classes Section 12.3 protected Members Section 12.4 Relationship between Base Classes and Derived Classes Section 12.5 Constructors and Destructors in Derived Classes Section 12.6 public, protected and private Inheritance Section 12.7 Software Engineering with Inheritance Section 12.8 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Chapter 13 Object-Oriented Programming: Polymorphism Section 13.1 Introduction Section 13.2 Polymorphism Examples Section 13.3 Relationships Among Objects in an Inheritance Hierarchy Section 13.4 Type Fields and switch Statements Section 13.5 Abstract Classes and Pure virtual Functions Section 13.6 Case Study: Payroll System Using Polymorphism Section 13.7 (Optional) Polymorphism, Virtual Functions and Dynamic Binding "Under the Hood" Section 13.8 Case Study: Payroll System Using Polymorphism and RunTime Type Information with Downcasting, dynamic_cast, typeid and type_info 582 594 595 607 609 613 617 621 621 624 624 625 625 633 634 635 638 638 670 678 678 680 681 682 682 683 683 686 687 689 690 707 708 710 728 732 Section 13.9 Virtual Destructors Section 13.10 (Optional) Software Engineering Case Study: Incorporating Inheritance into the ATM System Section 13.11 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Chapter 14 Templates Section 14.1 Introduction Section 14.2 Function Templates Section 14.3 Overloading Function Templates Section 14.4 Class Templates Section 14.5 Nontype Parameters and Default Types for Class Templates Section 14.6 Notes on Templates and Inheritance Section 14.7 Notes on Templates and Friends Section 14.8 Notes on Templates and static Members Section 14.9 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Chapter 15 Stream Input/Output Section 15.1 Introduction Section 15.2 Streams Section 15.3 Stream Output Section 15.4 Stream Input Section 15.5 Unformatted I/O using read, write and gcount Section 15.6 Introduction to Stream Manipulators Section 15.7 Stream Format States and Stream Manipulators Section 15.8 Stream Error States Section 15.9 Tying an Output Stream to an Input Stream Section 15.10 Wrap-Up Summary Terminology Self-Review Exercises Answers to Self-Review Exercises 735 736 744 744 746 746 747 747 749 750 751 754 754 761 762 762 763 764 764 765 766 766 766 769 770 771 775 776 780 781 787 797 800 800 800 803 804 806 Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] U integer suffix u integer suffix ul element ul element (XHTML) UL integer suffix ul integer suffix ultimate operator overloading exercise UML action expression 2nd 3rd action state 2nd activity diagram 2nd 3rd 4th arrow attribute class diagram constructor in a class diagram data types decision decision symbol diamond symbol 2nd dotted line final state guard condition 2nd 3rd guillemets (« and ») initial state merge symbol minus sign () note plus sign (+) public operation small circle symbol solid circle symbol String type transition transition arrow 2nd 3rd 4th 5th UML (Unified Modeling Language) 2nd 3rd 4th 5th 6th 7th 8th 9th 10th diagram UML activity diagram UML Activity Diagram solid circle (for representing an initial state) in the UML solid circle enclosed in an open circle (for representing the end of an activity) in the UML UML class diagram attribute compartment constructor operation compartment UML Partners UML Sequence Diagram activation arrowhead lifeline UML State Diagram rounded rectangle (for representing a state) in the UML solid circle (for representing an initial state) in the UML UML Use Case Diagram actor use case unary cast operator unary decrement operator ( ) unary increment operator (++) unary minus (-) operator unary operator 2nd 3rd unary operator overload 2nd unary plus (+) operator unary predicate function 2nd 3rd unary scope resolution operator (::) unbuffered output unbuffered standard error stream unconditional branch unconditional branch goto unconditional branch instruction unconditional goto statement in Simple undefined area in memory undefined value underflow_error exception underlying container underlying data structure underscore (_) unexpected event unexpected function 2nd unformatted I/O 2nd 3rd unformatted I/O using the read, gcount and write member functions unformatted output 2nd Unicode® 2nd 3rd Unified Modeling Language (UML) 2nd 3rd 4th 5th 6th 7th 8th 9th Uniform Resource Locator (URL) unincremented copy of an object uninitialized local reference causes a syntax error uninitialized variable union 2nd anonymous union constructor union functions cannot be virtual union with no constructor unique keys 2nd 3rd unique member function of list unique STL algorithm 2nd 3rd unique_copy STL algorithm 2nd 3rd universal-time format UNIX 2nd 3rd 4th 5th 6th 7th 8th 9th UNIX command line 2nd unmodifiable unmodifiable lvalue 2nd unnamed bit field unnamed bit field with a zero width unnamed namespace unnamed object unoptimized code unordered list element (ul) unresolved references 2nd unsigned char data type unsigned data type 2nd 3rd unsigned int data type 2nd 3rd unsigned integer in bits unsigned long data type 2nd 3rd 4th unsigned long int data type 2nd unsigned short data type unsigned short int data type unspecified number of arguments unsuccessful termination untie an input stream from an output stream unwinding the function call stack update a record update records in place upper_bound function of associative container upper_bound STL algorithm uppercase letter 2nd 3rd 4th 5th 6th uppercase stream manipulator 2nd 3rd URL (Uniform Resource Locator) 2nd us (top-level domain) use case diagram in the UML 2nd use case in the UML 2nd use case modeling USENIX C++ Conference user interface user-defined class name user-defined function 2nd maximum user-defined termination function user-defined type 2nd 3rd user-defined types User-defined, nonparameterized stream manipulators userdata.txt using a dynamically allocated ostring-stream object using a function template Using a static data member to maintain a count of the number of objects of a class using an anonymous union using an iterator to output a string using arrays instead of switch using command-line arguments using declaration 2nd using directive using function swap to swap two strings using functions exit and atexit using goto using member function fill and stream manipulator setfill to change the padding character for fields larger than the values being printed using namespace directive using signal handling using Standard Library functions to perform a heapsort using stream manipulator uppercase using template functions using variable-length argument lists Using virtual base classes utility function demonstration utility make Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] va_arg 2nd va_end 2nd va_list 2nd va_start 2nd validation 2nd validity checking valign attribute of element th value value attribute of element input value of a variable 2nd value of an array element value of an attribute value_type 2nd variable variable arguments header variable name 2nd argument parameter variable size variable type variable-length argument list 2nd VAX VMS vector class 2nd capacity function 2nd push_back function rbegin function rend function vector class template vector class template element-manipulation functions verb phrase in requirements document verbs in a problem statement verbs in a system specification vertical spacing 2nd vertical tab ('v') 2nd vi text editor 2nd video I/O viewcart.cgi virtual base class 2nd 3rd 4th virtual destructor virtual directory virtual function 2nd 3rd 4th 5th 6th 7th 8th virtual function call virtual function call illustrated virtual function table (vtable) virtual inheritance virtual memory 2nd 3rd virtual memory operating systems visibility in the UML visibility marker in the UML Visual Basic NET Visual C++ NET Visual C++ home page 2nd Visual Studio NET Quick Info box visualizing recursion VMS void * 2nd void keyword 2nd void return type volatile qualifier 2nd volume of a cube vtable 2nd 3rd 4th vtable pointer Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] waiting line walk a list "walk off" either end of an array "warehouse" section of the computer warning watch debugger command Watch window (Visual C++ NET debugger) 2nd waterfall model wchar_t character type 2nd "weakest" iterator type 2nd Web address Web browser Web form Web server 2nd 3rd 4th 5th webstore.ansi.org/ansidocstore/default.asp what function of class runtime_error what virtual function of class exception 2nd while repetition statement 2nd 3rd 4th 5th 6th white-space character 2nd 3rd 4th 5th 6th 7th 8th 9th 10th blank newline tab whole number whole/part relationship width attribute of element img width attribute of element table width implicitly set to 0 width member function of class ios_base 2nd width of a bit field width of random number range width setting width-to-height ratio Windows 2nd 3rd Windows 2000 Withdrawal class (ATM case study) 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th word 2nd word boundary word equivalent of a check amount word processing 2nd Wordpad workflow of a portion of a software system workflow of an object in the UML workstation World Wide Web (WWW) World Wide Web resources for STL worst-case runtime for an algorithm wraparound write function of ostream 2nd 3rd 4th writing data randomly to a random-access file www.accu.informika.ru/resources/public/terse/cpp.htm www.acm.org/crossroads/xrds3-2/ovp32.html www.borland.com www.borland.com/bcppbuilder www.codearchive.com/list.php?go=0708 www.compilers.net www.cuj.com www.deitel.com 2nd 3rd www.deitel.com/newsletter/subscribe.html 2nd www.devx.com www.forum.nokia.com/main/0,6566,050_20,00.html www.gametutorials.com/Tutorials/GT/GT_Pg1.htm www.hal9k.com/cug www.jasc.com www.kai.com/C_plus_plus www.mathtools.net/C_C /Games/ www.metrowerks.com www.msdn.microsoft.com/visualc/ www.omg.org 2nd www.prenhall.com/deitel www.research.att.com/~bs/homepage.html www.symbian.com/developer/development/cppdev.html www.thefreecountry.com/developercity/ccompilers.shtml www.uml.org www.unicode.org www.w3.org/markup www.w3.org/TR/xhtml1 www.w3schools.com/xhtml/default.asp www.xhtml.org Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] XHTML (Extensible Hypertext Markup Language) XHTML (Extensible HyperText Markup Language) 2nd 3rd comment document elements form 2nd Recommendation table tag xor operator keyword xor_eq operator keyword Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] yellow arrow in break mode Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] zero-based counting zero-width bit field zeros and ones zeroth element ... Internet and World Wide Web How to Program, 3/E Java How to Program, 6/E Small C++ How to Program, 5/E Small Java™ How to Program, 6/E Perl How to Program Python How to Program Visual C++ NET How to Program Visual Basic® 6 How to Program... How To Program Series Advanced Java™ 2 Platform How to Program C How to Program, 4/E C++ How to Program, 5/E C# How to Program e-Business and e-Commerce How to Program Internet and World Wide Web How to Program, 3/E... Software Engineering Case Study Software Bundled with C++ How to Program, 5/e Teaching Resources for C++ How to Program, 5/e C++ Multimedia Cyber Classroom, 5/e, Online C++ in the Lab CourseCompassSM, WebCT™ and Blackboard™