Absolute C++ Walter Savitch

Similar documents
Problem Solving with C++

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.

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

Introduction to Programming Using Java (98-388)

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

Object Oriented Programming with c++ Question Bank

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

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

This page intentionally left blank

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

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

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

Practical C++ Programming

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

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

C-LANGUAGE CURRICULAM

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

Computer Programming C++ (wg) CCOs

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

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.

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

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

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

Chapter 2 Basic Elements of C++

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

CERTIFICATE IN WEB PROGRAMMING

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

VALLIAMMAI ENGINEERING COLLEGE

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

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

Interview Questions of C++

Short Notes of CS201

VIRTUAL FUNCTIONS Chapter 10

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

CS201 - Introduction to Programming Glossary By

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

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

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

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

Object Oriented Programming

Introduction to C++ Systems Programming

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

STRUCTURING OF PROGRAM

Contents Chapter 1 Introduction to Programming and the Java Language

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

Instantiation of Template class

CS201 Some Important Definitions

AN OVERVIEW OF C++ 1

CompuScholar, Inc. Alignment to Nevada "Computer Science" Course Standards

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


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

Chapter 2: Basic Elements of C++

SAURASHTRA UNIVERSITY

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

Contents. Preface. Introduction. Introduction to C Programming


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

index C++ language characters ASCII codes, 16 escape sequence, 19 trigraph sequence, 18 UCS codes, 17 Unicode, 17 classes, 7 code presentation styles,

Contents. 2 Introduction to C++ Programming,

Objectives. In this chapter, you will:

Get Unique study materials from

Building Java Programs

Programming. C++ Basics

Chapter 4 Defining Classes I

Syllabus of C++ Software for Hands-on Learning: This course offers the following modules: Module 1: Getting Started with C++ Programming


CSCI 1061U Programming Workshop 2. C++ Basics

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Standard. Number of Correlations


XII- COMPUTER SCIENCE VOL-II MODEL TEST I

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Index COPYRIGHTED MATERIAL

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

This page intentionally left blank

Programming, numerics and optimization

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

Supplement I.A: Glossary For Introduction to Programming and Data Structures with C++ Fourth Edition By Y. Daniel Liang

CS3157: Advanced Programming. Outline

Object Oriented Programming. Solved MCQs - Part 2

Fast Introduction to Object Oriented Programming and C++

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

UNIT- 3 Introduction to C++

Curriculum Map Grade(s): Subject: AP Computer Science

An Object Oriented Programming with C

2 ADT Programming User-defined abstract data types

Computer Science 306 Study Guide

Microsoft. Microsoft Visual C# Step by Step. John Sharp

B.C.A 2017 OBJECT ORIENTED PROGRAMMING USING C++ BCA303T MODULE SPECIFICATION SHEET

Tokens, Expressions and Control Structures

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Ch. 12: Operator Overloading

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

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

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

Computer Programming : C++

END TERM EXAMINATION

Transcription:

Absolute C++ sixth edition Walter Savitch Global edition

This page intentionally left blank

Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents Chapter 1 C++ Basics 1.1 INTRODUCTION TO C++ Origins of the C++ Language C++ and Object-Oriented Programming The Character of C++ C++ Terminology A Sample C++ Program TIP: Compiling C++ Programs 1.2 VARIABLES, EXPRESSIONS, AND ASSIGNMENT STATEMENTS Identifiers Variables Assignment Statements Introduction to the string class PITFALL: Uninitialized Variables TIP: Use Meaningful Names More Assignment Statements Assignment Compatibility Literals Escape Sequences Raw String Literals Naming Constants Arithmetic Operators and Expressions Integer and Floating-Point Division PITFALL: Division with Whole Numbers Type Casting Increment and Decrement Operators PITFALL: Order of Evaluation 1.3 CONSOLE INPUT/OUTPUT Output Using cout New Lines in Output

TIP: End Each Program with \n or endl Formatting for Numbers with a Decimal Point Output with cerr Input Using cin TIP: Line Breaks in I/O 1.4 PROGRAM STYLE Comments 1.5 LIBRARIES AND NAMESPACES Libraries and include Directives Namespaces PITFALL: Problems with Library Names Chapter 2 Flow of Control 2.1 BOOLEAN EXPRESSIONS Building Boolean Expressions PITFALL: Strings of Inequalities Evaluating Boolean Expressions Precedence Rules PITFALL: Integer Values Can Be Used as Boolean Values 2.2 BRANCHING MECHANISMS if-else Statements Compound Statements PITFALL: Using = in Place of = = Omitting the else Nested Statements Multiway if-else Statement The switch Statement PITFALL: Forgetting a break in a switch Statement TIP: Use switch Statements for Menus Enumeration Types The Conditional Operator 2.3 LOOPS The while and do-while Statements Increment and Decrement Operators Revisited The Comma Operator

