Tài liệu C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN docx

1.4K 871 0
Tài liệu C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN docx

Đ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

C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN FOURTH EDITION D.S MALIK Australia  Brazil  Japan  Korea  Mexico  Singapore  Spain  United Kingdom  United States C++ Programming: From Problem Analysis to Program Design, Fourth Edition by D.S Malik Senior Product Manager: Alyssa Pratt Acquisitions Editor: Amy Jollymore Content Product Manager: Jill Braiewa Marketing Manager: Bryant Chrzan Editorial Assistant: Patrick Frank Print Buyer: Julio Esperas Cover Designer: Lisa Kuhn, Curio Press, LLC Compositor: Integra Art Director: Marissa Falco Validation: Green Pen Quality Assurance ª 2009 Course Technology, Cengage Learning ALL RIGHTS RESERVED No part of this work covered by the copyright herein may be reproduced, transmitted, stored or used in any form or by any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the publisher For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706 For permission to use material from this text or product, submit all requests online at cengage.com/permissions Further permissions questions can be emailed to permissionrequest@cengage.com Proofreader: Green Pen Quality Assurance Indexer: Liz Cunningham ISBN-13: 978-1-4239-0209-6 ISBN-10: 1-4239-0209-2 Course Technology 25 Thomson Place Boston, MA 02210 USA Visualâ C++ NET and PowerPointâ are registered trademarks of the Microsoft Corporation; Pentiumâ is a registered trademark of Intel Corporation; IBM is a registered trademark of Industrial Business Machines Disclaimer Course Technology reserves the right to revise this publication and make changes from time to time in its content without notice The programs in this book are for instructional purposes only They have been tested with care, but are not guaranteed for any particular intent beyond educational purposes The authors and the publisher not offer any warranties or representations, nor they accept any liabilities with respect to the programs Cengage Learning is a leading provider of customized learning solutions with office locations around the globe, including Singapore, the United Kingdom, Australia, Mexico, Brazil, and Japan Locate your local office at: international.cengage.com/region Cengage Learning products are represented in Canada by Nelson Education, Ltd For your lifelong learning solutions, visit course.cengage.com Visit our corporate website at cengage.com Printed in Canada 14 13 12 11 10 09 08 TO My Daughter Shelly Malik BRIEF CONTENTS PREFACE An Overview of Computers and Programming Languages Basic Elements of C++ xxvii 29 Input/Output 115 Control Structures I (Selection) 167 Control Structures II (Repetition) 231 User-Defined Functions I 307 User-Defined Functions II 345 User-Defined Simple Data Types, Namespaces, and the string Type 415 Arrays and Strings 469 10 Applications of Arrays (Searching and Sorting) and the vector Type 545 11 Records (structs) 603 12 Classes and Data Abstraction 641 13 Inheritance and Composition 717 14 Pointers, Classes, Virtual Functions, and Abstract Classes 785 15 Overloading and Templates 853 16 Exception Handling 943 17 Recursion 981 18 Linked Lists 1017 19 Stacks and Queues 1111 vi | C++ Programming: From Problem Analysis to Program Design, Fourth Edition APPENDIX A Reserved Words 1219 APPENDIX B Operator Precedence 1221 APPENDIX C Character Sets 1223 APPENDIX D Operator Overloading 1227 APPENDIX E Additional C++ Topics 1229 APPENDIX F Header Files 1251 APPENDIX G Memory Size on a System and Random Number Generator 1261 APPENDIX H Standard Template Library (STL) 1263 APPENDIX I Answers to Odd-Numbered Exercises 1305 INDEX 1327 TABLE OF CONTENTS Preface xxvii AN OVERVIEW OF COMPUTERS AND PROGRAMMING LANGUAGES Introduction A Brief Overview of the History of Computers Elements of a Computer System Hardware Central Processing Unit Main Memory Secondary Storage Input /Output Devices 6 Software The Language of a Computer The Evolution of Programming Languages A C++ Program 10 Processing a C++ Program 12 Programming with the Problem Analysis–Coding–Execution Cycle 14 Programming Methodologies Structured Programming 22 22 Object-Oriented Programming 22 ANSI/ISO Standard C++ 24 Quick Review 24 Exercises 26 viii | C++ Programming: From Problem Analysis to Program Design, Fourth Edition BASIC ELEMENTS OF C++ 29 The Basics of a C++ Program 30 Comments Special Symbols 32 32 Reserved Words (Keywords) Identifiers 33 33 Whitespaces 34 Data Types Simple Data Types Floating-Point Data Types Arithmetic Operators and Operator Precedence Order of Precedence Expressions Mixed Expressions 34 35 38 40 44 45 46 Type Conversion (Casting) 48 string Type 50 Input Allocating Memory with Constants and Variables 51 52 Putting Data into Variables Assignment Statement 54 54 Saving and Using the Value of an Expression 58 Declaring and Initializing Variables Input (Read) Statement 59 60 Variable Initialization 63 Increment and Decrement Operators 67 Output 69 Preprocessor Directives 77 namespace and Using cin and cout in a Program Using the string Data Type in a Program 78 78 Creating a C++ Program 79 Program Style and Form Syntax Use of Blanks 83 83 84 Table of Contents | Use of Semicolons, Brackets, and Commas 84 Semantics Naming Identifiers 84 84 Prompt Lines Documentation 85 86 Form and Style 86 More on Assignment Statements 88 Programming Example: Convert Length 99 Programming Example: Make Change 93 Quick Review 97 Exercises 99 Programming Exercises 107 INPUT/OUTPUT 115 I/O Streams and Standard I/O Devices cin and the Extraction Operator >> 116 117 Using Predefined Functions in a Program cin and the get Function 123 125 cin and the ignore Function The putback and peek Functions 126 128 The Dot Notation Between I/O Stream Variables and I/O Functions: A Precaution 130 Input Failure The clear Function 131 133 Output and Formatting Output setprecision Manipulator 135 135 fixed Manipulator 136 showpoint Manipulator setw 136 138 Additional Output Formatting Tools setfill Manipulator left and right Manipulators Input/Output and the string Type 141 141 143 145 ix x | C++ Programming: From Problem Analysis to Program Design, Fourth Edition File Input/Output 146 Programming Example: Movie Ticket Sale and Donation to Charity Programming Example: Student Grade 155 Quick Review 158 Exercises 160 Programming Exercises 150 163 CONTROL STRUCTURES I (SELECTION) 167 Control Structures 168 Relational Operators 169 Relational Operators and Simple Data Types 171 Comparing Floating-point Numbers for equality Comparing Characters 171 172 Relational Operators and the string Type 173 Logical (Boolean) Operators and Logical Expressions Order of Precedence 175 177 Short-Circuit Evaluation 181 int Data Type and Logical (Boolean) Expressions bool Data Type and Logical (Boolean) Expressions 182 183 Selection: if and if else 184 One-Way Selection Two-Way Selection 185 187 Compound (Block of) Statements 191 Multiple Selections: Nested if Comparing if else Statements with 192 a Series of if Statements Using Pseudocode to Develop, Test, and Debug a Program 196 196 Input Failure and the if Statement 199 Confusion Between the Equality Operator (==) and the Assignment Operator (=) 202 Conditional Operator (?:) 203 switch Structures 204 1330 | Index constructor(s) (continued) invoking, 664–666 linked lists and, 1039–1041, 1044, 1045, 1072 operator overloading and, 894 parameters and, 665–670 precautions regarding, 670–671 queues and, 1144, 1179–1180, 1190 stacks and, 1116, 1124–1125 container(s) adapters, 1289–1293 member functions common to, 1273–1276 sequence, 1264–1273, 1275–1288 continue statements, 278–281 control structures See also repetition checking account balances and, 250–259 described, 158–159 divisibility tests and, 276–278 Fibonacci numbers and, 259–264 nested, 241–243, 270, 281–288 number-guessing games and, 244–247, 249–250 overview, 167–229 relational operators and, 169–174 short-circuit evaluation and, 181–182 conversion constructor, 914 CONVERSION memory space, 52–53 convertEnum function, 428, 430–431 copy constructors See also constructors described, 816–823, 894 linked lists and, 1039, 1041, 1045 stacks and, 1116 copy function, 1276–1280 copyList function, 1043–1044, 1072 copyStack function, 1124, 1143–1144 copyText function, 527–528 cos function, 309 counter-controlled while loops, 236–238 courseScore variable, 358–359 cout keyword, 33, 69 cout statement, 76, 497, 983–984 described, 78 functions and, 130 inheritance and, 738 preprocessor directives and, 116–117 cpp file extension, 12, 79 CPUs (central processing units) described, 4–5 history of, cstdlib header file, 1262 c_str function, 498–499 cstring header file See string.h (cstring) header file c-strings (character arrays), 492–499, 514–516, 910–916 ctype.h (cctype) header file, 1252–1253 CU (control unit), 4–5 curly braces ({}), 80, 82, 84 customer(s) queues and, 1188–1191, 1199–1200 use of the term, 1187 customerNumber variable, 1188 customerType class, 1188–1191 cylinders, dimensions of, 750–751 cylinderSurfaceArea operation, 751 cylinderType class, 750–751 cylinderVolume operation, 751 D dangling pointers, 801 data abstraction, 674–676 comparison, 388–398 formatted, 1234 data types See also specific data types anonymous, 424–425 arithmetic operators and, 40–45 control structures and, 171 conversion, 48–50 described, 34–50 extraction operator and, 118–119 simple, 35–38, 171, 415–468 user-defined, 415–468 dataType class, 743–745 dClass class, 741, 742, 743 debugging See also errors control structures and, 196–199 information hiding and, 677 variables and, 66 decimal numbers described, 8, 1229 nonnegative numbers and, 1229–1131 recursion and, 999–1007 decimal point (.), 130–132, 140 decision makers, 185, 233 declaration statements, 80 decrement operators, 67–69, 887–888 decToBin function, 1005, 1007 deep copy, 810–812 default keyword, 204 delete operator, 797, 799–801, 813 deleteNode function, 1038, 1045, 1048–1053, 1079–1080 deleteQueue function, 1167–1172, 1178–119, 1183 deque class, 1280–1283 deque container, 1280–1283 dereferencing operator, 787, 788–794, 795, 1034 derived classes See also inheritance constructors of, 728–736 described, 718–721 Index | header files and, 735–736 member functions of, 725–726 virtual destructors and, 830 derivedClass class, 721, 733, 824, 828–829 destroyList function, 817, 818 destructor(s) described, 673–674 linked lists and, 1044 operator overloading and, 894 pointers and, 813–814 queues and, 1179–1180 stacks and, 1116, 1124–1125 virtual, 830 diagonals, reversing, 509–511 different formal parameter lists, use of the term, 378–379 digital signals, 6–7 discardExp function, 1157 displayResults function, 428, 431–432 displayRules function, 427–428 divByZero class, 960 divisibility tests, 276–278 divisionByZero class, 961, 963, 966, 968 divisors, 276–278 keyword, 274 .while loops break statements and, 278–281 exception handling and, 971 overview, 274–278 documentation, 86 doDivision function, 964, 968 domains, 675 dot notation, 130–131 dot operator, 794, 795 double data type, 39, 40 functions and, 309, 316, 351 inheritance and, 741 memory and, 54 operator overloading and, 868 templates and, 917, 919 double quotes ("), 51, 75, 443 doubleFirst function, 369 doublyLinkedList class, 1071 draw function, 830 dummyExceptionClass class, 959 dynamic arrays, 803–809, 475 See also arrays dynamic binding See run-time binding E EBCDIC (Extended Binary-Coded Decimal Interchange Code), 8, 38, 492, 1224–1225 Eiffel, 750 election results, 579–595 ellipse class, 830 else statements, 193–194 employeeType class, 832–834 encapsulation, 749 end function, 1042, 1270–1273, 1278 enumeration types arrays and, 503–507 defining, 416–417 described, 35–38, 416 functions and, 422–424 input/output of, 420–422 operations on, 419 overview, 416–437 enumerators, 417 eof function, 248–249 EOF-controlled while loops, 247–248, 284–287 equal sign (¼), 32 equality operator, 202–203 equalTime function, 644–645, 651–656 error(s) See also debugging; exception handling; syntax errors constructors and, 665 control structures and, 211, 212 linked lists and, 1049 logging, 972 stacks and, 1157 variables and, 63 escape (\) character, 70, 75–76, 148 evaluateExpression function, 1153–1155 1331 evaluateOpr function, 1155–1157 exabytes (EB), exception(s) See also exception handling classes, 955–969 throwing, 949–950, 956, 961–969 exception handling See also errors; exceptions mechanisms of, 948–955 overview, 943–979 within programs, 944–948 techniques, 970–975 exclamation point (!), 32 executable statements, 80–81 execution dynamic arrays and, 803 flow of, 325 time, specifying input/output files at, 498 exp function, 309 expr variable, 315 expressions See also logical (Boolean) expressions arithmetic, 41–43 conditional, 203–204 floating-point, 45–48 integral, 45–48 mixed, 46–47 saving and using the value of, 58–59 extern keyword, 374 external variables, 374 extraction operator, 117–123, 738, 866, 874–879 F fabs function, 309 fact function, 984 fail state, 132 Fibonacci numbers described, 259–264 recursion and, 990–991 FIFO (First In First Out) structure, 1167 file(s) closing, 148 I/O, 146–149, 498 1332 | Index file(s) (continued) name extensions, 12, 79 opening, 147, 149 specifying, at execution time, 498 fill function, 144, 809, 1296–1298 fill_n function, 1296–1298 find function, 449–451 find_if function, 1298–1299 first variable, 369, 1038 firstRect variable, 784 fixed manipulator, 136, 137–138 flag variables, 244 flag-controlled while loops, 243–244 float data type, 39, 40 float.h (cfloat) header file, 1253–1254 floating point data type arithmetic operators and, 43 control structures and, 171–172 described, 35–40 type conversion and, 48–50 floating-point expressions, 45–48 floor function, 309, 310 for keyword, 265 for loops arrays and, 475–476, 506–508, 807 break statements and, 278–281 enumeration types and, 320 exception handling and, 958 functions and, 348–349, 352, 371 nested loops and, 281–288 overview, 264–270 searches and, 568 STL and, 1276, 1278 vector data type and, 577 for loop control variable, 265 formal parameters, 313–314 formatted data, 1234 FORTRAN, 3, forward slash (/), 32 friend functions, 862–865, 887, 893–894 front, of queues, 1042, 1167–1168, 1074–1075, 1177–1178 front function, 1042, 1074–1075 fstream header file, 146 fullTimeEmployee class, 832, 835–836 funcExp function, 380–381 function(s) See also main function arrays and, 482–491, 511–514 calls, 123 classes and, relationship between, 650 data types/return types of, 314 definitions, 313 described, 30 dot notation and, 130–131 enumeration types and, 422–424 flow of execution and, 325 friend, 862–865 headings (headers), 312–313 inheritance and, 721–728 names, 346 nesting, 370 overloading, 378–380, 916 overview, 307–414 pointers and, 806 predefined/standard, 30, 123–131, 308–311 prototypes, 318–323, 325, 380, 873–876, 880, 890, 891 pure virtual, 830–838 return values, 806 signatures, 378 templates, 854, 917–919 value-returning, 312–313, 314–315, 370 virtual, 823–830 void, 312, 346–354 functionA function, 974 functionB function, 974, 975 functionC function, 974, 975 functions (listed by name) abs function, 309, 312, 313 addFirst function, 369 addQueue function, 1167–1172, 1182–1183, 1185, 1199–1200 addRegionsVote function, 588–589 addressOfX function, 840 assert function, 211–218, 911, 944, 947 back function, 1042, 1183 begin function, 1042, 1270–1273, 1278 binary_search function, 1301–1303 binToDec function, 1003 buildListBackward function, 1033 buildListForward function, 1031, 1033 calculate function, 390 calculateAverage function, 390–392 callPrint function, 825–826 ceil function, 309 characterCount function, 528 classifyNumber function, 384 clear function, 133–135, 144 compareCode function, 520–521 compareThree function, 318–323 convertEnum function, 428, 430–431 copy function, 1276–1280 copyList function, 1043–1044, 1072 copyStack function, 1124, 1143–1144 copyText function, 527–528 cos function, 309 c_str function, 498–499 decToBin function, 1005, 1007 deleteNode function, 1038, 1045, 1048–1053, 1079–1080 deleteQueue function, 1167–1172, 1178–119, 1183 destroyList function, 817, 818 discardExp function, 1157 Index | displayResults function, 428, 431–432 displayRules function, 427–428 doDivision function, 964, 968 doubleFirst function, 369 draw function, 830 end function, 1042, 1270–1273, 1278 eof function, 248–249 equalTime function, 644–645, 651–656 evaluateExpression function, 1153–1155 evaluateOpr function, 1155–1157 exp function, 309 fabs function, 309 fact function, 984 fill function, 144, 809, 1296–1298 fill_n function, 1296–1298 find function, 449–451 find_if function, 1298–1299 floor function, 309, 310 front function, 1042, 1074–1075 funcExp function, 380–381 functionA function, 974 functionB function, 974, 975 functionC function, 974, 975 funcValueParam function, 355 funOne function, 362–364, 375 funTwo function, 364 gameResult function, 427–430 get function, 125–126, 128, 130–131 144, 738 getCandidatesName function, 582–583 getCurrentBalance function, 692 getData function, 625–627 getDay function, 745 getFirstName function, 860 getFreeServerID function, 1197 getHeight function, 727 getLastName function, 860 getLength function, 727 getline function, 145, 287 getMonth function, 745 getNumber function, 383–384, 387 getNumberOfBusyServers function, 1197 getScore function, 359 getStudentData function, 765–766 getTime function, 644, 651–656, 899 getWidth function, 727 getYear function, 745 ignore function, 126–128, 144, 738 incrementHours function, 644 incrementMinutes function, 644, 654 incrementSeconds function, 644, 651–656 initialize function, 383, 385, 527, 584, 624, 1073 initializeList function, 1041 initializeQueue function, 1167–1168, 1174, 1182–1185 initializeStack function, 1114, 1119–1120, 1138 insert function, 1076–1077 insertFirst function, 1033, 1038, 1045, 1047–1048, 1061–1062, 1195 insertLast function, 1033, 1038, 1045, 1048, 1062 insertNode function, 1061 isEmptyList function, 1040 isEmptyQueue function, 1167–1168, 1200 isEmptyStack function, 1114, 1138 isFullQueue function, 1167–1168 isFullStack function, 1114, 1136, 1138 islower function, 312 isNumPalindrome function, 323–325 1333 larger function, 316–323, 326–327, 379–380, 917, 918–919 largerChar function, 379 largerInt function, 379 largestInRows function, 512, 513–514 length function, 446–448 max function, 326–327 maxSaleByPerson function, 629 maxSaleByQuarter function, 629–630 move function, 831 peek function, 128–130 pigLatinString function, 456–457 pow function, 309, 310, 312, 325 print function, 721, 727, 729, 742, 761–762, 809, 826–827, 860, 878, 1073–1074 printArray function, 490 printGrade function, 359 printGradeReports function, 766–767 printHeading function, 398, 590 printListReverse function, 1068 printMatrix function, 511–514 printReport function, 628–629 printResults function, 384–385, 391–393, 397, 438, 590–591 printStars function, 348–349, 351–352 printTime function, 644, 651–656 processVotes function, 588 putback function, 128–130 rand function, 1262 rbegin function, 1277 readCode function, 519–520 remove function, 1299–1301 rend function, 1277 replace function, 1299–1301 retrievePlay function, 427–429 1334 | Index functions (listed by name) (continued) reversePrint function, 1066–1068 rotate function, 456 runSimulation function, 1202–1203 saleByQuarter function, 627 search function, 1038, 1301–1303, 1045–1047 searchItem function, 550, 1074 seekp function, 1240–1245 sellProduct function, 696–698 seqSearch function, 548–550 setCustomerInfo function, 1190 setData function, 741, 742, 745–746 setDimension function, 727 setLastName function, 860 setName function, 860 setServerBusy function, 1197 setSimulationParameters function, 1201 setTime function, 644, 651–656, 648, 662, 899 showSelection function, 696 size function, 448–449 sort function, 1301–1303 sortCandidatesName function, 583–584 square root function, 309 squareFirst function, 369 strcmp function, 493–495 strcpy function, 493–495 strlen function, 493–495 substr function, 452–454, 957 sumRows function, 512, 513–514 swap function, 454–460 tail recursive function, 985 testCopyConst function, 823 testTime function, 651 tolower function, 310 top function, 1122 totalSaleByPerson function, 627–628 toupper function, 310, 312 updateServer function, 1198 updateXYZ function, 858–859 validSelection function, 427–428 what function, 955 winningObject function, 428, 431 WriteTotal function, 528 funcValueParam function, 355 funOne function, 362–364, 375 funTwo function, 364 G gameResult function, 427–430 general case, 982–893, 987 get function, 125–126, 128, 130–131 144, 738 getCandidatesName function, 582–583 getCurrentBalance function, 692 getData function, 625–627 getDay function, 745 getFirstName function, 860 getFreeServerID function, 1197 getHeight function, 727 getLastName function, 860 getLength function, 727 getline function, 145, 287 getMonth function, 745 getNumber function, 383–384, 387 getNumberOfBusyServers function, 1197 getScore function, 359 getStudentData function, 765–766 getTime function, 644, 651–656, 899 getWidth function, 727 getYear function, 745 gigabytes (GB), global variables, 374–376 GPAs (grade point averages), 194–195, 604–606, 610–611, 751–772, 1130–1134 GPS (global positioning satellites), grade(s) See also GPAs (grade point averages) calculating, 356–359 reports, 751–772 greater-than sign (>), 32 H h file extension, 1248 Hamblin, Charles L., 1148 hardware, head, use of the term, 1018–1019, 1020, 1022 header files, 76, 212, 1145–1146 described, 77 exception handling and, 956 functions and, 123–124 information hiding and, 678–679 inheritance and, 735–737, 738, 742 I/O and, 123–124, 139, 141, 144, 146 linked lists and, 1053–1054, 1063–1066 manipulators and, 139, 141, 144 multiple inclusions of, 726–727 namespaces and, 78, 437, 440–441 naming conventions, 1248–1249 overview, 1251–1260 pointers and, 821 stacks and, 1126–1130 string data type and, 516 templates and, 921–927 height variable, 727, 729, 731 hexadecimal numbers, 1232–1234 high-level languages, Hollerith, Herman, hr variable, 645, 655, 664 hyphen (-), 32 I IBM (International Business Machines), 2, 3, 38 identifier(s) described, 33–34 functions and, 370–374 Index | global, 370–374 inheritance and, 737 legal, 34 local, 370–374 namespaces and, 442 naming, 84–85 nested, 371 scope of, 370–374 self-documenting, 85 if statements described, 184–204 exception handling and, 944 input failure and, 199–201 linked lists and, 1067 nested, 192–197 operator overloading and, 881–882 recursion and, 1006 series of, comparing if .else statements with, 196 if .else statements described, 184–204 functions and, 359 while loops and, 241–243 ifstream class, 738, 739 ignore function, 126–128, 144, 738 implementation files, 678, 921–927 implicit type conversion, 48 #include directive, 77, 78, 116–117, 147 arrays and, 494 functions and, 310 inheritance and, 727 increment operators, 67–69, 802, 887–888, 1034 incrementHours function, 644 incrementMinutes function, 644, 654 incrementSeconds function, 644, 651–656 indirection operator See dereferencing operator infile variable, 248, 499 infinite loops, 234 infix notation, 1148 information hiding, 677–681 inheritance See also base classes; derived classes constructors and, 748 described, 718, 749 multiple, 719 overview, 718–743 pointers and, 823–830 private, 719, 720–721 protected, 719 public, 719, 720–721, 725–726 single, 719 initialize function, 383, 385, 527, 584, 624, 1073 initialize statement, 371 initializeList function, 1041 initializeQueue function, 1167–1168, 1174, 1182–1185 initializeStack function, 1114, 1119–1120, 1138 input See also input/output (I/O) devices, failure, 122, 131–133, 199–201 overview, 51–66 statements, 60–66 stream variables, 199 input/output (I/O) See also input binary files and, 1234–1239 devices, standard, 116–123 file, 146–149, 498 formatting output and, 135–140 overview, 110–166 predefined functions and, 123–131 random file access and, 1240–1248 records and, 610 streams and, 116–123, 130–131, 738–739 string data type and, 145, 498–499 input stream variables, 130–131 insert function, 1076–1077 1335 insertFirst function, 1033, 1038, 1045, 1047–1048, 1061–1062, 1195 insertion operator, 738, 854, 866 insertion sorts, 559–666 insertLast function, 1033, 1038, 1045, 1048, 1062 insertNode function, 1061 instance variables, 656 int data type, 36–37, 54 arrays and, 485–487, 512, 807 control structures and, 182–183 dynamic arrays and, 803–804 exception handling and, 952, 955 functions and, 322–323, 351 linked lists and, 1022–1028 memory and, 54 pointers and, 787, 788, 790, 792, 799–800, 802, 810 records and, 617 templates and, 917, 919 variables and, 66, 68 integral data type, 35–38, 491 integral expressions, 45–48 intList variable, 612–613 ios class, 738 iostream header file, 77, 78, 144, 309, 440–441, 738 IR (instruction register), isEmptyList function, 1040 isEmptyQueue function, 1167–1168, 1200 isEmptyStack function, 1114, 1138 isFullQueue function, 1167–1168 isFullStack function, 1114, 1136, 1138 islower function, 312 isNegative variable, 279 isNumPalindrome function, 323–325 ISO (International Standards Organization), 24 See also ANSI/ISO Standard Cỵỵ 1336 | Index istream class, 131, 248, 437, 738, 739 istream member functions, 123 iteration See also iterators described, 998 recursion and, 998–1007 iterator(s) See also iteration described, 1034 linked lists and, 1034–1041 STL and, 1269–1270, 1288–1293 J Jacquard, Joseph, Java, 9, 750 Jobs, Steven, K key (item) comparisons, 550 keywords See also specific keywords described, 33 overview, 1219 kilobytes (KB), L larger function, 316–323, 326–327, 379–380, 917, 918–919 largerChar function, 379 largerInt function, 379 largestInRows function, 512, 513–514 last variable, 1038 left manipulator, 143–144 Leibniz, Gottfried von, length converting, 89–93 of linked lists, 1041, 1073 length function, 446–448 length variable, 727, 729, 731, 868 length_error exception, 956 less-than sign (

Ngày đăng: 15/02/2014, 07:20

Từ khóa liên quan

Mục lục

  • 01_C6605_title_page.pdf

  • 02_C6605_copyright_new.pdf

  • 03_C6605_dedication.pdf

  • 04_C6605_Brief_contents.pdf

  • 05_C6605_Table_of_Contents.pdf

  • 06_C6605_Preface.pdf

  • 07_C6605_features_page.pdf

  • 08_6605_sup_resources.pdf

  • 09_C6605_Acknowledgement.pdf

  • C6606_C01_CTP.pdf

  • C6606_C02_CTP.pdf

  • C6606_C03_CTP.pdf

  • C6606_C04_CTP.pdf

  • C6606_C05_CTP.pdf

  • C6606_C06_CTP.pdf

  • C6607_C07_CTP.pdf

  • C6607_C08_CTP.pdf

  • C6607_C09_CTP.pdf

  • C6607_C10_CTP.pdf

  • C6607_C11_CTP.pdf

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

Tài liệu liên quan