Problem Solving with C++

Similar documents
Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Absolute C++ Walter Savitch

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Introduction to Programming Using Java (98-388)

C++ (Non for C Programmer) (BT307) 40 Hours

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.

CS201 Some Important Definitions

C-LANGUAGE CURRICULAM

I BSc(IT) [ Batch] Semester II Core: Object Oriented Programming With C plus plus - 212A Multiple Choice Questions.

The Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured

This page intentionally left blank

Welcome to Teach Yourself Acknowledgments Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p.

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Object Oriented Programming with c++ Question Bank

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

Practical C++ Programming

Chapter 2 Basic Elements of C++

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Borland 105, 278, 361, 1135 Bounded array Branch instruction 7 break statement 170 BTree 873 Building a project 117 Built in data types 126

VALLIAMMAI ENGINEERING COLLEGE

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Short Notes of CS201

Chapter 2: Basic Elements of C++

Programming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 12: Classes and Data Abstraction

CS201 - Introduction to Programming Glossary By

Building Java Programs

Introduction to C++ Systems Programming

COP 3014: Fall Final Study Guide. December 5, You will have an opportunity to earn 15 extra credit points.

Chapter Procedural Abstraction and Functions That Return a Value. Overview. Top-Down Design. Benefits of Top Down Design.

Chapter 4. Procedural Abstraction and Functions That Return a Value

Computer Programming C++ (wg) CCOs

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Instantiation of Template class

PROGRAMMING IN C AND C++:

Advanced C++ Programming Workshop (With C++11, C++14, C++17) & Design Patterns

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

KLiC C++ Programming. (KLiC Certificate in C++ Programming)

RAJIV GANDHI COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF INFORMATION TECHNOLOGY OBJECT ORIENTED PROGRAMMING QUESTION BANK UNIT I 2 MARKS

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

Contents. 1 Introduction to Computers, the Internet and the World Wide Web 1. 2 Introduction to C Programming 26

Programming. C++ Basics

Chapter 15 - C++ As A "Better C"

Programmer-Defined Functions

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

Objectives. In this chapter, you will:

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

Interview Questions of C++

Contents Chapter 1 Introduction to Programming and the Java Language

Chapter 4 Defining Classes I

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

CERTIFICATE IN WEB PROGRAMMING

AN OVERVIEW OF C++ 1

Standard. Number of Correlations

Supplement I.A: Glossary. For Introduction to C++ Programming, Second Edition By Y. Daniel Liang

Contents. Preface. Introduction. Introduction to C Programming

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

Contents. 2 Introduction to C++ Programming,

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming

Index COPYRIGHTED MATERIAL

Basic Types, Variables, Literals, Constants

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

SAURASHTRA UNIVERSITY


M.C.A DEGREE EXAMINATION,NOVEMBER/DECEMBER 2010 Second Semester MC 9222-OBJECT ORIENTED PROGRAMMING (Regulation 2009)

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Tokens, Expressions and Control Structures

Get Unique study materials from

XII- COMPUTER SCIENCE VOL-II MODEL TEST I

[CHAPTER] 1 INTRODUCTION 1


STRUCTURING OF PROGRAM

Chapter 8. Operator Overloading, Friends, and References. Copyright 2010 Pearson Addison-Wesley. All rights reserved

Review of the C Programming Language for Principles of Operating Systems

3. Java - Language Constructs I


Review of the C Programming Language

Model Viva Questions for Programming in C lab

Fast Introduction to Object Oriented Programming and C++

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Programming for Engineers Iteration


C++ for System Developers with Design Pattern

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

CSCI 1061U Programming Workshop 2. C++ Basics

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Transcription:

GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock

Ninth Edition PROBLEM SOLVING with C++

Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter 1 Introduction to Computers and C++ Programming 1.1 Computer Systems Hardware Software High-Level Languages Compilers History Note 1.2 Programing and Problem-Solving Algorithms Program Design Object-Oriented Programming The Software Life Cycle 1.3 Introduction to C++ Origins of the C++ Language A Sample C++ Program Pitfall: Using the Wrong Slash in \n Programming Tip: Input and Output Syntax Layout of a Simple C++ Program Pitfall: Putting a Space Before the include File Name Compiling and Running a C++ Program Pitfall: Compiling a C++11 program Programming Tip: Getting Your Program to Run 1.4 Testing and Debugging Kinds of Program Errors Pitfall: Assuming Your Program Is Correct Chapter 2 C++ Basics 2.1 Variables and Assignments Variables Names: Identifiers Variable Declarations