The for Statement TIP: Repeat-N-Times Loops PITFALL: Extra Semicolon in a for Statement PITFALL: Infinite Loops The break and continue Statements Nested Loops 2.4 INTRODUCTION TO FILE INPUT Reading From a Text File Using ifstream Chapter 3 Function Basics 3.1 PREDEFINED FUNCTIONS Predefined Functions That Return a Value Predefined void Functions A Random Number Generator 3.2 PROGRAMMER-DEFINED FUNCTIONS Defining Functions That Return a Value Alternate Form for Function Declarations PITFALL: Arguments in the Wrong Order PITFALL: Use of the Terms Parameter and Argument Functions Calling Functions EXAMPLE: A Rounding Function Functions That Return a Boolean Value Defining void Functions return Statements in void Functions Preconditions and Postconditions main Is a Function Recursive Functions 3.3 SCOPE RULES Local Variables Procedural Abstraction Global Constants and Global Variables

Blocks Nested Scopes TIP: Use Function Calls in Branching and Loop Statements Variables Declared in a for Loop Chapter 4 Parameters and Overloading 4.1 PARAMETERS Call-by-Value Parameters A First Look at Call-by-Reference Parameters Call-by-Reference Mechanism in Detail Constant Reference Parameters EXAMPLE: The swapvalues Function TIP: Think of Actions, Not Code Mixed Parameter Lists TIP: What Kind of Parameter to Use PITFALL: Inadvertent Local Variables TIP: Choosing Formal Parameter Names EXAMPLE: Buying Pizza 4.2 OVERLOADING AND DEFAULT ARGUMENTS Introduction to Overloading PITFALL: Automatic Type Conversion and Overloading Rules for Resolving Overloading EXAMPLE: Revised Pizza-Buying Program Default Arguments 4.3 TESTING AND DEBUGGING FUNCTIONS The assert Macro Stubs and Drivers Chapter 5 Arrays 5.1 INTRODUCTION TO ARRAYS Declaring and Referencing Arrays

TIP: Use for Loops with Arrays PITFALL: Array Indexes Always Start with Zero TIP: Use a Defined Constant for the Size of an Array Arrays in Memory PITFALL: Array Index out of Range The Range-Based for Loop Initializing Arrays 5.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 EXAMPLE: Production Graph 5.3 PROGRAMMING WITH ARRAYS Partially Filled Arrays TIP: Do Not Skimp on Formal Parameters EXAMPLE: Searching an Array EXAMPLE: Sorting an Array EXAMPLE: Bubble Sort 5.4 MULTIDIMENSIONAL ARRAYS Multidimensional Array Basics Multidimensional Array Parameters EXAMPLE: Two-Dimensional Grading Program Chapter 6 Structures and Classes 6.1 STRUCTURES Structure Types PITFALL: Forgetting a Semicolon in a Structure Definition Structures as Function Arguments TIP: Use Hierarchical Structures Initializing Structures 6.2 CLASSES

Defining Classes and Member Functions Encapsulation Public and Private Members Accessor and Mutator Functions TIP: Separate Interface and Implementation TIP: A Test for Encapsulation Structures versus Classes TIP: Thinking Objects Chapter 7 Constructors and Other Tools 7.1 CONSTRUCTORS Constructor Definitions PITFALL: Constructors with No Arguments Explicit Constructor Calls TIP: Always Include a Default Constructor EXAMPLE: BankAccount Class Class Type Member Variables Member Initializers and Constructor Delegation in C++11 7.2 MORE TOOLS The const Parameter Modifier PITFALL: Inconsistent Use of const Inline Functions Static Members Nested and Local Class Definitions 7.3 VECTORS A PREVIEW OF THE STANDARD TEMPLATE LIBRARY Vector Basics PITFALL: Using Square Brackets beyond the Vector Size TIP: Vector Assignment Is Well Behaved Efficiency Issues

