Previous Next

Starting out with C++. Early objects (Gaddis, Tony,Walters, Judy,Muganda, Godfrey) (z-library.sk, 1lib.sk, z-lib.sk)

Author: Gaddis, Tony, Walters, Judy, Muganda, Godfrey

C/C++/C#

For courses in C++ Programming. Fundamentals of C++ for Novices and Experienced Programmers Alike Intended for use in a two-term, three-term, or accelerated one-term C++ programming sequence, thisNinth EditionofStarting Out with C++: Early Objectsintroduces the fundamentals of C++ to novices and experienced programmers alike. In clear, easy-to-understand terms, the text introduces all of the necessary topics for beginning C++ programmers. Real-world examples allow readers to apply their knowledge in understanding how, why, and when to implement the features of C++. The text is organized in a progressive, step-by-step fashion that allows for flexibility. Building on the popularity of previous editions, theNinth Editionhas been updated and enhanced with new material, including C++11 topics and recent changes in technology.

📄 File Format: PDF
💾 File Size: 11.5 MB
6
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
GlobAl edITIon Starting out With C++ Early Objects nInTH edITIon Tony Gaddis • Judy Walters • Godfrey Muganda
📄 Page 2
LOCATION OF VIDEONOTES IN THE TEXT Chapter 1 Designing a Program with Pseudocode, p. 54 Designing the Account Balance Program, p. 59 Predicting the Output of Problem 30, p. 59 Solving the Candy Bar Sales Problem, p. 60 Chapter 2 Using cout to Display Output, p. 66 Assignment Statements, p. 93 Arithmetic Operators, p. 96 Solving the Restaurant Bill Problem, p. 108 Chapter 3 Using cin to Read Input, p. 111 Evaluating Mathematical Expressions, p. 118 Combined Assignment Operators, p. 136 Solving the Stadium Seating Problem, p. 182 Chapter 4 Using an if Statement, p. 195 Using an if/else Statement, p. 204 Using an if/else if Statement, p. 210 Using Logical Operators, p. 223 Solving the Time Calculator Problem, p. 272 Chapter 5 The while Loop, p. 278 The for Loop, p. 305 Nested Loops, p. 313 Solving the Ocean Levels Problem, p. 351 Chapter 6 Defining and Calling Functions, p. 358 Using Function Arguments, p. 367 Value-Returning Functions, p. 377 Solving the Markup Problem, p. 433 Chapter 7 Creating a Class, p. 446 Creating and Using Class Objects, p. 448 Creating and Using Structures, p. 488 Solving the Car Class Problem, p. 534 Chapter 8 Accessing Array Elements, p. 543 Passing an Array to a Function, p. 577 Two-Dimensional Arrays, p. 587 Solving the Chips and Salsa Problem, p. 627 Chapter 9 Performing a Binary Search, p. 640 Sorting a Set of Data, p. 647 Solving the Lottery Winners Problem, p. 675 (continued on next page) VideoNote
📄 Page 3
LOCATION OF VIDEONOTES IN THE TEXT (continued) Chapter 10 Pointer Variables, p. 681 Dynamically Allocating an Array, p. 705 Solving the Days in Current Month Problem, p. 736 Chapter 11 Operator Overloading, p. 764 Aggregation and Composition, p. 810 Overriding Base Class Functions, p. 831 Solving the Number of Days Worked Problem, p. 845 Chapter 12 Converting Strings to Numbers, p. 863 Writing a C-String Handling Function, p. 867 Solving the Case Manipulator Problem, p. 884 Chapter 13 The get Family of Member Functions, p. 903 Rewinding a File, p. 907 Solving the File Encryption Filter Problem, p. 946 Chapter 14 Recursive Binary Search, p. 961 QuickSort, p. 963 Solving the Recursive Multiplication Problem, p. 981 Chapter 15 Polymorphism, p. 989 Composition versus Inheritance, p. 1003 Solving the Sequence Sum Problem, p. 1019 Chapter 16 Throwing and Handling Exceptions, p. 1022 Writing a Function Template, p. 1034 Iterators, p. 1051 Solving the Arithmetic Exceptions Problem, p. 1068 Chapter 17 Adding an Element to a Linked List, p. 1079 Removing an Element from a Linked List, p. 1086 Solving the Member Insertion by Position Problem, p. 1117 Chapter 18 Storing Objects in an STL Stack, p. 1131 Storing Objects in an STL Queue, p. 1145 Solving the File Reverser Problem, p. 1157 Chapter 19 Inserting an Element into a Binary Tree, p. 1166 Removing an Element from a Binary Tree, p. 1170 Solving the Tree Size Problem, p. 1186 VideoNote
📄 Page 4
Ninth Edition Starting Out with C++ Early Objects Tony Gaddis Judy Walters Godfrey Muganda Global Edition Boston Columbus Indianapolis New York San Francisco Hoboken Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo
📄 Page 5
Vice President, Editorial Director, ECS: Marcia Horton Acquisitions Editor: Matt Goldstein Editorial Assistant: Kristy Alaura Acquisitions Editor, Global Editions: Aditee Agarwal Vice President of Marketing: Christy Lesko Director of Field Marketing: Tim Galligan Product Marketing Manager: Bram Van Kempen Field Marketing Manager: Demetrius Hall Marketing Assistant: Jon Bryant Director of Product Management: Erin Gregg Team Lead, Program and Project Management: Scott Disanno Program Manager: Carole Snyder Project Editor, Global Editions: K.K. Neelakantan Project Manager: RPK Editorial Services, Inc. Senior Specialist, Program Planning and Support: Maura Zaldivar-Garcia Senior Manufacturing Controller, Global Editions: Jerry Kataria Cover Designer: Lumina Datamatics Cover: Shutterstock Manager, Rights and Permissions: Rachel Youdelman Project Manager, Rights and Permissions: William Opaluch Inventory Manager: Meredith Maresca Media Project Manager: Renata Butera Media Production Manager, Global Editions: Vikram Kumar Full-Service Project Management: Deepthi Mohan, iEnergizer Aptara®, Ltd. Composition: Aptara® Corporation Microsoft and/or its respective suppliers make no representations about the suitability of the information contained in the documents and related graphics published as part of the services for any purpose. All such documents and related graphics are provided “as is” without warranty of any kind. Microsoft and/or its respective suppliers hereby disclaim all warranties and conditions with regard to this information, including all warranties and conditions of merchantability, whether express, implied or statutory, fitness for a particular purpose, title and non-infringement. In no event shall Microsoft and/or its respective suppliers be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of information available from the services. The documents and related graphics contained herein could include technical inaccuracies or typographical errors. Changes are periodically added to the information herein. Microsoft and/or its respective suppliers may make improvements and/or changes in the product(s) and/or the program(s) described herein at any time. Partial screen shots may be viewed in full within the software version specified. Microsoft® Windows®, and Microsoft Office® are registered trademarks of the Microsoft corporation in the U.S.A. and other countries. This book is not sponsored or endorsed by or affiliated with the Microsoft corporation. The programs and applications presented in this book have been included for their instructional value. They have been tested with care, but are not guaranteed for any particular purpose. The publisher does not offer any warranties or representations, nor does it accept any liabilities with respect to the programs or applications. Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world Visit us on the World Wide Web at: www.pearsonglobaleditions.com © Pearson Education Limited 2016 The rights of Tony Gaddis, Judy Walters, and Godfrey Muganda to be identified as the authors of this work have been as- serted by them in accordance with the Copyright, Designs and Patents Act 1988. Authorized adaptation from the United States edition, entitled Starting Out with C++: Early Objects, 9th Edition, ISBN 9780134400242, by Tony Gaddis, Judy Walters, and Godfrey Muganda published by Pearson Education © 2017. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without either the prior written permission of the publisher or a license permitting restricted copying in the United Kingdom issued by the Copyright Licensing Agency Ltd, Saffron House, 6–10 Kirby Street, London EC1N 8TS. All trademarks used herein are the property of their respective owners. The use of any trademark in this text does not vest in the author or publisher any trademark ownership rights in such trademarks, nor does the use of such trademarks imply any affiliation with or endorsement of this book by such owners. British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library 10 9 8 7 6 5 4 3 2 1 ISBN 10: 1292157275 ISBN 13: 9781292157276 Typeset in 10/12.5 Sabon LT Pro by iEnergizer Aptara®, Ltd. Printed and bound in Malaysia
📄 Page 6
Last A-Head 5 Contents at a Glance Preface 15 Chapter 1 Introduction to Computers and Programming 35 Chapter 2 Introduction to C++ 61 Chapter 3 Expressions and Interactivity 111 Chapter 4 Making Decisions 189 Chapter 5 Looping 277 Chapter 6 Functions 357 Chapter 7 Introduction to Classes and Objects 441 Chapter 8 Arrays 541 Chapter 9 Searching, Sorting, and Algorithm Analysis 637 Chapter 10 Pointers 679 Chapter 11 More about Classes and Object-Oriented Programming 737 Chapter 12 More on C-Strings and the string Class 849 Chapter 13 Advanced File and I/O Operations 887 Chapter 14 Recursion 949 Chapter 15 Polymorphism and Virtual Functions 983 Chapter 16 Exceptions, Templates, and the Standard Template Library (STL) 1021 Chapter 17 Linked Lists 1071 Chapter 18 Stacks and Queues 1119 Chapter 19 Binary Trees 1159 Appendix A: The ASCII Character Set 1189 Appendix B: Operator Precedence and Associativity 1193 Appendix C: Answers to Checkpoints 1195 Appendix D: Answers to Odd-Numbered Review Questions 1235 Index 1255 5
📄 Page 7
This page intentionally left blank
📄 Page 8
Contents Preface 15 CHAPTER 1 Introduction to Computers and Programming 35 1.1 Why Program? 35 1.2 Computer Systems: Hardware and Software 37 1.3 Programs and Programming Languages 42 1.4 What Is a Program Made of? 47 1.5 Input, Processing, and Output 51 1.6 The Programming Process 52 1.7 Tying It All Together: Hi! It’s Me 57 CHAPTER 2 Introduction to C++ 61 2.1 The Parts of a C++ Program 61 2.2 The cout Object 65 2.3 The #include Directive 70 2.4 Variables and the Assignment Statement 71 2.5 Literals 73 2.6 Identifiers 75 2.7 Integer Data Types 77 2.8 Floating-Point Data Types 82 2.9 The char Data Type 86 2.10 The C++ string Class 90 2.11 The bool Data Type 91 2.12 Determining the Size of a Data Type 92 2.13 More on Variable Assignments and Initialization 93 2.14 Scope 95 2.15 Arithmetic Operators 96 2.16 Comments 100 2.17 Programming Style 101 2.18 Tying It All Together: Smile! 103 7
📄 Page 9
8 Contents CHAPTER 3 Expressions and Interactivity 111 3.1 The cin Object 111 3.2 Mathematical Expressions 118 3.3 Data Type Conversion and Type Casting 126 3.4 Overflow and Underflow 132 3.5 Named Constants 133 3.6 Multiple and Combined Assignment 136 3.7 Formatting Output 140 3.8 Working with Characters and Strings 150 3.9 More Mathematical Library Functions 164 3.10 Random Numbers 166 3.11 Focus on Debugging: Hand Tracing a Program 170 3.12 Green Fields Landscaping Case Study—Part 1 172 3.13 Tying It All Together: Word Game 175 CHAPTER 4 Making Decisions 189 4.1 Relational Operators 189 4.2 The if Statement 195 4.3 The if/else Statement 204 4.4 The if/else if Statement 209 4.5 Menu-Driven Programs 217 4.6 Nested if Statements 219 4.7 Logical Operators 223 4.8 Validating User Input 232 4.9 More about Blocks and Scope 234 4.10 More about Characters and Strings 237 4.11 The Conditional Operator 243 4.12 The switch Statement 247 4.13 Enumerated Data Types 256 4.14 Focus on Testing and Debugging: Validating Output Results 259 4.15 Green Fields Landscaping Case Study—Part 2 261 4.16 Tying It All Together: Fortune Teller 266 CHAPTER 5 Looping 277 5.1 Introduction to Loops: The while Loop 277 5.2 Using the while Loop for Input Validation 284 5.3 The Increment and Decrement Operators 287 5.4 Counters 292 5.5 Keeping a Running Total 294 5.6 Sentinels 297 5.7 The do-while Loop 299
📄 Page 10
Contents 9 5.8 The for Loop 305 5.9 Focus on Software Engineering: Deciding Which Loop to Use 311 5.10 Nested Loops 313 5.11 Breaking Out of a Loop 315 5.12 Using Files for Data Storage 319 5.13 Focus on Testing and Debugging: Creating Good Test Data 335 5.14 Central Mountain Credit Union Case Study 338 5.15 Tying It All Together: What a Colorful World 342 CHAPTER 6 Functions 357 6.1 Modular Programming 357 6.2 Defining and Calling Functions 358 6.3 Function Prototypes 366 6.4 Sending Data into a Function 367 6.5 Passing Data by Value 372 6.6 The return Statement 376 6.7 Returning a Value from a Function 377 6.8 Returning a Boolean Value 383 6.9 Using Functions in a Menu-Driven Program 385 6.10 Local and Global Variables 389 6.11 Static Local Variables 396 6.12 Default Arguments 398 6.13 Using Reference Variables as Parameters 402 6.14 Overloading Functions 412 6.15 The exit() Function 416 6.16 Stubs and Drivers 419 6.17 Little Lotto Case Study 421 6.18 Tying It All Together: Glowing Jack-o-lantern 426 CHAPTER 7 Introduction to Classes and Objects 441 7.1 Abstract Data Types 441 7.2 Object-Oriented Programming 443 7.3 Introduction to Classes 445 7.4 Creating and Using Objects 448 7.5 Defining Member Functions 450 7.6 Constructors 457 7.7 Destructors 463 7.8 Private Member Functions 466 7.9 Passing Objects to Functions 469 7.10 Object Composition 476 7.11 Focus on Software Engineering: Separating Class Specification, Implementation, and Client Code 480
📄 Page 11
10 Contents 7.12 Structures 487 7.13 More about Enumerated Data Types 499 7.14 Home Software Company OOP Case Study 503 7.15 Introduction to Object-Oriented Analysis and Design 510 7.16 Screen Control 520 7.17 Tying It All Together: Yoyo Animation 525 CHAPTER 8 Arrays 541 8.1 Arrays Hold Multiple Values 541 8.2 Accessing Array Elements 543 8.3 Inputting and Displaying Array Data 545 8.4 Array Initialization 552 8.5 The Range-Based for loop 559 8.6 Processing Array Contents 562 8.7 Using Parallel Arrays 573 8.8 The typedef Statement 577 8.9 Arrays as Function Arguments 577 8.10 Two-Dimensional Arrays 587 8.11 Arrays with Three or More Dimensions 594 8.12 Vectors 597 8.13 Arrays of Objects 609 8.14 National Commerce Bank Case Study 619 8.15 Tying It All Together: Rock, Paper, Scissors 621 CHAPTER 9 Searching, Sorting, and Algorithm Analysis 637 9.1 Introduction to Search Algorithms 637 9.2 Searching an Array of Objects 644 9.3 Introduction to Sorting Algorithms 647 9.4 Sorting an Array of Objects 655 9.5 Sorting and Searching Vectors 658 9.6 Introduction to Analysis of Algorithms 661 9.7 Case Studies 669 9.8 Tying It All Together: Secret Messages 669 CHAPTER 10 Pointers 679 10.1 Pointers and the Address Operator 679 10.2 Pointer Variables 681 10.3 The Relationship Between Arrays and Pointers 685
📄 Page 12
Contents 11 10.4 Pointer Arithmetic 689 10.5 Initializing Pointers 690 10.6 Comparing Pointers 693 10.7 Pointers as Function Parameters 695 10.8 Pointers to Constants and Constant Pointers 699 10.9 Focus on Software Engineering: Dynamic Memory Allocation 704 10.10 Focus on Software Engineering: Returning Pointers from Functions 708 10.11 Pointers to Class Objects and Structures 714 10.12 Focus on Software Engineering: Selecting Members of Objects 718 10.13 Smart Pointers 720 10.14 Tying It All Together: Pardon Me, Do You Have the Time? 728 CHAPTER 11 More about Classes and Object-Oriented Programming 737 11.1 The this Pointer and Constant Member Functions 737 11.2 Static Members 742 11.3 Friends of Classes 749 11.4 Memberwise Assignment 754 11.5 Copy Constructors 755 11.6 Operator Overloading 764 11.7 Rvalue References and Move Operations 785 11.8 Function Objects and Lambda Expressions 795 11.9 Type Conversion Operators 804 11.10 Convert Constructors 807 11.11 Aggregation and Composition 810 11.12 Inheritance 816 11.13 Protected Members and Class Access 821 11.14 Constructors, Destructors, and Inheritance 826 11.15 Overriding Base Class Functions 831 11.16 Tying It All Together: Putting Data on the World Wide Web 834 CHAPTER 12 More on C-Strings and the string Class 849 12.1 C-Strings 849 12.2 Library Functions for Working with C-Strings 854 12.3 Conversions Between Numbers and Strings 863 12.4 Writing Your Own C-String Handling Functions 867 12.5 More about the C++ string Class 873 12.6 Advanced Software Enterprises Case Study 876 12.7 Tying It All Together: Program Execution Environments 878
📄 Page 13
CHAPTER 13 Advanced File and I/O Operations 887 13.1 Input and Output Streams 887 13.2 More Detailed Error Testing 895 13.3 Member Functions for Reading and Writing Files 899 13.4 Binary Files 911 13.5 Creating Records with Structures 915 13.6 Random-Access Files 920 13.7 Opening a File for Both Input and Output 927 13.8 Online Friendship Connections Case Study: Object Serialization 932 13.9 Tying It All Together: File Merging and Color-Coded HTML 937 CHAPTER 14 Recursion 949 14.1 Introduction to Recursion 949 14.2 The Recursive Factorial Function 956 14.3 The Recursive gcd Function 958 14.4 Solving Recursively Defined Problems 959 14.5 A Recursive Binary Search Function 961 14.6 Focus on Problem Solving and Program Design: The QuickSort Algorithm 963 14.7 The Towers of Hanoi 967 14.8 Focus on Problem Solving: Exhaustive and Enumeration Algorithms 970 14.9 Focus on Software Engineering: Recursion versus Iteration 974 14.10 Tying It All Together: Infix and Prefix Expressions 975 CHAPTER 15 Polymorphism and Virtual Functions 983 15.1 Type Compatibility in Inheritance Hierarchies 983 15.2 Polymorphism and Virtual Member Functions 989 15.3 Abstract Base Classes and Pure Virtual Functions 997 15.4 Focus on Object-Oriented Programming: Composition versus Inheritance 1003 15.5 Secure Encryption Systems, Inc., Case Study 1007 15.6 Tying It All Together: Let’s Move It 1010 CHAPTER 16 Exceptions, Templates, and the Standard Template Library (STL) 1021 16.1 Exceptions 1021 16.2 Function Templates 1033 16.3 Class Templates 1041 16.4 Class Templates and Inheritance 1046 16.5 Introduction to the Standard Template Library 1050 16.6 Tying It All Together: Word Transformers Game 1063 12 Contents
📄 Page 14
CHAPTER 17 Linked Lists 1071 17.1 Introduction to the Linked List ADT 1071 17.2 Linked List Operations 1077 17.3 A Linked List Template 1089 17.4 Recursive Linked List Operations 1093 17.5 Variations of the Linked List 1101 17.6 The STL list Container 1102 17.7 Reliable Software Systems, Inc., Case Study 1105 17.8 Tying It All Together: More on Graphics and Animation 1108 CHAPTER 18 Stacks and Queues 1119 18.1 Introduction to the Stack ADT 1119 18.2 Dynamic Stacks 1127 18.3 The STL stack Container 1131 18.4 Introduction to the Queue ADT 1133 18.5 Dynamic Queues 1140 18.6 The STL deque and queue Containers 1143 18.7 Focus on Problem Solving and Program Design: Eliminating Recursion 1146 18.8 Tying It All Together: Converting Postfix Expressions to Infix 1151 CHAPTER 19 Binary Trees 1159 19.1 Definition and Applications of Binary Trees 1159 19.2 Binary Search Tree Operations 1163 19.3 Template Considerations for Binary Search Trees 1179 19.4 Tying It All Together: Genealogy Trees 1179 Appendix A: The ASCII Character Set 1189 Appendix B: Operator Precedence and Associativity 1193 Appendix C: Answers to Checkpoints 1195 Appendix D: Answers to Odd-Numbered Review Questions 1235 Index 1255 Contents 13
📄 Page 15
Additional Appendices The following appendices are located on the book’s companion web site. Appendix E: A Brief Introduction to Object-Oriented Programming Appendix F: Using UML in Class Design Appendix G: Multi-Source File Programs Appendix H: Multiple and Virtual Inheritance Appendix I: Header File and Library Function Reference Appendix J: Namespaces Appendix K: C++ Casts and Run-Time Type Identification Appendix L: Passing Command Line Arguments Appendix M: Binary Numbers and Bitwise Operations Appendix N: Introduction to Flowcharting 14 Contents
📄 Page 16
Preface Welcome to Starting Out with C++: Early Objects, 9th Edition. This book is intended for use in a two-term or three-term C++ programming sequence, or an accelerated one-term course. Students new to programming, as well as those with prior course work in other languages, will find this text beneficial. The fundamentals of programming are covered for the novice, while the details, pitfalls, and nuances of the C++ language are explored in-depth for both the beginner and more experienced student. The book is written with clear, easy-to-understand language and it covers all the necessary topics for an introductory programming course. This text is rich in example programs that are concise, practical, and real world oriented, ensuring that the student not only learns how to implement the features and constructs of C++, but why and when to use them. What’s New in the Ninth Edition The New C++11 Standard C++11 is the latest standard version of the C++ language. In previous years, while the standard was being developed, it was known as C++0x. In August 2011, it was approved by the International Standards Organization (ISO), and the name of the standard was officially changed to C++11. Most of the popular C++ compilers now support this standard. The new C++11 standard was the primary motivation behind this edition, which introduces many of the new language features. However, a C++11 compiler is not strictly required to use the book. As you progress through the book, you will see C++11 icons in the margins, next to the new features that are introduced. Programs appearing in sections that are not marked with this icon will still compile using an older compiler. The C++11 Topics Introduced in This Edition • The auto key word is introduced in Chapter 2 as a way to simplify complex variable definitions. This key word causes the compiler to infer a variable’s data type from its initialization value. 15
📄 Page 17
16 Preface • Chapter 2 also introduces the new long long int and unsigned long long int data types and the LL literal suffix. • Chapter 5 shows how to pass a string object directly to a file stream object’s open member function, without the need to call the c_str() member function. A discussion of the c_str()function still exists for anyone using a legacy compiler. • The range-based for loop is introduced in Chapter 7. This new looping mechanism automatically iterates over each element of an array, vector, or other collection, without the need for a counter variable or a subscript. • Chapter 7 also introduces strongly typed enums. • Chapter 8 introduces new ways to initialize variables and shows how a vector can now be initialized with an initialization list. • Chapter 10 introduces smart pointers and provides examples of how and why to use the new unique_ptr and shared_ptr pointers for safely allocating and working with dynamic memory. • Chapter 10 also introduces the move assignment operator, and the nullptr key word, which is now the standard way of representing a null pointer. • Chapter 11 discusses move constructors, provides more in depth coverage of move assignment operators, and introduces lambda expressions. • Chapter 12 introduces new functions in the C++11 string library and discusses the new overloaded to_string functions for converting numeric values to string objects. • Chapter 15 introduces and demonstrates the use of the new override key word that helps prevent subtle overriding errors and the new final key word that prevents a virtual member function from being overridden. • Chapter 16 introduces the new C++11 functions begin(c) and end(c) to specify positions within a collection c where an operation should begin and end. What Else is New This book’s pedagogy and clear writing style remain the same as in the previous edition. However, in addition to updating the book to introduce the new C++11 standard, many improvements have been made to make it even more student-friendly. • Updated Material Material has been updated throughout the book to reflect changes in technology and in software development environments, as well as to improve clarity and incorporate best practices in teaching introductory programming. As a result, new graphics and new or redesigned figures have been added throughout the book where appropriate and new or improved sample programs have been included in a number of chapters. • New Material New material has been added on a number of topics. In addition to introducing and using new C++11 features, this new edition includes new sections on literals, random numbers, and enumerated data types, as well as improved material on designing classes.
📄 Page 18
Preface 17 • New Programming Challenges New Programming Challenge problems have been added to every chapter. • Reorganized Chapters Several chapters have been redesigned to improve student learning. Chapter 5 (Looping) has been reorganized to give students more practice using the while loop before introducing do-while and for loops. The Chapter 6 (Functions) material on defining and calling functions has been reorganized to introduce function prototypes earlier and allow main to always be the first function in a client program. Organization of the Text This text teaches C++ in a step-by-step fashion. Each chapter covers a major set of topics and builds knowledge as the student progresses through the book. Although the chapters can be easily taught in their existing sequence, flexibility is provided. The following dependency diagram (Figure P-1) suggests possible sequences of instruction. Chapter 1 covers fundamental hardware, software, and programming concepts. The instructor may choose to skip this chapter if the class has already mastered those topics. Chapters 2 through 6 cover basic C++ syntax, data types, expressions, selection structures, repetition structures, and functions. Each of these chapters builds on the previous chapter and should be covered in the order presented. Chapter 7 introduces object-oriented programming. It can be covered any time after Chapter 6, but before Chapter 11. Instructors who prefer to introduce arrays before classes can cover Chapter 8 before Chapter 7. In this case it is only necessary to postpone Section 8.13 (Arrays of Objects) until Chapter 7 has been covered. As Figure P-1 illustrates, in the second half of the book Chapters 11, 12, 13, and 14 can be covered in any order. Chapters 11, 15, and 16, however, should be done in sequence. Instructors who wish to introduce data structures at an earlier point in the course, without having first covered advanced C++ and OOP features, can cover Chapter 17 (Linked Lists), followed by Chapters 18 and 19 (Stacks & Queues and Binary Trees), any time after Chapter 14 (Recursion). In this case it is necessary to simply omit the sections in Chapters 17–19 that deal with templates and the Standard Template Library.
📄 Page 19
18 Preface Chapter 1 Introduction Chapters 2–6 Basic Language Elements Chapter 10 Pointers Chapter 7 OOP Introduction Chapter 8 Arrays Chapter 11 More OOP Chapter 12 Advanced Strings Chapter 13 Advanced Files and I/O Chapter 14 Recursion Chapter 17 Linked Lists Chapter 15 Adv. OOP Chapter 16 Exceptions, Templates, and STL Chapter 18 Stacks and Queues Chapter 19 Binary Trees Chapter 9 Searching, Sorting, and Algorithm Analysis Figure P-1
📄 Page 20
Preface 19 Brief Overview of Each Chapter Chapter 1: Introduction to Computers and Programming This chapter provides an introduction to the field of computer science and covers the fundamentals of hardware, software, operating systems, programming, problem solving, and software engineering. The components of programs, such as key words, variables, operators, and punctuation are covered. The tools of the trade, such as hierarchy charts and pseudocode, are also presented. The Tying It All Together section shows students how to use the cout statement to create a personalized output message. Programming Challenges at the end of the chapter help students see how the same basic input, processing, and output structure can be used to create multiple programs. Chapter 2: Introduction to C++ This chapter gets the student started in C++ by introducing the basic parts of a C++ program, data types, the use of variables and literals, assignment statements, simple arithmetic operations, program output, and comments. The C++ string class is presented and string objects are used from this point on in the book as the primary method of handling strings. Programming style conventions are introduced, and good programming style is modeled here, as it is throughout the text. The Tying It All Together section lets the student play with simple text- based graphics. Chapter 3: Expressions and Interactivity In this chapter the student learns to write programs that input and handle numeric, character, and string data. The use of arithmetic operators and the creation of mathematical expressions are covered, with emphasis on operator precedence. Debugging is introduced, with a section on hand tracing a program. Sections are also included on using random numbers, on simple output formatting, on data type conversion and type casting, and on using library functions that work with numbers. The Tying It All Together section shows students how to create a simple interactive word game. Chapter 4: Making Decisions Here the student learns about relational expressions and how to control the flow of a program with if, if/else, and if/else if statements. Logical operators, the conditional operator, and the switch statement are also covered. Applications of these constructs, such as menu-driven programs, are illustrated. This chapter also introduces the concepts of blocks and scope and continues the theme of debugging with a section on validating output results. The Tying It All Together section uses random numbers and branching statements to create a fortune telling game.
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List