Assignment Statements Pitfall: Uninitialized Variables Programming Tip: Use Meaningful Names 2.2 Input and Output Output Using cout Include Directives and Namespaces Escape Sequences Programming Tip: End Each Program with a \n or end Formatting for Numbers with a Decimal Point Input Using cin Designing Input and Output Programming Tip: Line Breaks in I/O 2.3 Data Types and Expresions The Types int and double Other Number Types C++11 Types The Type char The Type bool Introduction to the Class string Type Compatibilities Arithmetic Operators and Expressions Pitfall: Whole Numbers in Division More Assignment Statements 2.4 Simple Flow of Control A Simple Branching Mechanism Pitfall: Strings of Inequalities Pitfall: Using = in place of == Compound Statements Simple Loop Mechanisms Increment and Decrement Operators Programming Example: Charge Card Balance Pitfall: Infinite Loops 2.5 Program Style Indenting Comments Naming Constants Chapter 3 More Flow of Control

3.1 Usin g Boolean Expresions Evaluating Boolean Expressions Pitfall: Boolean Expressions Convert to int Values Enumeration Types (Optional) 3.2 Multiway Branches Nested Statements Programming Tip: Use Braces in Nested Statements Multiway if-else Statements Programming Example: State Income Tax The switch Statement Pitfall: Forgetting a break in a switch Statement Using switch Statements for Menus Blocks Pitfall: Inadvertent Local Variables 3.3 More About C++ Loop Statements The while Statements Reviewed Increment and Decrement Operators Revisited The for Statement Pitfall: Extra Semicolon in a for Statement What Kind of Loop to Use Pitfall: Uninitialized Variables and Infinite Loops The break Statement Pitfall: The break Statement in Nested Loops 3.4 Designing Loops Loops for Sums and Products Ending a Loop Nested Loops Debugging Loops Chapter 4 Procedural Abstraction and FunctionsThat Return a Value 4.1 Top-Down Design 4.2 Predefined Functions Using Predefined Functions Random Number Generation Type Casting Older Form of Type Casting Pitfall: Integer Division Drops the Fractional Part 4.3 Programer-Defined Functions

Function Definitions Functions That Return a Boolean Value Alternate Form for Function Declarations Pitfall: Arguments in the Wrong Order Function DefinitionSyntax Summary More About Placement of Function Definitions Programming Tip: Use Function Calls in Branching Statements 4.4 Procedural Abstraction The Black-Box Analogy Programming Tip: Choosing Formal Parameter Names Programming Tip: Nested Loops Case Study: Buying Pizza Programming Tip: Use Pseudocode 4.5 Scope and Local Variables The Small Program Analogy Programming Example: Experimental Pea Patch Global Constants and Global Variables Call-by-Value Formal Parameters Are Local Variables Block Scope Namespaces Revisited Programming Example: The Factorial Function 4.6 Overloading Function Names Introduction to Overloading Programming Example: Revised Pizza-Buying Program Automatic Type Conversion Chapter 5 Functions for All Subtasks 5.1 void Functions Definitions of void Functions Programming Example: Converting Temperatures return Statements in void Functions 5.2 Cal-By-Reference Parameters A First View of Call-by-Reference Call-by-Reference in Detail Programming Example: The swap_values Function Mixed Parameter Lists Programming Tip: What Kind of Parameter to Use Pitfall: Inadvertent Local Variables

5.3 Using Procedural Abstraction Functions Calling Functions Preconditions and Postconditions Case Study: Supermarket Pricing 5.4 Testing and Debugging Functions Stubs and Drivers 5.5 General Debugging Techniques Keep an Open Mind Check Common Errors Localize the Error The assert Macro Chapter 6 I/O Streams as an Introduction to Objects and Classes 6.1 Streams and Basic File I/O Why Use Files for I/O? File I/O Introduction to Classes and Objects Programming Tip: Check Whether a File Was Opened Successfully Techniques for File I/O Appending to a File (Optional) File Names as Input (Optional) 6.2 Tools for Stream I/O Formatting Output with Stream Functions Manipulators Streams as Arguments to Functions Programming Tip: Checking for the End of a File A Note on Namespaces Programming Example: Cleaning Up a File Format 6.3 Character I/O The Member Functions get and put The putback Member Function (Optional) Programming Example: Checking Input Pitfall: Unexpected '\n' in Input Programming Example: Another new_line Function Default Arguments for Functions (Optional) The eof Member Function Programming Example: Editing a Text File Predefined Character Functions