Chapter 8 Operator Overloading, Friends, and References 8.1 BASIC OPERATOR OVERLOADING Overloading Basics TIP: A Constructor Can Return an Object Returning by const Value Overloading Unary Operators Overloading as Member Functions TIP: A Class Has Access to All Its Objects Overloading Function Application ( ) PITFALL: Overloading &&,, and the Comma Operator 8.2 FRIEND FUNCTIONS AND AUTOMATIC TYPE CONVERSION Constructors for Automatic Type Conversion PITFALL: Member Operators and Automatic Type Conversion Friend Functions Friend Classes PITFALL: Compilers without Friends 8.3 REFERENCES AND MORE OVERLOADED OPERATORS References TIP: Returning Member Variables of a Class Type Overloading >> and << TIP: What Mode of Returned Value to Use The Assignment Operator Overloading the Increment and Decrement Operators Overloading the Array Operator [ ] Overloading Based on L-Value versus R-Value Chapter 9 Strings

9.1 AN ARRAY TYPE FOR STRINGS C-String Values and C-String Variables PITFALL: Using = and == with C-strings Other Functions in <cstring> EXAMPLE: Command-Line Arguments C-String Input and Output 9.2 CHARACTER MANIPULATION TOOLS Character I/O The Member Functions get and put EXAMPLE: Checking Input Using a Newline Function PITFALL: Unexpected '\n' in Input The putback, peek, and ignore Member Functions Character-Manipulating Functions PITFALL: toupper and tolower Return int Values 9.3 THE STANDARD CLASS String Introduction to the Standard Class string I/O with the Class string TIP: More Versions of getline PITFALL: Mixing cin >> variable String Processing with the Class string EXAMPLE: Palindrome Testing Converting between string Objects and C-Strings Converting between string Objects and Numbers Chapter 10 Pointers and Dynamic Arrays 10.1 POINTERS Pointer Variables Basic Memory Management nullptr PITFALL: Dangling Pointers

Dynamic Variables and Automatic Variables TIP: Define Pointer Types PITFALL: Pointers as Call-by-Value Parameters Uses for Pointers 10.2 DYNAMIC ARRAYS Array Variables and Pointer Variables Creating and Using Dynamic Arrays EXAMPLE: A Function That Returns an Array Pointer Arithmetic Multidimensional Dynamic Arrays 10.3 CLASSES, POINTERS, AND DYNAMIC ARRAYS The -> Operator The this Pointer Overloading the Assignment Operator EXAMPLE: A Class for Partially Filled Arrays Destructors Copy Constructors Chapter 11 Separate Compilation and Namespaces 11.1 SEPARATE COMPILATION Encapsulation Reviewed Header Files and Implementation Files EXAMPLE: DigitalTime Class TIP: Reusable Components Using ifndef TIP: Defining Other Libraries 11.2 NAMESPACES Namespaces and using Directives Creating a Namespace using Declarations Qualifying Names TIP: Choosing a Name for a Namespace

EXAMPLE: A Class Definition in a Namespace Unnamed Namespaces PITFALL: Confusing the Global Namespace and the Unnamed Namespace TIP: Unnamed Namespaces Replace the static Qualifier TIP: Hiding Helping Functions Nested Namespaces TIP: What Namespace Specification Should You Use? Chapter 12 Streams and File I/O 12.1 I/O STREAMS File I/O PITFALL: Restrictions on Stream Variables Appending to a File TIP: Another Syntax for Opening a File TIP: Check That a File Was Opened Successfully Character I/O Checking for the End of a File 12.2 TOOLS FOR STREAM I/O File Names as Input Formatting Output with Stream Functions Manipulators Saving Flag Settings More Output Stream Member Functions EXAMPLE: Cleaning Up a File Format EXAMPLE: Editing a Text File 12.3 STREAM HIERARCHIES: A PREVIEW OF INHERITANCE Inheritance among Stream Classes EXAMPLE: Another newline Function Parsing Strings with the stringstream Class 12.4 RANDOM ACCESS TO FILES

