c++ programming program design including data structcures

1.6K 1.8K 5
c++ programming  program design including data structcures

Đ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++.

C++ PROGRAMMING: PROGRAM DESIGN INCLUDING DATA STRUCTURES FIFTH EDITION D.S MALIK Australia  Brazil  Japan  Korea  Mexico  Singapore  Spain  United Kingdom  United States This is an electronic version of the print textbook Due to electronic rights restrictions, some third party content may be suppressed Editorial review has deemed that any suppressed content does not materially affect the overall learning experience The publisher reserves the right to remove content from this title at any time if subsequent rights restrictions require it For valuable information on pricing, previous editions, changes to current editions, and alternate formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for materials in your areas of interest C++ Programming: Program Design Including Data Structures, Fifth Edition D.S Malik Executive Editor: Marie Lee Acquisitions Editor: Amy Jollymore 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 www.cengage.com/permissions Further permissions questions can be emailed to permissionrequest@cengage.com Senior Product Manager: Alyssa Pratt Editorial Assistant: Zina Kresin Library of Congress Control Number: 2010921540 Content Project Manager: Matthew Hutchinson ISBN-13: 978-0-538-79809-2 Art Director: Faith Brosnan Print Buyer: Julio Esperas Proofreader: GreenPen QA Indexer: Elizabeth Cunningham Cover Designer: Roycroft Design/ www.roycroftdesign.com Cover Photo: Contemporary Building ª Steve Hix/Somos Images/Corbis Compositor: Integra ª 2011 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 ISBN-10: 0-538-79809-2 Course Technology 20 Channel Center Street Boston, MA 02210 USA Some of the product names and company names used in this book have been used for identification purposes only and may be trademarks or registered trademarks of their respective manufacturers and sellers Any fictional data related to persons or companies or URLs used throughout this book is intended for instructional purposes only At the time this book was printed, any such data was fictional and not belonging to any real persons or companies Course Technology, a part of Cengage Learning, 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 author 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: www.cengage.com/global Cengage Learning products are represented in Canada by Nelson Education, Ltd To learn more about Course Technology, visit www.cengage.com/coursetechnology Purchase any of our products at your local college store or at our preferred online store www.CengageBrain.com TO My Parents Printed in the United States of America 16 15 14 13 12 11 10 B RIEF C ONTENTS PREFACE An Overview of Computers and Programming Languages Basic Elements of C++ xxv 27 Input/Output 117 Control Structures I (Selection) 175 Control Structures II (Repetition) 247 User-Defined Functions I 319 User-Defined Functions II 361 User-Defined Simple Data Types, Namespaces, and the string Type 433 Arrays and Strings 485 10 Records (structs) 563 11 Classes and Data Abstraction 601 12 Inheritance and Composition 675 13 Pointers, Classes, Virtual Functions, Abstract Classes, and Lists 745 14 Overloading and Templates 827 15 Exception Handling 919 16 Recursion 959 17 Linked Lists 991 18 Stacks and Queues 1083 iv | C++ Programming: Program Design Including Data Structures, Fifth Edition 19 Searching and Sorting Algorithms 1183 20 Binary Trees 1265 21 Graphs 1321 22 Standard Template Library (STL) 1361 APPENDIX A Reserved Words 1477 APPENDIX B Operator Precedence 1479 APPENDIX C Character Sets 1481 APPENDIX D Operator Overloading 1485 APPENDIX E Additional C++ Topics 1487 APPENDIX F Header Files 1509 APPENDIX G Memory Size on a System and Random Number Generator 1519 APPENDIX H References 1521 APPENDIX I Answers to Odd-Numbered Exercises 1523 INDEX 1555 TABLE OF C ONTENTS Preface xxv Introduction A Brief Overview of the History of Computers Elements of a Computer System Hardware Central Processing Unit and Main Memory AN OVERVIEW OF COMPUTERS AND PROGRAMMING LANGUAGES 4 Input /Output Devices Software The Language of a Computer The Evolution of Programming Languages Processing a C++ Program 10 Programming with the Problem Analysis–Coding–Execution Cycle 12 Programming Methodologies 20 Structured Programming 20 Object-Oriented Programming 20 ANSI/ISO Standard C++ Quick Review 22 Exercises 22 23 BASIC ELEMENTS OF C++ 27 A C++ Program 28 The Basics of a C++ Program 31 Comments 32 Special Symbols 32 vi | C++ Programming: Program Design Including Data Structures, Fifth Edition Reserved Words (Keywords) 33 Identifiers 33 Whitespaces 34 Data Types 35 Simple Data Types 35 Floating-Point Data Types 38 Arithmetic Operators and Operator Precedence Order of Precedence Expressions Mixed Expressions 39 43 44 45 Type Conversion (Casting) 47 string Type 49 Input 50 Allocating Memory with Constants and Variables 50 Putting Data into Variables 53 Assignment Statement 53 Saving and Using the Value of an Expression 56 Declaring and Initializing Variables 57 Input (Read) Statement 58 Variable Initialization 61 Increment and Decrement Operators 65 Output 67 Preprocessor Directives 75 namespace and Using cin and cout in a Program 76 Using the string Data Type in a Program 76 Creating a C++ Program 77 Debugging: Understanding and Fixing Syntax Errors 80 Program Style and Form 84 Syntax 84 Use of Blanks 85 Use of Semicolons, Brackets, and Commas 85 Semantics 85 Naming Identifiers 85 Prompt Lines 86 Documentation 87 Form and Style 87 More on Assignment Statements 89 Programming Example: Convert Length 91 Table of Contents | vii Programming Example: Make Change 94 Quick Review 98 Exercises Programming Exercises 100 109 INPUT/OUTPUT I/O Streams and Standard I/O Devices cin and the Extraction Operator >> Using Predefined Functions in a Program 117 118 119 124 cin and the get Function 127 cin and the ignore Function 128 The putback and peek Functions 130 The Dot Notation between I/O Stream Variables and I/O Functions: A Precaution Input Failure The clear Function 132 133 135 Output and Formatting Output 137 setprecision Manipulator 137 fixed Manipulator 138 showpoint Manipulator 139 setw 142 Additional Output Formatting Tools 144 setfill Manipulator 144 left and right Manipulators 146 Input/Output and the string Type 148 Debugging: Understanding Logic Errors and Debugging with cout Statements File Input/Output 152 Programming Example: Movie Tickets Sale and Donation to Charity 156 Programming Example: Student Grade 162 Quick Review 165 Exercises 166 Programming Exercises 149 170 CONTROL STRUCTURES I (SELECTION) 175 Control Structures 176 Relational Operators 177 Relational Operators and Simple Data Types 178 viii | C++ Programming: Program Design Including Data Structures, Fifth Edition Comparing Characters 179 Relational Operators and the string Type 180 Logical (Boolean) Operators and Logical Expressions 182 Order of Precedence 184 int Data Type and Logical (Boolean) Expressions 187 bool Data Type and Logical (Boolean) Expressions 188 Selection: if and if else 188 One-Way Selection 189 Two-Way Selection 191 Compound (Block of) Statements 195 Multiple Selections: Nested if 195 Comparing if else Statements with a Series of if Statements 198 Short-Circuit Evaluation 199 Comparing Floating-Point Numbers for Equality: A Precaution 200 Associativity of Relational Operators: A Precaution 201 Avoiding Bugs by Avoiding Partially Understood Concepts and Techniques Input Failure and the if Statement 203 206 Confusion between the Equality Operator (==) and the Assignment Operator (=) 209 Conditional Operator (?:) 211 Program Style and Form (Revisited): Indentation 211 Using Pseudocode to Develop, Test, and Debug a Program 212 switch Structures 215 Avoiding Bugs by Avoiding Partially Understood Concepts and Techniques (Revisited) 221 Terminating a Program with the assert Function Programming Example: Cable Company Billing 225 Quick Review 231 Exercises 232 Programming Exercises 223 241 CONTROL STRUCTURES II (REPETITION) 247 Why Is Repetition Needed? 248 while Looping (Repetition) Structure 249 Designing while Loops 251 Case 1: Counter-Controlled while Loops 252 Case 2: Sentinel-Controlled while Loops 255 Index | domain, 631 dot notation, 132, 133 double data type, 121, 498 functions and, 328, 329 inheritance and, 687, 700 templates and, 891, 893 double quotes (‘‘), 458, 510, 513, 695 doubleFirst function, 381 doubleLinkedList class, 1042 draw function, 788 driver programs, 392, 393–394 dynamic arrays See also arrays described, 761 overview, 490, 761–767 dynamic variables See also variables described, 756 overview, 755–759 E early binding See compile-time binding EBCDIC (Extended Binary Coded Decimal Interchange Code), 8, 37, 510, 1482–1483 edge(s) described, 1323 directed (branch), 1266 origin of, 1323 parallel, 1325 weight of, 1337, 1348–1352 election-results example, 1235–1256 employeeType class, 789, 790 empty function, 1372, 1403–1405 encapsulation, 708 end function, 1014–1015, 1369–1372, 1373 enumeration types, 35, 506 anonymous data types and, 442–443 described, 434 functions and, 440–442 input/output of, 438–440 loops and, 438 operations on, 437 overview, 434–444 two-dimensional arrays and, 521–524 enumerators, 435 eof function, 263–264 EOF-controlled while loops, 263, 264–268, 294–295 equal sign (=), 1121 equality operator, 209–211 equalTime function, 605, 607, 608, 614–615, 616 erase function, 462, 463, 1367, 1373, 1374, 1400 1561 errors See also bugs; compile-time errors; debugging; syntax errors identifiers and, 34 information hiding and, 634 logging, 948 logic, 149–152 semantic, 194 stacks and, 1096, 1124, 1126 escape sequences, 69–74 evaluateExpression function, 1122–1124 evaluateOpr function, 1124 example function, 499 exception handling exception classes and, 931–945 logging errors and, 948 mechanisms, 924–931 overview, 919–957 with programs, 920–935 stack unwinding and, 948–951 techniques, 946–948 exe filename extension, 77, 78 executable code, 637–642 statements, 78 exp function, 321 expressions See also specific types overview, 44–46 saving, 56–57 using the value of, 56–57 extClockType class, 676 extern keyword, 386 extraction operator, 119–124, 129, 148, 696–697, 840, 848–853 F fabs function, 321 fact function, 962 fail state, 134, 208 Fibonacci numbers, 967–971, 974 described, 269 overview, 270–273, 279–280 nth, 270, 967–971 Fibonacci sequences, 270 FIFO (First In First Out) data structure, 1134, 1362 file(s) described, 153 input/output, 152–165 -name extensions, 77–78 opening, 153 stream variables, 153 fill function, 767, 1418–1420 fill_n function, 1418–1420 1562 | Index fillNames function, 1246–1247 find function, 462, 465–467, 1422–1427 find_end function, 1422–1427 find_first_of function, 1422–1427 find_if function, 1422–1427 first, use of the term, 992 fixed manipulator, 138–139, 140–141 flag variables, 260 flag-controlled while loops, 259, 260, 268 floating-point data types, 35, 38, 39, 44, 200–201 floor function, 321, 322 for keyword, 274 for loops, 780, 1201, 1335, 1354 arrays and, 493, 524, 525, 526, 765 enumeration types and, 438 exception handling and, 934 functions and, 365, 383 nested, 292–293 operator overloading and, 859 overview, 273–280 sorting algorithms and, 1207, 1216 STL and, 1368, 1369, 1371, 1375, 1376 for_each function, 1452–1454 formal parameter lists, 326, 362, 395 formatted data, 1492 forward slash (/), 32 free tree, 1346 friend functions, 836, 837–840 front, of queues, 1133 front function, 1134, 1380, 1405 front_inserter iterator, 1417 fstream class, 697 fstream.h header file, 697, 1506 fullTimeEmployee class, 789, 791–793 funcArrayAsParam function, 498 funcExp function, 397 function(s) See also functions (listed by name) body, 325 calls, 125, 326, 340, 363 debugging and, 392–394 with default parameters, 396–399 definition of, 325, 362 described, 31 enumeration types and, 440–442 flow of execution and, 340–341 friend, 836, 837–840 headers, 325 identifiers and, 382–386 memory allocation and, 372–382 nesting, 382 objects, 1410, 1411–1416 overloading, 395, 396, 708, 890 passing two-dimensional arrays as parameters to, 527–530 predefined, 320–323 prototypes, 331, 332–333, 397, 398 redefining/overriding, 679–686 return values, 764 signatures, 395 structS and, 570–571 stubs, 394 templates, 891, 892–893 user-defined, 324 value-returning, 324, 325-343 functions (listed by name) See also functions; main function abs function, 321, 325 accumulate function, 1463–1468 addFirst function, 381 addQueue function, 1134, 1136, 1138, 1139, 1143, 1147–1150, 1165 addressOfX function, 810, 811 addVotes function, 1252 adjacent_difference function, 1463–1468 adjacent_find function, 1441–1445 append function, 462 assert function, 223–231, 920, 923, 1509 assign function, 1380, 1385 at function, 462, 1380 back function, 1045, 1134, 1380, 1385, 1405 begin function, 1014–1015, 1369–1373 billingAmount function, 721 binary_search function, 1437–1440 binSearch function, 1193 binToDec function, 977–979 breadthFirstTraversal function, 1336–1337 bubbleSort function, 1206, 1207 buildListBackward function, 1006 buildListForward function, 1003–1004, 1006 calculateTotalVotes function, 1242 callPrint function, 781, 782, 786 ceil function, 321 clear function, 135–136, 462, 463, 1367, 1373, 1374, 1400 clearGraph function, 1332 clearList function, 802 compare function, 462 compareThree function, 331, 332–333 copy function, 1375, 1376–1378 copyList function, 1015–1016 copyStack function, 1090, 1096, 1114–1115 copyTree function, 1282, 1283–1284 cos function, 321 count function, 1448–1452 count_if function, 1448–1452 Index | createGraph function, 1331–1332 createSpanningGraph function, 1353 createWeightedGraph function, 1338–1339 decToBin function, 980–982 deleteFromTree function, 1293–1296 deleteNode function, 1024–1025, 1033–1034, 1050–1051, 1280, 1295–1296 deleteQueue function, 1134, 1136, 1137, 1139, 1143–1144, 1147–1150, 1164–1165 depthFirstTraversal function, 1335 destroy function, 1282, 1283 destroyList function, 774, 776, 1012–1013, 1282, 1283 dft function, 1335 dftAtVertex function, 1335 discardExp function, 1126 divideList function, 1228–1229, 1231, 1232 doDivision function, 940 doubleFirst function, 381 draw function, 788 empty function, 1372, 1403–1405 end function, 1014–1015, 1369–1372, 1373 eof function, 263–264 equalTime function, 605, 607, 608, 614–615, 616 erase function, 462, 463, 1367, 1373, 1374, 1400 evaluateExpression function, 1122–1124 evaluateOpr function, 1124 example function, 499 exp function, 321 fabs function, 321 fact function, 962 fill function, 767, 1418–1420 fill_n function, 1418–1420 fillNames function, 1246–1247 find function, 462, 465–467, 1422–1427 find_end function, 1422–1427 find_first_of function, 1422–1427 find_if function, 1422–1427 floor function, 321, 322 for_each function, 1452–1454 front function, 1134, 1380, 1405 funcArrayAsParam function, 498 funcExp function, 397 generate function, 1420–1422 generate_n function, 1420–1422 get function, 127–128, 514, 696 getCost function, 653 getCredits function, 721 getData function, 584–586 getFirstName function, 1238 getFreeServerID function, 1162 1563 getGpa function, 722 getLastName function, 1238 getLength function, 685 getLine function, 515 getNumberOfBusyServers function, 1162 getScore function, 369–370 getStudentData function, 724–725 getTime function, 616 getTotalVotes function, 1242 getWaitingTime function, 1156 getWidth function, 685 height function, 1271 ignore function, 128–130, 696 includes function, 1455–1463 incrementMinutes function, 614 incrementSeconds function, 614 incrementWaitingTime function, 1156 initalize function, 583 initializeList function, 1013–1014, 1044 initializeQueue function, 1134, 1140, 1142, 1147–1150 initializeStack function, 1086, 1091–1092, 1110 inner_product function, 1463–1468 inorder function, 1275, 1302 inorderTitle function, 1310 inorderTraversal function, 1280, 1304 inplace_merge function, 1441–1445 insert function, 462, 467–468, 808, 1037, 1047, 1280, 1289, 1367, 1373, 1374, 1399 insertAt function, 803–804 insertEnd function, 804, 899, 902, 1246 insertFirst function, 1006, 1019–1020, 1032–1033, 1118 insertLast function, 1006, 1020, 1032–1033 insertNode function, 1048 isEmpty function, 1280, 1330–1331 isEmptyList function, 1012, 1043 isEmptyQueue function, 1134, 1165 isEmptyStack function, 1086, 1092, 1109–1110 isFullQueue function, 1134, 1147, 1165 isFullStack function, 1086, 1108, 1109–1110, 1092 isItemAt function, 801 isItemAtEqual function, 897 islower function, 322 isNumPalindrome function, 338–340 isupper function, 322 larger function, 328–331, 332, 341–343 largerChar function, 396 largerInt function, 396 largest function, 966–967 largestInRows function, 528–529 1564 | Index functions (listed by name) (Continued) length function, 462, 463, 464–465 listSize function, 800–801 max function, 1448–1452 max_element function, 1448–1452 maxListSize function, 800–801 maxSaleByPerson function, 588 maxSaleByQuarter function, 588–589 max_size function, 1373 merge function, 1232, 1386, 1387, 1441–1445 mergeList function, 1230–1231, 1233, 1234 function, 1448–1452 min_element function, 1448–1452 minimalSpanning function, 1353–1354 minLocation function, 1211–1212 move function, 788 nodeCount function, 1282 partial_sum function, 1463–1468 partition function, 1223, 1224 peek function, 130–132 poolCapacity function, 394 poolFillTime function, 394 pop function, 1085, 1086, 1110, 1112–1114, 1094–1096, 1403–1405 pop_back function, 1367, 1374 pop_front function, 1380, 1382, 1385 pow function, 321–326, 456 print function, 684, 701, 714, 720–721, 767, 781–783, 801, 852, 897, 1013, 1044 printDataTotalVotes function, 1242 printGradeReports function, 725–726 printGraph function, 1332 printListReverse function, 1039–1040 printMatrix function, 528–529 printReport function, 587–588 printResult function, 453, 454, 457, 1126–1129 printShortestDistance function, 1344 printStars function, 364–366 printTime function, 605, 616 printTreeAndWeight function, 1354–1355 processVotes function, 1250 push function, 1085, 1086, 1110–1112, 1092–1094, 1403–1405 push_back function, 1367, 1368, 1374, 1382 push_front function, 1380, 1385 quickSort function, 1224 random_shuffle function, 1448–1452 rbegin function, 1373, 1376 recMergeSort function, 1231–1233 remove function, 805, 899, 1427, 1385 removeAt function, 801, 805, 897 remove_copy function, 1427 remove_copy_if function, 1427 remove_if function, 1385, 1427 replace function, 463, 467–468, 1430–1434 replaceAt function, 805–806, 899 replace_copy function, 1430–1434 replace_copy_if function, 1430–1434 replace_if function, 1430–1434 resize function, 1367, 1368, 1374 retrieveAt function, 802, 897 reverse function, 1387, 1445–1448 reverse_copy function, 1445–1448 reversePrint function, 1037–1039 rFibNum function, 967–971 rollDice function, 639–640 rotate function, 1445–1448 rotate_copy function, 1445–1448 runSimulation function, 1167, 1168 saleByQuarter function, 586 search function, 1018–1019, 1045, 1280, 1288–1289, 1437–1440 search_n function, 1437–1440 searchVideoList function, 1309 seekg function, 1498, 1499–1503 seekp function, 1499–1500, 1503 sellProduct function, 654–655 seqSearch function, 508–509, 573, 574, 805, 899 setCustomerInfo function, 1155–1156 setData function, 701, 704–705 set_difference function, 1455–1463 setDimension function, 684, 685 setFirstName function, 834–835 setInfo function, 718 set_intersection function, 1455–1463 setLastName function, 834–835 setName function, 1238 setServerBusy function, 1162 setSimulationParameters function, 1166 set_symmetric_difference function, 1455–1463 setTime function, 604, 605, 608, 611–612, 616, 621, 622 set_union function, 1455–1463 setX function, 755 shortestPath function, 1343, 1344 showSelection function, 654 size function, 463, 1372, 1403–1405 sort function, 1207, 1386, 1437–1440 sortCourses function, 718, 722 splice function, 1386, 1389–1390 sqrt function, 321, 322 squareFirst function, 381 strcmp function, 512, 513 strlen function, 512 substr function, 463, 469–470 Index | sumRows function, 528–529 swap function, 463, 470, 1210–1211, 1223, 1373, 1434 terminate function, 948 testTime function, 610–611 tolower function, 322 top function, 1085, 1086, 1403–1404 totalSaleByPerson function, 586–587 toupper function, 322, 323, 1454 transform function, 1452–1454 unique function, 1385 updateServers function, 1163 updateVotesByRegion function, 1242 what function, 931–932 write function, 1498 G general case, 960, 965 generate function, 1420–1422 generate_n function, 1420–1422 get function, 127–128, 514, 696 getCost function, 653 getCredits function, 721 getData function, 584–586 getFirstName function, 1238 getFreeServerID function, 1162 getGpa function, 722 getLastName function, 1238 getLength function, 685 getLine function, 515 getNumberOfBusyServers function, 1162 getScore function, 369–370 getStudentData function, 724–725 getTime function, 616 getTotalVotes function, 1242 getWaitingTime function, 1156 getWidth function, 685 grade-calculation programs, 162–165, 369–372, 710–731, 1102–1106 graph(s) See also digraph (directed graph) as ADTs, 1329–1332 definitions, 1323–1326 described, 1323 minimal spanning tree, 1345–1355 notations, 1323–1326 operations on, 1328–1329 overview, 1321–1360 representation, 1326–1328 traversals, 1333–1337 graphType class, 1329–1330, 1338 greedy algorithm See shortest path algorithm 1565 H hardware, overview of, 4–5 head, use of the term, 992, 994, 996 header file(s), 76, 80, 456, 512 See also specific files containers and, 1406–1407 control structures and, 224 described, 634 functions and, 321 graphs and, 1344 inheritance and, 694–696 input/output and, 118, 142, 143 linked lists and, 1025–1026, 1034–1037 multiple inclusions of, 695–696 namespaces and, 452, 458 naming conventions, 1506–1507 overview, 1509–1517 stacks and, 1098–1102 templates and, 895 heap algorithms, 1410 height, use of the term, 1270, 1271 height function, 1271 hexadecimal number system, 1490–1492 high-level languages, Hollerith, Herman, I IBM (International Business Machines) character sets and, 37 encoding schemes and, history of, 2–3 identifiers described, 33 functions and, 382–386 global, 382 local, 382 namespaces and, 452, 455 naming, 85–86 overview, 33–34 self-documenting, 86 IDEs (integrated development environments) debugging and, 299 exception handling and, 935 executable code and, 638 filename extensions and, 78 identifiers and, 34 indentation and, 212 input/output and, 137 overview, 11–12 if statements, 188–212, 981 comparing if .else statements with, 198–199 1566 | Index if statements (Continued) functions and, 334 nested, 195, 196, 197–199 if .else statements, 198–199 ignore function, 128–130, 696 illustrate class, 644–648 immediate successors, 1329 implementation files, 634, 895 implicit type coercion, 47 incident edges, 1325 #include preprocessor directive, 75, 81, 512, 637 functions and, 322–323 inheritance and, 696 input/output and, 118 STL and, 1363, 1379, 1383, 1397 string data type and, 458 includes function, 1455–1463 increment operator, 65, 66–67, 760, 861–862 incrementMinutes function, 614 incrementSeconds function, 614 incrementWaitingTime function, 1156 indexes See array indexes infinite loops, 250 infix notation, 1119, 1120 information hiding, 623–637 inheritance constructors and, 686–693 described, 676 linked lists and, 1018 overview, 676–702, 708 pointers and, 780–787 stream classes and, 696–697 initalize function, 583 initializeList function, 1013–1014, 1044 initializeQueue function, 1134, 1140, 1142, 1147–1150 initializeStack function, 1086, 1091–1092, 1110 inner_product function, 1463–1468 inorder function, 1275, 1302 inorder sequence, 1272, 1273 inorder traversal, nonrecursive, 1297–1299 inorderTitle function, 1310 inorderTraversal function, 1280, 1304 inplace_merge function, 1441–1445 input See also input/output (I/O) devices, failure, 124, 133, 134–136, 206–207 iterators, 1390–1391 memory allocation and, 50–53 overview, 50–65 statement, 58–61 stream variables, 119 streams, 118 string, 514–515 input/output (I/O) See also input; output c-Strings and, 515–517 debugging and, 149–152 enumeration types and, 438 EOF-controlled while loops and, 263, 264 file, 152–165, 516 functions and, 321 inheritance and, 696–697 overview, 1492–1506 random file access and, 1498–1506 stream classes and, 696–697 stream variables, 132–133 string data type and, 148–152, 458 structS and, 570–571 insert function, 462, 467–468, 808, 1037, 1047, 1280, 1289, 1367, 1373, 1374, 1399 insert iterator, 1416, 1417, 1418 insertAt function, 803–804 insertEnd function, 804, 899, 902, 1246 inserter iterator, 1417 insertFirst function, 1006, 1019–1020, 1032–1033, 1118 insertion operator, 515, 696, 697 insertion sort algorithms, 1212, 1213–1218 insertLast function, 1006, 1020, 1032–1033 insertNode function, 1048 instance variables, 615 instances, of classes, 606 int data type, 36–37, 121, 333–335, 364 arrays and, 508, 761, 763–764, 765, 767 binary trees and, 1302, 1304 classes and, 603, 624 control structures and, 187–188 dereferencing operator and, 748–751 dynamic variables and, 756 exception handling and, 942 lists and, 797, 996 pointers and, 746, 747 recursion and, 976 STL and, 1365, 1369, 1371, 1375–1376, 1402, 1420, 1427 StructS and, 568, 577 templates and, 891, 893 int keyword, 87 integral data type, 35–36, 506 integral expressions, 44 iomanip.h header file, 458, 1506 ios class, 697 iostream.h header file, 321, 452, 456–455, 458, 695, 696–697, 1506, 1507 isEmpty function, 1280, 1330–1331 Index | isEmptyList function, 1012, 1043 isEmptyQueue function, 1134, 1165 isEmptyStack function, 1086, 1092, 1109–1110 isFullQueue function, 1134, 1147, 1165 isFullStack function, 1086, 1108, 1109–1110, 1092 isItemAt function, 801 isItemAtEqual function, 897 islower function, 322 isNumPalindrome function, 338–340 ISO (International Standards Organization), 22 istream class, 697 istream iterators, 1396 istream member functions, 124 istream_iterator class, 1396 isupper function, 322 iterative control structures See also iterators described, 974 linked lists and, 1007–1013 recursion and, 974–984 iterators See also iterative control structures bidirectional, 1392–1393 containers and, 1406–1407 declaring, 1368–1369 described, 1007 forward, 1392 input, 1390–1391 linked lists and, 1007–1013 ostream, 1376–1378, 1402, 1423 output, 1391 overview, 1367, 1390–1396 random access, 1393–1394 stream, 1396 types of, 1390–1395 J Jacquard, Joseph, Jobs, Steven, K key, of items, 1185 keywords See also specific keywords described, 33 list of, 1477 kilobytes (KB), 67 Konigsberg bridge problem, 13221323 ă Kruskals algorithm, 1347 1567 L larger function, 328–331, 332, 341–343 largerChar function, 396 largerInt function, 396 largest function, 966–967 largestInRows function, 528–529 largest-number program, 342–343 leaf, use of the term, 1269 left child, 1266 left manipulator, 146–148 left subtree, 1266 length, of a path, 1270 length function, 462, 463, 464–465 length-conversion program, 91–94 length_error class, 932 level, of nodes, 1270 libraries See also STL (C++ Standard Template Library) described, 11 Standard C++, 458 LIFO (Last In First Out) data structure, 117, 1085, 1088, 1362 limits.h (climits) header file, 1506, 1512–1513 linked lists See also lists ADTs and, 1005–1017, 1026–1027, 1040–1042 building, 1000–1005 circular, 1051 copying, 1015–1016 deleting items in, 996–999 described, 992 destroying, 1012–1013, 1043 dividing, 1227–1229 doubly, 1040–1051 first/last elements of, 1045–1051 initializing, 1013–1014, 1044 inserting items in, 996–999 iterators, 1007–1013 length of, 1013–1014, 1044 ordered, 1026–1037 overview, 991–1082 printing, 1013, 1037–1039, 1044–1045 properties, 993–1000 recursion and, 1037–1039 searching, 1018–1019, 1027–1028, 1045 sorting algorithms and, 1225–1235 stacks and, 1118–1119 traversing, 995–996 unordered, 1017–1026 linkedListIterator class, 1007–1009 linkedListType class, 1005–1007, 1009, 1011–1012, 1016, 1017, 1130, 1150 1568 | Index linkedQueueType class, 1146, 1149–1151 linkedStackType class, 1108–1109, 1117–1119 linkers, 11 links, of nodes, 992 list(s) See also linked lists adjacency, 1327–1328 array-based, 1208–1225 described, 796 formal parameter, 326, 362, 395 length of, 796 sort algorithms and, 1208–1225 list class, 1383–1390 list container, 1383–1390, 1407 listSize function, 800–801 listType class, 632, 893–894 loaders, 11 local declaration, 328 logic errors, 149–152, 932 See also errors logical expressions, 178, 182–188, 443–444 logical operators, 182–188 logical values, 178 loop(s) See also recursion; specific types arrays and, 491 enumeration types and, 438 graphs and, 1325 nested, 291–296, 525, 526 overview, 1325 recursion and, 974–984 stacks and, 1131–1133 structS and, 575–576 loop control variables (LCVs), 250, 251, 256, 274 Lukasiewicz, Jan, 1119 M machine language, main function, 31, 78, 80, 124, 324, 369, 381, 456–457, 795, 832–833, 838, 1122, 1168 candy-machine example and, 656–657 exception handling and, 940, 950 pointer variables and, 754, 778–779 structS and, 589–590 void functions and, 362 main memory See RAM (random access memory) make command, 638 map containers, 1407 math.h (cmath) header file, 456, 458, 1506, 1514–1515 max function, 1448–1452 max_element function, 1448–1452 maxListSize function, 800–801 maxSaleByPerson function, 588 maxSaleByQuarter function, 588–589 max_size function, 1373 member access operator, 133, 567, 607–609 member access operator arrow, 753 member access specifiers, 603 See also private members; protected members; public members member functions containers and, 1372–1374 implementation of, 611–615 operator functions and, 839–842 operator overloading and, 839–846 redefining/overriding, 679–686 members, of classes, 602 memory See also RAM (random access memory); stacks addresses, allocation, 50–53, 372–382 cells, data types and, 36 leaks, 758 overview, 4–5 structS and, 565–566 size, 1519–1520 menu-driven programs, 388–389 merge function, 1232, 1386, 1387, 1441–1445 merge sort algorithms, 1225–1235 mergeList function, 1230–1231, 1233, 1234 function, 1448–1452 min_element function, 1448–1452 minimal spanning tree, 1345–1346, 1347, 1348–1355 minimalSpanning function, 1353–1354 minLocation function, 1211–1212 mixed expressions, 45, 46 mnemonics, 8–9 modular programming, 20 modules, 320 See also functions move function, 788 movie-ticket-sales program, 156–161 multidimensional arrays, 518–533 See also arrays multimap containers, 1407 multiple inheritance, 677 See also inheritance multiset containers, 1397–1399, 1407 mutator functions, 616, 617–619 myException class, 948–949 N named constants, 51, 52, 386–390, 461 namespace keyword, 76 namespaces, 76, 452–458, 1506, 1507, 1519–1520 n-dimensional arrays, 532, 533 See also arrays Index | new operator, 756–757, 761, 933–934 newline (\n) escape sequence, 69, 71–73, 120, 128, 295 newString class, 882, 884–890 node(s) building linked lists and, 1000–1005 dangling, 999 data of, retrieving, 1014 deleting, 1020–1024, 1033–1034, 1048–1051 described, 992 inserting, 1019–1025, 1028–1032, 1046–1048 level of, 1270 link properties and, 993–1000 overview, 1217 structure of, 1006 nodeCount function, 1282 nonrecursive algorithms, 1129–1133 null character, 510 null pointers, 755 null strings, 49 number(s) See also specific number systems -classification program, 399–404 conversion, 1487–1492 -guessing game, 260–261 random, generating, 1519–1520 O obj filename extension, 77–78 object(s) arrays of, 627–629 class scope and, 609 declaration, 606–607 described, 602 identifying, 709–710 overview, 606 programs, 10–11 object-oriented design See OOD (object-oriented design) object-oriented programming, See OOP (objectoriented programming) octal number system, 1490–1492 one-dimensional arrays, 487, 491–494, 498, 519, 527 See also arrays OOD (object-oriented design) See also objects basic principles, 708 described, 20 overview, 20–22, 602, 707–731 OOP (object-oriented programming) See also objects described, 21 languages, in existence today, 709 overview, 707–731 operands, 40 1569 operating system software, operations, identifying, 709–710 operator(s) See also operator overloading; specific operators arithmetic operators, 39, 40, 41–44 described, 631 precedence, 43–44, 85, 184–187, 1479–1480 operator function(s) described, 829 as nonmember functions, 839–848 syntax, 830 operator overloading array index operator and, 882–890 assignment operator and, 853–861 binary operators and, 842–848 described, 829 linked lists and, 1017 member versus nonmember, 867–868 need for, 828–829 overview, 829–882 stacks and, 1097–1098, 1115–1117 table, 1485 unary operators and, 861–867 ordered lists, 807–809, 1005–1006, 1011–1012, 1026–1037 See also lists orderedArrayListType class, 800, 807–809, 896, 1193–1194 orderedLinkedList class, 1005–1006, 1011–1012, 1026–1037 origin, of edges, 1323 ostream class, 697, 721 ostream iterators, 1376–1378, 1402, 1423 ostream_iterator class, 1396 out_of_range class, 932 output See also input/output (I/O) devices, formatting, 137–148 iterators, 1391 overview, 67–74, 117–174 statements, 68 stream variables, 119 streams, 118 string, 515–516 overflow condition, 126, 1094 overflow_error class, 932 P palindrome number program, 338–340 parallel arrays, 537, 538 See also arrays parameter(s) actual, 326 arrays as, 497–498 1570 | Index parameter(s) (Continued) binary trees and, 1283, 1301–1304 classes and, 610–611, 622, 623–626 constructors with, invoking, 623–625 default, 396–399, 626 exception handling and, 939, 942–945 formal, 325–326, 498–500 passing, to functions, 527–530 queues and, 1155 recursion and, 967 reference, 363, 372–382 sorting algorithms and, 1230 structS and, 573–574 value, 363, 372–382, 784 parameterized stream manipulators, 148 parameterized types, 893 See also class templates parent, use of the term, 1266, 1269 parentheses, 187, 327, 1301 partial_sum function, 1463–1468 partition function, 1223, 1224 partTimeEmployee class, 676, 692–693, 694, 789, 793–795 Pascal, Blaise, patches, 296–299 path binary trees and, 1269 described, 1217 length of, 1270 simple, 1325–1326 weight of, 1337 PCs (personal computers), history of, See also computers peek function, 130–132 period (.), 129, 566, 567, 607 personalInfo class, 703, 705–707 personType class, 641–642, 676, 692–695, 702–703, 789, 833–836, 1236–1237, 1239–1240, 1243 petType class, 780–781, 783, 784–787 pig-latin strings, 471–475 pivot, 1218, 1219–1225 plus sign (+), 606 pointer variables dangling, 759 declaring, 746–747 described, 746 functions and, 764 initializing, 755 operations on, 759–761 operator overloading and, 868 overview, 746–759 pointers See also pointer variables deep copy and, 768–770 functions and, 764 peculiarities of, 770–780 return types of functions as, 764 shallow copy and, 768–770 Poisson distributions, 1167 polymorphism described, 708 parametric, 709 poolCapacity function, 394 poolFillTime function, 394 pop function, 1085, 1086, 1110, 1112–1114, 1094–1096, 1403–1405 pop_back function, 1367, 1374 pop_front function, 1380, 1382, 1385 postconditions, 635 postfix Expressions calculator, 1119–1129 post-increment operator, 863–867 postorder sequence, 1273, 1274–1276 postorder traversal, nonrecursive, 1300–1301 posttest loops, 286 pound sign (#), 145, 257, 606, 843, 847, 1122 pow function, 321–326, 456 pre-increment operator, 862–863 precision described, 39 double, 39 single, 39 preconditions, 635 predefined functions described, 125 overview, 31 using, 124–133 predicates, 1416 prefix (Polish) notation, 1119 preorder sequence, 1273 preorder traversal, nonrecursive, 1299–1300 preprocessors, 10, 75–76 See also #include preprocessor directive pretest loops, 286 Prim’s algorithm, 1347–1348, 1352–1354 print function, 684, 701, 714, 720–721, 767, 781–783, 801, 852, 897, 1013, 1044 printDataTotalVotes function, 1242 printGradeReports function, 725–726 printGraph function, 1332 printListReverse function, 1039–1040 printMatrix function, 528–529 printReport function, 587–588 printResult function, 453, 454, 457, 1126–1129 printShortestDistance function, 1344 printStars function, 364–366 printTime function, 605, 616 printTreeAndWeight function, 1354–1355 Index | private keyword, 603 private members, 606–606, 619–621, 1090, 1164 friend functions and, 836, 837–839 inheritance and, 677–679, 685–686, 698–699 linked lists and, 1006, 1011, 1012 overview, 603 sorting algorithms and, 1232 structS and, 633 problem analysis-coding-execution cycle, 12–20 processVotes function, 1250 program(s) See also programming; programming languages basic elements of, 28–34 creating, overview of, 77–80 described, 28 driver, 392, 393–394 form, 84–89, 211–212 overview, processing, overview of, 10–12 source, 10 style, 84–89, 211–212 terminating, 223–231, 946, 948 programming See also programs described, 28 methodologies, 20–22 structured, 20 programming languages See also programming described, 31 evolution of, 8–9 overview, 1–26 structured, 20 prompt lines, 86 protected keyword, 603 protected members, 606, 1011, 1012 friend functions and, 836 inheritance and, 698–702 overview, 603 prototypes, 331, 332–333, 397, 398 pseudocode described, 212 overview, 212–215 ptrMemberVarType class, 770, 771, 772–780 public keyword, 603, 604–606 public members, 606, 619–621, 633, 1369 friend functions and, 836 overview, 603 inheritance and, 677–679, 683–684, 686, 698–699 push function, 1085, 1086, 1110–1112, 1092–1094, 1403–1405 push_back function, 1367, 1368, 1374, 1382 push_front function, 1380, 1385 1571 Q queue(s) See also queuing systems application of, 1151–1171 described, 1133 empty, 1142, 1146–1147 full, 1142, 1146–1147 implementation of, as arrays, 1136–1145 initializing, 1142, 1147 linked implementation of, 1145–1151 operations, 1134–1135 overview, 1133–1151 STL and, 1405, 1407 queueADT class, 1135–1136, 1140, 1145–1147 queueType class, 1164 queuing systems See also queues described, 1152 designing, 1151–1153 quick sort algorithms, 1218–1225 quickSort function, 1224 R RAM (random access memory), 4, See also memory RAND_MAX constant, 1520 random file access, 1498–1506 random number generators, 1519–1520 random_shuffle function, 1448–1452 raw data, 1492 rbegin function, 1373, 1376 rear, of queues, 1133–1134 Rebuild command, 12, 638 recMergeSort function, 1231–1233 records See structS rectangle class, 677, 789 rectangleType class, 680–690, 840–868 recursion described, 960 direct, 963 graphs and, 1334 indirect, 963 infinite, 963–964 iteration and, 974–984 linked lists and, 1037–1039 overview, 959–989 problem solving with, 964–974 removing, 1129–1133 sorting algorithms and, 1234 recursive algorithms, 961, 964–974 recursive definitions, 960, 961–964 recursive functions described, 961, 962–963 designing, 963–964 1572 | Index recursive functions (Continued) iteration and, 974–975 tail, 963 reference variables, as parameters, 368–372 relational operators, 201–203, 437–438 described, 178 overview, 177–182 structS and, 569–570 remove function, 805, 899, 1427, 1385 removeAt function, 801, 805, 897 remove_copy function, 1427 remove_copy_if function, 1427 remove_if function, 1385, 1427 repetition structures See also loops need for, 248–249 overview, 176–177, 247–318 replace function, 463, 467–468, 1430–1434 replaceAt function, 805–806, 899 replace_copy function, 1430–1434 replace_copy_if function, 1430–1434 replace_if function, 1430–1434 reserved words See keywords resize function, 1367, 1368, 1374 retrieveAt function, 802, 897 return keyword, 77, 328 return statement, 208, 324, 327–331, 333–335 return type, of functions, 326 reverse function, 1387, 1445–1448 Reverse Polish notation, 1119 reverse_copy function, 1445–1448 reversePrint function, 1037–1039 rFibNum function, 967–971 right child, 1266 right manipulator, 146–148 right subtree, 1266 rightmost bit, 979 ‘‘rock, paper, and scissors’’ game, 444–452 rollDice function, 639–640 root, use of the term, 1269 root node, 1217, 1286 rooted tree, 1346 rotate function, 1445–1448 rotate_copy function, 1445–1448 row(s) arrays and, 523, 525 largest element in, 526 order form, 527 processing, 523 sum by, 525 runSimulation function, 1167, 1168 run-time (late/dynamic) binding, 782, 788 run-together words, 86 S saleByQuarter function, 586 sales data analysis example, 580–593 scope resolution operator, 386, 454, 457, 611–615, 683 search algorithms Big-O notation and, 1194–1202 comparison-based, 1202 overview, 1184–1194 search function, 1018–1019, 1045, 1280, 1288–1289, 1437–1440 searching See also search algorithms; search function arrays, for specific items, 507–510 comparison-based, 1202 linked lists, 1018–1019, 1027–1028, 1045 sequential, 507, 508–510, 573–574, 1185–1187 search_n function, 1437–1440 searchVideoList function, 1309 secondary storage, seekg function, 1498, 1499–1503 seekp function, 1499–1500, 1503 selection structures multiple, 195–199 one-way, 189–191 overview, 176–177, 188–212 two-way, 191–194 selection sort algorithms, 1208–1212 selectors, 215 sellProduct function, 654–655 semantic(s) described, 85 errors, 194 rules, 31 semicolon (;), 85 sentinel(s), 257, 259 -controlled while loops, 255, 256 described, 255 seqSearch function, 508–509, 573, 574, 805, 899 sequence containers, 1363–1372 sequence structures, 176–177 sequential search algorithm, 507, 508–510, 573–574, 1185–1187 server(s) lists, 1159–1163 queues and, 1152, 1156–1163 serverListType class, 1160–1161 serverType class, 1156–1158 set container, 1397–1399, 1407 setCustomerInfo function, 1155–1156 Index | setData function, 701, 704–705 set_difference function, 1455–1463 setDimension function, 684, 685 setfill manipulator, 144–146 setFirstName function, 834–835 setInfo function, 718 set_intersection function, 1455–1463 setLastName function, 834–835 setName function, 1238 setprecision manipulator, 137–138, 140–141 sets described, 807 ordered, 809 unordered, 807 setServerBusy function, 1162 setSimulationParameters function, 1166 set_symmetric_difference function, 1455–1463 setTime function, 604, 605, 608, 611–612, 616, 621, 622 set_union function, 1455–1463 setw manipulator, 142–144, 146 setX function, 755 shallow copy, 768, 769, 770 shape class, 677, 678, 787–789 short-circuit evaluation, 199, 200 shortest path, 1337 shortest path algorithm, 1337, 1338–1345 shortestPath function, 1343, 1344 showpoint manipulator, 139–142 showSelection function, 654 side effects, 386–390 simple data types, 53, 433–483, 486 simple graphs, 1325 See also graphs simulation example, 1151–1171 time-driven, 1152 single inheritance, 677 See also inheritance size function, 463, 1372, 1403–1405 slicing problem, 786 software See also programs operating system, overview of, sort algorithms, 1202–1208, 1216–1217 sort function, 1207, 1386, 1437–1440 sortCourses function, 718, 722 source code, 10, 77 file, 77 program, 10 use of the term, 1337 spanning tree, 1347 splice function, 1386, 1389–1390 sqrt function, 321, 322 1573 square brackets ([]), 495 squareFirst function, 381 stack(s) application of, 1119–1229 copying, 1114–1115 described, 1084 empty, 1092, 1109–1110 header files and, 1098–1102 implementation of, as arrays, 1088–1102 initializing, 1081–1082, 1110 linked implementation of, 1106–1119 overview, 1084–1087 STL and, 1403–1404, 1407 unwinding, 948–951 stack class, 1403–1404 stackADT class, 1107–1108, 1086–1088 stackType class, 1088–1091, 1097–1098, 1101 Standard C++ See also ANSI/ISO Standard C++ library, 458 naming conventions, 1506–1507 statement(s) action, 189 declaration, 78 executable, 78 nested, 195, 196, 197–199, 280 terminators, 85 static binding See compile-time binding static keyword, 491, 643 static members, 643–648 std:: prefix, 455 stepwise refinement, 20 STL (C++ Standard Template Library) See also templates algorithms and, 1407–1468 components of, 1362–1390 overview, 1361–1475 strcmp function, 512, 513 stream(s) classes, 696–697 described, 118 extraction operator, 59 functions, 124 insertion operator, 31, 68, 848–853 iterators, 1396 variables, 119, 373 string(s) See also string data type arrays of, 530–531 comparison, 512–513 described, 49 exception handling and, 942 output, 515–516 pig-latin, 471–475 reading, 60–61, 513 1574 | Index string(s) (Continued) templates and, 891, 893 writing, 513 string data type, 49–50, 76, 148–152, 180–182 See also strings functions, list of, 462–463 overview, 458–470 string.h (cstring) header file, 470, 512, 516, 517, 1506, 1515–1517 strlen function, 512 strongly connected, use of the term, 1326 struct(S) arrays and, 571–576 classes versus, 632–633 comparison operators and, 569–570 described, 564 input/output and, 570–571 members, accessing, 566–568 overview, 563–600 pointer variables and, 752–753 seekg function and, 1500–1503 structS within, 576–579 struct keyword, 565 structured data types, 486 structured design, 20 structured programming, 20 structures See also specific types choosing the right, 289 switch, 215, 216–223 testing, 212–215 studentType class, 717–718 subgraphs, 1323 subsets, 1323 substr function, 463, 469–470 sumRows function, 528–529 swap function, 463, 470, 1210–1211, 1223, 1373, 1434 switch statement, 439–440 switch structures, 215, 216–223 syntax errors, 80–84, 133, 396 See also debugging; errors; syntax rules control structures and, 215 fixing, 80–84 syntax rules, 31, 84–85 See also syntax errors system programs, T tabs, 120 tail recursive functions, 963 target, 1187 telephone-digit program, 257–259 template keyword, 891 templates See also STL (C++ Standard Template Library) array-based lists and, 896–902 class, 891, 893–895 function, 891, 892–893 overview, 891–902 terminate function, 948 ternary operators, 211 testing, of control structures, 212–215 testTime function, 610–611 text processing program, 540–547 this keyword, 831 this pointer, 831–836, 861 throw keyword, 926 throw statements, 925–926, 932, 941–945 tilde ($), 629 tokens, 32–33, 34 tolower function, 322 top, of stacks, 116, 1084, 1094, 1112 top function, 1085, 1086, 1403–1404 top-down design, 20 totalSaleByPerson function, 586–587 toupper function, 322, 323, 1454 Tower of Hanoi problem, 971–974 transaction time, 1152 transform function, 1452–1454 traversal binary tree, 1272–1276, 1297–1304 breadth-first (level-by-level), 1276, 1335, 1336–1337 depth first, 1333, 1334–1335 graph, 1333–1337 inorder, 1297–1299 postorder traversal, 1300–1301 preorder, 1299–1300 try/catch blocks, 924–931, 941–945, 947, 948, 950–951 two-dimensional arrays See also arrays accessing components of, 530 declaration of, 521, 531–532 described, 519 dynamic, 765–767 enumeration types and, 521–524 initialization of, 521, 524–525 overview, 518–533 passing, as parameters to functions, 527–530 printing, 525 processing, 523 type conversion, 47, 48–49 name, 631 typedef iterators, 1394–1395 typedef statement, 443 Index | U UML (Unified Modeling Language) See also class diagrams binary trees and, 1280 described, 606 unary operators, 40, 861–867 underflow condition, 1096 underscore (_), 33, 34, 86, 453 undirected graph, 1323 Unicode, union, of sets, 1323 unique function, 1385 UNIX, 265 unordered lists, 803–807, 896, 899, 900–902, 1005–1006, 1011, 1017–1026, 1232, 1329 unorderedArrayListType class, 800, 803–807, 896, 899, 900–902, 1207–1208 unorderedLinkedList class, 1005–1006, 1011, 1017–1026, 1232, 1329 updateServers function, 1163 updateVotesByRegion function, 1242 user-defined functions, 324 using keyword, 76, 454 using statement, 454–455, 456 V value parameters, 367–368 value-returning function(s) calls, 326 described, 324 overview, 324–343 return statements and, 327–331 variable(s) automatic, 391, 392 declaring, 57–58, 442 described, 52 enumeration types and, 436 external, 386 functions and, 372–382 global, 386–390, 391 initialized, 53, 57–58, 61–65 input/output and, 1493–1495, 1501 instance, 615 local, 372 loop control (LCVs), 250, 251, 256, 274 1575 memory allocation and, 50–53 operator overloading and, 868 putting data into, 53–56 static, 391, 392 structS and, 565–569, 570–571, 578–579 vector class, 1363–1367 vector containers, 1363–1372, 1407 vector objects, declaring, 1364–1368 vertices connected, 1325 described, 1323 drawing, 1324 video store example, 1052–1071, 1305–1314 videoBinaryTree class, 1309–1310 videoListType class, 1308–1309 videoType class, 1307–1308 virtual functions, 780–781, 782, 783–795 virtual keyword, 783 Visual C++ 2008 Express (Microsoft), 638 Visual Studio NET (Microsoft), 638 void functions, 324, 362–366 W waitingCustomerQueueType class, 1164 walk-throughs, 56, 65, 214, 292 weighted graphs, 1337, 1338–1339 See also graphics weighted tree, 1346 weightedGraphType class, 1338–1339 what function, 931–932 while loops, 1131–1133, 1186, 1189, 1192–1193, 1195 counter-controlled, 252, 253–255 described, 249 designing, 251–252 EOF-controlled, 263, 264–268, 294–295 expressions in, 268–269 Fibonacci numbers and, 269, 270–273 flag-controlled, 259, 260, 268 functions and, 366 nested, 293 overview, 249–284 sentinel-controlled, 255, 256 whitespace, 34, 120, 129, 149 Wozniak, Stephen, write function, 1498 ... 340 Programming Example: Largest Number 341 Programming Example: Cable Company 343 Quick Review 349 Exercises 350 Programming Exercises 356 ix x | C++ Programming: Program Design Including Data. .. Objects, and Operations 709 Programming Example: Grade Report 710 Quick Review 731 Exercises 732 Programming Exercises 739 xiv | C++ Programming: Program Design Including Data Structures, Fifth Edition... Analysis: Merge Sort 1232 Programming Example: Election Results 1235 Quick Review 1256 Exercises 1257 Programming Exercises 1260 xx | C++ Programming: Program Design Including Data Structures, Fifth

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

Từ khóa liên quan

Mục lục

  • Cover

  • Title Page

  • Copyright

  • TABLE OF CONTENTS

  • Preface

  • 1 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 and Main Memory

      • Input /Output Devices

      • Software

      • The Language of a Computer

      • The Evolution of Programming Languages

      • Processing a C++ Program

      • Programming with the Problem Analysis–Coding–Execution Cycle

      • Programming Methodologies

        • Structured Programming

        • Object-Oriented Programming

        • ANSI/ISO Standard C++

        • Quick Review

        • Exercises

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

Tài liệu liên quan