Pitfall: toupper and to lower Return Values Chapter 7 Arrays 7.1 Introduction to Arrays Declaring and Referencing Arrays Programming Tip: Use for Loops with Arrays Pitfall: Array Indexes Always Start with Zero Programming Tip: Use a Defined Constant for the Size of an Array Arrays in Memory Pitfall: Array Index Out of Range Initializing Arrays Programming Tip: C++11 Range-Based for Statement 7.2 Arrays in Functions Indexed Variables as Function Arguments Entire Arrays as Function Arguments The const Parameter Modifier Pitfall: Inconsistent Use of const Parameters Functions That Return an Array Case Study: Production Graph 7.3 Programing with Arrays Partially Filled Arrays Programming Tip: Do Not Skimp on Formal Parameters Programming Example: Searching an Array Programming Example: Sorting an Array Programming Example: Bubble Sort 7.4 Multidimensional Arrays Multidimensional Array Basics Multidimensional Array Parameters Programming Example: Two-Dimensional Grading Program Pitfall: Using Commas Between Array Indexes Chapter 8 Strings and Vectors 8.1 An Array Type for Strings C-String Values and C-String Variables Pitfall: Using = and == with C Strings

Other Functions in <cstring> Pitfall: Copying past the end of a C-string using strcpy C-String Input and Output C-String-to-Number Conversions and Robust Input 8.2 The Standard string Class Introduction to the Standard Class string I/O with the Class string Programming Tip: More Versions of getline Pitfall: Mixing cin >> variable; and getline String Processing with the Class string Programming Example: Palindrome Testing Converting Between string Objects and C Strings Converting Between Strings and Numbers 8.3 Vectors Vector Basics Pitfall: Using Square Brackets Beyond the Vector Size Programming Tip: Vector Assignment Is Well Behaved Efficiency Issues Chapter 9 Pointers and Dynamic Arrays 9.1 Pointers Pointer Variables Basic Memory Management Pitfall: Dangling Pointers Static Variables and Automatic Variables Programming Tip: Define Pointer Types 9.2 Dynamic Arrays Array Variables and Pointer Variables Creating and Using Dynamic Arrays Pointer Arithmetic (Optional) Multidimensional Dynamic Arrays (Optional) Chapter 10 Defining Classes 10.1 Structures Structures for Diverse Data

Pitfall: Forgetting a Semicolon in a Structure Definition Structures as Function Arguments Programming Tip: Use Hierarchical Structures Initializing Structures 10.2 Clases Defining Classes and Member Functions Public and Private Members Programming Tip: Make All Member Variables Private Programming Tip: Define Accessor and Mutator Functions Programming Tip: Use the Assignment Operator with Objects Programming Example: BankAccount ClassVersion 1 Summary of Some Properties of Classes Constructors for Initialization Programming Tip: Always Include a Default Constructor Pitfall: Constructors with No Arguments Member Initializers and Constructor Delegation in C++11 10.3 Abstract Data Types Classes to Produce Abstract Data Types Programming Example: Alternative Implementation of a Class 10.4 Introduction to Inheritance Derived Classes Defining Derived Classes Chapter 11 Friends, Overloaded Operators, and Arrays in Classes 11.1 Friend Functions Programming Example: An Equality Function Friend Functions Programming Tip: Define Both Accessor Functions and Friend Functions Programming Tip: Use Both Member and Nonmember Functions Programming Example: Money Class (Version 1) Implementation of digit_to_int (Optional) Pitfall: Leading Zeros in Number Constants The const Parameter Modifier Pitfall: Inconsistent Use of const 11.2 Overloading Operators Overloading Operators Constructors for Automatic Type Conversion Overloading Unary Operators