Chapter 13 Recursion 13.1 RECURSIVE Void FUNCTIONS EXAMPLE: Vertical Numbers Tracing a Recursive Call A Closer Look at Recursion PITFALL: Infinite Recursion Stacks for Recursion PITFALL: Stack Overflow Recursion versus Iteration 13.2 RECURSIVE FUNCTIONS THAT RETURN A VALUE General Form for a Recursive Function That Returns a Value EXAMPLE: Another Powers Function Mutual Recursion 13.3 THINKING RECURSIVELY Recursive Design Techniques Binary Search Coding Checking the Recursion Efficiency Chapter 14 Inheritance 14.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 Functions That Are Not Inherited 14.2 PROGRAMMING WITH INHERITANCE

Assignment Operators and Copy Constructors in Derived Classes Destructors in Derived Classes EXAMPLE: Partially Filled Array with Backup PITFALL: Same Object on Both Sides of the Assignment Operator EXAMPLE: Alternate Implementation of PFArrayDBak TIP: A Class Has Access to Private Members of All Objects of the Class TIP: Is a versus Has a Protected and Private Inheritance Multiple Inheritance Chapter 15 Polymorphism and Virtual Functions 15.1 VIRTUAL FUNCTION BASICS Late Binding Virtual Functions in C++ Provide Context with C++11 s override Keyword Preventing a Virtual Function from Being Overridden TIP: The Virtual Property Is Inherited TIP: When to Use a Virtual Function PITFALL: Omitting the Definition of a Virtual Member Function Abstract Classes and Pure Virtual Functions EXAMPLE: An Abstract Class 15.2 POINTERS AND VIRTUAL FUNCTIONS Virtual Functions and Extended Type Compatibility PITFALL: The Slicing Problem TIP: Make Destructors Virtual Downcasting and Upcasting How C++ Implements Virtual Functions

Chapter 16 Templates 16.1 FUNCTION TEMPLATES Syntax for Function Templates PITFALL: Compiler Complications TIP: How to Define Templates EXAMPLE: A Generic Sorting Function PITFALL: Using a Template with an Inappropriate Type 16.2 CLASS TEMPLATES Syntax for Class Templates EXAMPLE: An Array Template Class The vector and basic_string Templates 16.3 TEMPLATES AND INHERITANCE EXAMPLE: Template Class For a Partially Filled Array with Backup Chapter 17 Linked Data Structures 17.1 NODES AND LINKED LISTS Nodes Linked Lists Inserting a Node at the Head of a List PITFALL: Losing Nodes Inserting and Removing Nodes Inside a List PITFALL: Using the Assignment Operator with Dynamic Data Structures Searching a Linked List Doubly Linked Lists Adding a Node to a Doubly Linked List Deleting a Node from a Doubly Linked List EXAMPLE: A Generic Sorting Template Version of Linked List Tools 17.2 LINKED LIST APPLICATIONS EXAMPLE: A Stack Template Class EXAMPLE: A Queue Template Class

TIP: A Comment on Namespaces Friend Classes and Similar Alternatives EXAMPLE: Hash Tables With Chaining Efficiency of Hash Tables EXAMPLE: A Set Template Class Efficiency of Sets Using Linked Lists 17.3 ITERATORS Pointers as Iterators Iterator Classes EXAMPLE: An Iterator Class 17.4 TREES Tree Properties EXAMPLE: A Tree Template Class Chapter 18 Exception Handling 18.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 TIP: Exception Classes Can Be Trivial Throwing an Exception in a Function EXAMPLE: Returning the High Score Exception Specification PITFALL: Exception Specification in Derived Classes 18.2 PROGRAMMING 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 19 Standard Template Library 19.1 ITERATORS Iterator Basics PITFALL: Compiler Problems TIP: Use auto to Simplify Variable Declarations Kinds of Iterators Constant and Mutable Iterators Reverse Iterators Other Kinds of Iterators 19.2 CONTAINERS Sequential Containers PITFALL: Iterators and Removing Elements TIP: Type Definitions in Containers The Container Adapters stack and queue PITFALL: Underlying Containers The Associative Containers set and map Efficiency TIP: Use Initialization, Ranged for, and auto with Containers 19.3 GENERIC ALGORITHMS Running Times and Big-O Notation Container Access Running Times Nonmodifying Sequence Algorithms Modifying Sequence Algorithms Set Algorithms Sorting Algorithms Appendix 1 C++ Keywords Appendix 2 Precedence of Operators Appendix 3 The ASCII Character Set Appendix 4 Some Library Functions Appendix 5 Old and New Header Files Appendix 6 Additional C++11 Language Features

Index A B C D E F G H I K L M N O P Q R S T U V W Z