Problem Solving with C++ (9 PAP/PSC)

Problem Solving with C++ (9 PAP/PSC)

  • ただいまウェブストアではご注文を受け付けておりません。 ⇒古書を探す
  • 製本 Paperback:紙装版/ペーパーバック版/ページ数 1058 p.
  • 言語 ENG
  • 商品コード 9780133591743
  • DDC分類 005.133

Full Description


Notecome packaged with this content. If you would like to purchase both the physical text and MyProgrammingLab search for ISBN-10: 0133862216/ISBN-13: 9780133862218. That package includes ISBN-10: 0133591743/ISBN-13: 9780133591743 and ISBN-10: 0133834417 /ISBN-13: 9780133834413. MyProgrammingLab is not a self-paced technology and should only be purchased when required by an instructor.Problem Solving with C++ is intended for use in the C++ introductory programming course. Created for the beginner, it is also suitable for readers interested in learning the C++ programming language.Problem Solving with C++ continues to be the most widely used textbook by students and instructors in the introduction to programming and C++ language course. Through each edition, hundreds and thousands of students have valued Walt Savitch's approach to programming, which emphasizes active reading through the use of well-placed examples and self-test examples. Created for the beginner, this book focuses on cultivating strong problem-solving and programming techniques while introducing students to the C++ programming language.MyProgrammingLab for Problem Solving with C++ is a total learning package. MyProgrammingLab is an online homework, tutorial, and assessment program that truly engages students in learning. It helps students better prepare for class, quizzes, and exams-resulting in better performance in the course-and provides educators a dynamic set of tools for gauging individual and class progress. Teaching and Learning ExperienceThis program presents a better teaching and learning experience-for you and your students. Personalized Learning with MyProgrammingLab: Through the power of practice and immediate personalized feedback, MyProgrammingLab helps students fully grasp the logic, semantics, and syntax of programming.Keep Your Course Current: This edition features a new introduction to C++11 in the context of C++98.Flexible Coverage that Fits your Course: Instructors can easily adapt the order in which chapters and sections are covered in their course without losing continuity. Clear and Friendly Presentation: Savitch's clear, concise style is a hallmark feature of the text, receiving praise from students and instructors alike. Tried-and-true Pedagogy: A suite of pedagogical tools, enhanced by understandable language and code, has been used by hundreds of thousands of students and instructors.

Contents