Overloading >> and << 11.3 Arrays and Clases Arrays of Classes Arrays as Class Members Programming Example: A Class for a Partially Filled Array 11.4 Clases and Dynamic Arrays Programming Example: A String Variable Class Destructors Pitfall: Pointers as Call-by-Value Parameters Copy Constructors Overloading the Assignment Operator Chapter 12 Separate Compilation and Namespaces 12.1 Separate Compilation ADTs Reviewed Case Study: DigitalTime A Class Compiled Separately Using #ifndef Programming Tip: Defining Other Libraries 12.2 Namespaces Namespaces and using Directives Creating a Namespace Qualifying Names A Subtle Point About Namespaces (Optional) Unnamed Namespaces Programming Tip: Choosing a Name for a Namespace Pitfall: Confusing the Global Namespace and the Unnamed Namespace Chapter 13 Pointers and Linked Lists 13.1 Nodes and Linked Lists Nodes nullptr Linked Lists Inserting a Node at the Head of a List Pitfall: Losing Nodes Searching a Linked List

Pointers as Iterators Inserting and Removing Nodes Inside a List Pitfall: Using the Assignment Operator with Dynamic Data Structures Variations on Linked Lists Linked Lists of Classes 13.2 Stacks and Queues Stacks Programming Example: A Stack Class Queues Programming Example: A Queue Class Chapter 14 Recursion 14.1 Recursive Functions for Tasks Case Study: Vertical Numbers A Closer Look at Recursion Pitfall: Infinite Recursion Stacks for Recursion Pitfall: Stack Overflow Recursion Versus Iteration 14.2 Recursive Functions for Values General Form for a Recursive Function That Returns a Value Programming Example: Another Powers Function 14.3 Thinking Recursively Recursive Design Techniques Case Study: Binary SearchAn Example of Recursive Thinking Programming Example: A Recursive Member Function Chapter 15 Inheritance 15.1 Inheritance Basics Derived Classes Constructors in Derived Classes Pitfall: Use of Private Member Variables from the Base Class Pitfall: Private Member Functions Are Effectively Not Inherited The protected Qualifier Redefinition of Member Functions

Redefining Versus Overloading Access to a Redefined Base Function 15.2 Inheritance Details Functions That Are Not Inherited Assignment Operators and Copy Constructors in Derived Classes Destructors in Derived Classes 15.3 Polymorphism Late Binding Virtual Functions in C++ Virtual Functions and Extended Type Compatibility Pitfall: The Slicing Problem Pitfall: Not Using Virtual Member Functions Pitfall: Attempting to Compile Class Definitions Without Definitions for Every Virtual Member Function Programming Tip: Make Destructors Virtual Chapter 16 Exception Handling 16.1 Exception-Handling Basics A Toy Example of Exception Handling Defining Your Own Exception Classes Multiple Throws and Catches Pitfall: Catch the More Specific Exception First Programming Tip: Exception Classes Can Be Trivial Throwing an Exception in a Function Exception Specification Pitfall: Exception Specification in Derived Classes 16.2 Programing Techniques for Exception Handling When to Throw an Exception Pitfall: Uncaught Exceptions Pitfall: Nested try-catch Blocks Pitfall: Overuse of Exceptions Exception Class Hierarchies Testing for Available Memory Rethrowing an Exception

Chapter 17 Templates 17.1 Templates for Algorithm Abstraction Templates for Functions Pitfall: Compiler Complications Programming Example: A Generic Sorting Function Programming Tip: How to Define Templates Pitfall: Using a Template with an Inappropriate Type 17.2 Templates for Data Abstraction Syntax for Class Templates Programming Example: An Array Class Chapter 18 Standard Template Library 18.1 Iterators using Declarations Iterator Basics Programming Tip: Use auto to Simplify Variable Declarations Pitfall: Compiler Problems Kinds of Iterators Constant and Mutable Iterators Reverse Iterators Other Kinds of Iterators 18.2 Containers Sequential Containers Pitfall: Iterators and Removing Elements Programming Tip: Type Definitions in Containers Container Adapters stack and queue Associative Containers set and map Programming Tip: Use Initialization, Ranged For,and auto with Containers Efficiency 18.3 Generic Algorithms Running Times and Big-O Notation Container Access Running Times Nonmodifying Sequence Algorithms Container Modifying Algorithms Set Algorithms Sorting Algorithms

Appendices 1 C++ Keywords 2 Precedence of Operators 3 The ASCII Character Set 4 Some Library Functions 5 Inline Functions 6 Overloading the Array Index Square Brackets 7 The this Pointer 8 Overloading Operators as Member Operators Index SYMBOLS A B C D E F G H I L M N O P Q R S T U V W Z Credits