Chapter 1 Introduction to Computers and C++ Programming 11.1 Computer Systems 2Hardware 2Software 7High-Level Languages 8Compilers 9History Note 121.2 Programming and Problem-Solving 12Algorithms 12Program Design 15Object-Oriented Programming 16The Software Life Cycle 171.3 Introduction to C++ 18Origins of the C++ Language 18A Sample C++ Program 19Pitfall: Using the Wrong Slash in \n 23Programming Tip: Input and Output Syntax 23Layout of a Simple C++ Program 24Pitfall: Putting a Space Before the include File Name 26Compiling and Running a C++ Program 26Pitfall: Compiling a C++11 program 27Programming Tip: Getting Your Program to Run 271.4 Testing and Debugging 29Kinds of Program Errors 30Pitfall: Assuming Your Program Is Correct 31Chapter Summary 32Answers to Self-Test Exercises 33Practice Programs 35Programming Projects 36Chapter 2 C++ Basics 392.1 Variables and Assignments 40Variables 40Names: Identifiers 42Variable Declarations 44Assignment Statements 45Pitfall: Uninitialized Variables 47Programming Tip: Use Meaningful Names 492.2 Input and Output 50Output Using cout 50Include Directives and Namespaces 52Escape Sequences 53Programming Tip: End Each Program with a \n or endl 55Formatting for Numbers with a Decimal Point 55Input Using cin 56Designing Input and Output 58Programming Tip: Line Breaks in I/O 582.3 Data Types and Expressions 60The Types int and double 60Other Number Types 62C++11 Types 63The Type char 64The Type bool 66Introduction to the Class string 66Type Compatibilities 68Arithmetic Operators and Expressions 69Pitfall: Whole Numbers in Division 72More Assignment Statements 742.4 Simple Flow of Control 74A Simple Branching Mechanism 75Pitfall: Strings of Inequalities 80Pitfall: Using = in place of == 81Compound Statements 82Simple Loop Mechanisms 84Increment and Decrement Operators 87Programming Example: Charge Card Balance 89Pitfall: Infinite Loops 902.5 Program Style 93Indenting 93Comments 93Naming Constants 95Chapter Summary 98Answers to Self-Test Exercises 98Practice Programs 103Programming Projects 105Chapter 3 More Flow of Control 1113.1 Usin g Boolean Expressions 112Evaluating Boolean Expressions 112Pitfall: Boolean Expressions Convert to int Values 116Enumeration Types (Optional) 1193.2 Multiway Branches 120Nested Statements 120Programming Tip: Use Braces in Nested Statements 121Multiway if-else Statements 123Programming Example: State Income Tax 125The switch Statement 128Pitfall: Forgetting a break in a switch Statement 132Using switch Statements for Menus 133Blocks 135Pitfall: Inadvertent Local Variables 1383.3 More About C++ Loop Statements 139The while Statements Reviewed 139Increment and Decrement Operators Revisited 141The for Statement 144Pitfall: Extra Semicolon in a for Statement 149What Kind of Loop to Use 150Pitfall: Uninitialized Variables and Infinite Loops 152The break Statement 153Pitfall: The break Statement in Nested Loops 1543.4 Designing Loops 155Loops for Sums and Products 155Ending a Loop 157Nested Loops 160Debugging Loops 162Chapter Summary 165Answers to Self-Test Exercises 166Practice Programs 172Programming Projects 174Chapter 4 Procedural Abstraction and Functions That Return a Value 1814.1 Top-Down Design 1824.2 Predefined Functions 183Using Predefined Functions 183Random Number Generation 188Type Casting 190Older Form of Type Casting 192Pitfall: Integer Division Drops the Fractional Part 1924.3 Programmer-Defined Functions 193Function Definitions 193Functions That Return a Boolean Value 199Alternate Form for Function Declarations 199Pitfall: Arguments in the Wrong Order 200Function Definition-Syntax Summary 201More About Placement of Function Definitions 202Programming Tip: Use Function Calls in Branching Statements 2034.4 Procedural Abstraction 204The Black-Box Analogy 204Programming Tip: Choosing Formal Parameter Names 207Programming Tip: Nested Loops 208Case Study: Buying Pizza 211Programming Tip: Use Pseudocode 2174.5 Scope and Local Variables 218The Small Program Analogy 218Programming Example: Experimental Pea Patch 221Global Constants and Global Variables 221Call-by-Value Formal Parameters Are Local Variables 224Block Scope 226Namespaces Revisited 227Programming Example: The Factorial Function 2304.6 Overloading Function Names 232Introduction to Overloading 232Programming Example: Revised Pizza-Buying Program 235Automatic Type Conversion 238Chapter Summary 240Answers to Self-Test Exercises 240Practice Programs 245Programming Projects 247Chapter 5 Functions for All Subtasks 2515.1 void Functions 252Definitions of void Functions 252Programming Example: Converting Temperatures 255return Statements in void Functions 2555.2 Call-By-Reference Parameters 259A First View of Call-by-Reference 259Call-by-Reference in Detail 262Programming Example: The swap_values Function 267Mixed Parameter Lists 268Programming Tip: What Kind of Parameter to Use 269Pitfall: Inadvertent Local Variables 2705.3 Using Procedural Abstraction 273Functions Calling Functions 273Preconditions and Postconditions 275Case Study: Supermarket Pricing 2765.4 Testing and Debugging Functions 281Stubs and Drivers 2825.5 General Debugging Techniques 287Keep an Open Mind 287Check Common Errors 287Localize the Error 288The assert Macro 290Chapter Summary 292Answers to Self-Test Exercises 293Practice Programs 296Programming Projects 299Chapter 6 I/O Streams as an Introduction to Objects and Classes 3056.1 Streams and Basic File I/O 306Why Use Files for I/O? 307File I/O 308Introduction to Classes and Objects 312Programming Tip: Check Whether a File Was Opened Successfully 314Techniques for File I/O 316Appending to a File (Optional) 320File Names as Input (Optional) 3216.2 Tools for Stream I/O 323Formatting Output with Stream Functions 323Manipulators 329Streams as Arguments to Functions 332Programming Tip: Checking for the End of a File 332A Note on Namespaces 335Programming Example: Cleaning Up a File Format 3366.3 Character I/O 338The Member Functions get and put 338The putback Member Function (Optional) 342Programming Example: Checking Input 343Pitfall: Unexpected '\n' in Input 345Programming Example: Another new_line Function 347Default Arguments for Functions (Optional) 348The eof Member Function 353Programming Example: Editing a Text File 355Predefined Character Functions 356Pitfall: toupper and tolower Return Values 358Chapter Summary 360Answers to Self-Test Exercises 361Practice Programs 368Programming Projects 370Chapter 7 Arrays 3777.1 Introduction to Arrays 378Declaring and Referencing Arrays 378Programming Tip: Use for Loops with Arrays 380Pitfall: Array Indexes Always Start with Zero 380Programming Tip: Use a Defined Constant for the Size of an Array 380Arrays in Memory 382Pitfall: Array Index Out of Range 383Initializing Arrays 386Programming Tip: C++11 Range-Based for Statement 3867.2 Arrays in Functions 389Indexed Variables as Function Arguments 389Entire Arrays as Function Arguments 391The const Parameter Modifier 394Pitfall: Inconsistent Use of const Parameters 397Functions That Return an Array 397Case Study: Production Graph 3987.3 Programming with Arrays 411Partially Filled Arrays 411Programming Tip: Do Not Skimp on Formal Parameters 414Programming Example: Searching an Array 414Programming Example: Sorting an Array 417Programming Example: Bubble Sort 4217.4 Multidimensional Arrays 424Multidimensional Array Basics 425Multidimensional Array Parameters 425Programming Example: Two-DimensionalGrading Program 427Pitfall: Using Commas Between Array Indexes 431Chapter Summary 432Answers to Self-Test Exercises 433Practice Programs 437Programming Projects 439Chapter 8 Strings and Vectors 4518.1 An Array Type for Strings 453C-String Values and C-String Variables 453Pitfall: Using = and == with C Strings 456Other Functions in 458Pitfall: Copying past the end of a C-string using strcpy 461C-String Input and Output 464C-String-to-Number Conversions and Robust Input 4668.2 The Standard string Class 472Introduction to the Standard Class string 472I/O with the Class string 475Programming Tip: More Versions of getline 478Pitfall: Mixing cin >> variable; and getline 479String Processing with the Class string 480Programming Example: Palindrome Testing 484Converting Between string Objects and C Strings 487Converting Between Strings and Numbers 4888.3 Vectors 489Vector Basics 489Pitfall: Using Square Brackets Beyond the Vector Size 492Programming Tip: Vector Assignment Is Well Behaved 493Efficiency Issues 493Chapter Summary 495Answers to Self-Test Exercises 495Practice Programs 497Programming Projects 498Chapter 9 Pointers and Dynamic Arrays 5079.1 Pointers 508Pointer Variables 509Basic Memory Management 516Pitfall: Dangling Pointers 517Static Variables and Automatic Variables 518Programming Tip: Define Pointer Types 5189.2 Dynamic Arrays 521Array Variables and Pointer Variables 521Creating and Using Dynamic Arrays 522Pointer Arithmetic (Optional) 528Multidimensional Dynamic Arrays (Optional) 530Chapter Summary 532Answers to Self-Test Exercises 532Practice Programs 533Programming Projects 534Chapter 10 Defining Classes 54110.1 Structures 542Structures for Diverse Data 542Pitfall: Forgetting a Semicolon in a Structure Definition 547Structures as Function Arguments 548Programming Tip: Use Hierarchical Structures 549Initializing Structures 55110.2 Classes 554Defining Classes and Member Functions 554Public and Private Members 559Programming Tip: Make All Member Variables Private 567Programming Tip: Define Accessor and Mutator Functions 567Programming Tip: Use the Assignment Operator with Objects 569Programming Example: BankAccount Class-Version 1 570Summary of Some Properties of Classes 574Constructors for Initialization 576Programming Tip: Always Include a Default Constructor 584Pitfall: Constructors with No Arguments 585Member Initializers and Constructor Delegation in C++11 58710.3 Abstract Data Types 588Classes to Produce Abstract Data Types 589Programming Example: Alternative Implementation of a Class 59310.4 Introduction to Inheritance 598Derived Classes 599Defining Derived Classes 600Chapter Summary 604Answers to Self-Test Exercises 605Practice Programs 611Programming Projects 612Chapter 11 Friends, Overloaded Operators, and Arrays in Classes 61911.1 Friend Functions 620Programming Example: An Equality Function 620Friend Functions 624Programming Tip: Define Both Accessor Functions and Friend Functions 626Programming Tip: Use Both Member and Nonmember Functions 628Programming Example: Money Class (Version 1) 628Implementation of digit_to_int (Optional) 635Pitfall: Leading Zeros in Number Constants 636The const Parameter Modifier 638Pitfall: Inconsistent Use of const 63911.2 Overloading Operators 643Overloading Operators 644Constructors for Automatic Type Conversion 647Overloading Unary Operators 649Overloading >> and << 65011.3 Arrays and Classes 660Arrays of Classes 660Arrays as Class Members 664Programming Example: A Class for a Partially Filled Array 66511.4 Classes and Dynamic Arrays 667Programming Example: A String Variable Class 668Destructors 671Pitfall: Pointers as Call-by-Value Parameters 674Copy Constructors 675Overloading the Assignment Operator 680Chapter Summary 683Answers to Self-Test Exercises 683Practice Programs 693Programming Projects 694Chapter 12 Separate Compilation and Namespaces 70312.1 Separate Compilation 704ADTs Reviewed 705Case Study: DigitalTime -A Class Compiled Separately 706Using #ifndef 715Programming Tip: Defining Other Libraries 71812.2 Namespaces 719Namespaces and using Directives 719Creating a Namespace 721Qualifying Names 724A Subtle Point About Namespaces (Optional) 725Unnamed Namespaces 726Programming Tip: Choosing a Name for a Namespace 731Pitfall: Confusing the Global Namespace and the Unnamed Namespace 732Chapter Summary 733Answers to Self-Test Exercises 734Practice Programs 736Programming Projects 738Chapter 13 Pointers and Linked Lists 73913.1 Nodes and Linked Lists 740Nodes 740nullptr 745Linked Lists 746Inserting a Node at the Head of a List 747Pitfall: Losing Nodes 750Searching a Linked List 751Pointers as Iterators 755Inserting and Removing Nodes Inside a List 755Pitfall: Using the Assignment Operator with Dynamic Data Structures 757Variations on Linked Lists 760Linked Lists of Classes 76213.2 Stacks and Queues 765Stacks 765Programming Example: A Stack Class 766Queues 771Programming Example: A Queue Class 772Chapter Summary 776Answers to Self-Test Exercises 776Practice Programs 779Programming Projects 780Chapter 14 Recursion 78914.1 Recursive Functions for Tasks 791Case Study: Vertical Numbers 791A Closer Look at Recursion 797Pitfall: Infinite Recursion 799Stacks for Recursion 800Pitfall: Stack Overflow 802Recursion Versus Iteration 80214.2 Recursive Functions for Values 804General Form for a Recursive Function That Returns a Value 804Programming Example: Another Powers Function 80414.3 Thinking Recursively 809Recursive Design Techniques 809Case Study: Binary Search-An Example of Recursive Thinking 810Programming Example: A Recursive Member Function 818Chapter Summary 822Answers to Self-Test Exercises 822Practice Programs 827Programming Projects 827Chapter 15 Inheritance 83315.1 Inheritance Basics 834Derived Classes 837Constructors in Derived Classes 845Pitfall: Use of Private Member Variables from the Base Class 848Pitfall: Private Member Functions Are Effectively Not Inherited 850The protected Qualifier 850Redefinition of Member Functions 853Redefining Versus Overloading 856Access to a Redefined Base Function 85815.2 INHERITANCE DETAILS 859Functions That Are Not Inherited 859Assignment Operators and Copy Constructors in Derived Classes 860Destructors in Derived Classes 86115.3 Polymorphism 862Late Binding 863Virtual Functions in C++ 864Virtual Functions and Extended Type Compatibility 869Pitfall: The Slicing Problem 873Pitfall: Not Using Virtual Member Functions 874Pitfall: Attempting to Compile Class Definitions Without Definitions for Every Virtual Member Function 875Programming Tip: Make Destructors Virtual 875Chapter Summary 877Answers to Self-Test Exercises 877Practice Programs 881Programming Projects 884Chapter 16 Exception Handling 89316.1 Exception-Handling Basics 895A Toy Example of Exception Handling 895Defining Your Own Exception Classes 904Multiple Throws and Catches 904Pitfall: Catch the More Specific Exception First 908Programming Tip: Exception Classes Can Be Trivial 909Throwing an Exception in a Function 909Exception Specification 911Pitfall: Exception Specification in Derived Classes 91316.2 Programming Techniques forException Handling 914When to Throw an Exception 914Pitfall: Uncaught Exceptions 916Pitfall: Nested try-catch Blocks 916Pitfall: Overuse of Exceptions 916Exception Class Hierarchies 917Testing for Available Memory 917Rethrowing an Exception 918Chapter Summary 918Answers to Self-Test Exercises 918Practice Programs 920Programming Projects 921Chapter 17 Templates 92517.1 Templates for Algorithm Abstraction 926Templates for Functions 927Pitfall: Compiler Complications 931Programming Example: A Generic Sorting Function 933Programming Tip: How to Define Templates 937Pitfall: Using a Template with an Inappropriate Type 93817.2 Templates for Data Abstraction 939Syntax for Class Templates 939Programming Example: An Array Class 942Chapter Summary 949Answers to Self-Test Exercises 949Practice Programs 953Programming Projects 953Chapter 18 Standard Template Library 95718.1 Iterators 959using Declarations 959Iterator Basics 960Programming Tip: Use auto to Simplify Variable Declarations 964Pitfall: Compiler Problems 964Kinds of Iterators 966Constant and Mutable Iterators 970Reverse Iterators 971Other Kinds of Iterators 97218.2 Containers 973Sequential Containers 974Pitfall: Iterators and Removing Elements 978Programming Tip: Type Definitions in Containers 979Container Adapters stack and queue 979Associative Containers set and map 983Programming Tip: Use Initialization, Ranged For, and auto with Containers 990Efficiency 99018.3 Generic Algorithms 991Running Times and Big-O Notation 992Container Access Running Times 995Nonmodifying Sequence Algorithms 997Container Modifying Algorithms 1001Set Algorithms 1003Sorting Algorithms 1004Chapter Summary 1005Answers to Self-Test Exercises 1005Practice Programs 1007Programming Projects 1008Appendices1 C++ Keywords 10152 Precedence of Operators 10163 The ASCII Character Set 10184 Some Library Functions 10195 Inline Functions 10266 Overloading the Array Index Square Brackets 10277 The this Pointer 10298 Overloading Operators as Member Operators 1032Index 1034

最近チェックした商品