100% found this document useful (2 votes)
144 views40 pages

C Programming From Problem Analysis To Program Design 6th Edition D. S. Malik Instant Download

Ebook access

Uploaded by

yassygx093
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
144 views40 pages

C Programming From Problem Analysis To Program Design 6th Edition D. S. Malik Instant Download

Ebook access

Uploaded by

yassygx093
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

C Programming From Problem Analysis to Program

Design 6th Edition D. S. Malik install download

https://ebookname.com/product/c-programming-from-problem-
analysis-to-program-design-6th-edition-d-s-malik/

Get the full ebook with Bonus Features for a Better Reading Experience on ebookname.com
Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

C Programming From Problem Analysis to Program Design


2nd Edition Barbara Doyle

https://ebookname.com/product/c-programming-from-problem-
analysis-to-program-design-2nd-edition-barbara-doyle/

C Programming From Problem Analysis to Program Design


5th Edition Barbara Doyle

https://ebookname.com/product/c-programming-from-problem-
analysis-to-program-design-5th-edition-barbara-doyle/

C Programming Program Design Including Data Structures


Fourth edition D. S. Malik

https://ebookname.com/product/c-programming-program-design-
including-data-structures-fourth-edition-d-s-malik/

Global divas Filipino gay men in the diaspora 3. print


Edition Manalansan

https://ebookname.com/product/global-divas-filipino-gay-men-in-
the-diaspora-3-print-edition-manalansan/
Panzer Commander The Memoirs of Colonel Hans Von Luck
World War II Library Hans Von Luck

https://ebookname.com/product/panzer-commander-the-memoirs-of-
colonel-hans-von-luck-world-war-ii-library-hans-von-luck/

Western Fruit Gardening Reid M. Brooks

https://ebookname.com/product/western-fruit-gardening-reid-m-
brooks/

Generalized Sturmians and atomic spectra 1st Edition


James Avery And John Avery

https://ebookname.com/product/generalized-sturmians-and-atomic-
spectra-1st-edition-james-avery-and-john-avery/

Islands in the City West Indian Migration to New York


1st Edition Nancy Foner

https://ebookname.com/product/islands-in-the-city-west-indian-
migration-to-new-york-1st-edition-nancy-foner/

Ice Anna Kavan

https://ebookname.com/product/ice-anna-kavan/
On Transitions from Group Care 1st Edition Richard A.
Epstein

https://ebookname.com/product/on-transitions-from-group-care-1st-
edition-richard-a-epstein/
C++ PROGRAMMING:
FROM PROBLEM ANALYSIS TO PROGRAM DESIGN

SIXTH EDITION

D.S. MALIK

Australia  Brazil  Japan  Korea  Mexico  Singapore  Spain  United Kingdom  United States
This is an electronic version of the print textbook. Due to electronic rights restrictions,
some third party content may be suppressed. Editorial review has deemed that any suppressed
content does not materially affect the overall learning experience. The publisher reserves the right
to remove content from this title at any time if subsequent rights restrictions require it. For
valuable information on pricing, previous editions, changes to current editions, and alternate
formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.
C++ Programming: From Problem Analysis
to Program Design, Sixth Edition For product information and technology assistance, contact us at
Cengage Learning Customer & Sales Support,
D.S. Malik www.cengage.com/support
For permission to use material from this text or product,
Executive Editor: Marie Lee submit all requests online at www.cengage.com/permissions
Acquisitions Editor: Brandi Shailer Further permissions questions can be emailed to
Senior Product Manager: Alyssa Pratt [email protected]
Associate Product Manager: Stephanie
Lorenz Library of Congress Control Number:
Content Project Manager: Matthew ISBN- : -- - -
Hutchinson
Cengage Learning
Art Director: Faith Brosnan
Channel Center Street
Print Buyer: Julio Esperas Boston, MA
Cover Designer: Roycroft Design/ USA
www.roycroftdesign.com Some of the product names and company names used in this
Cover Photo: ª Masterfile Royalty Free book have been used for identification purposes only and may
Proofreader: Andrea Schein be trademarks or registered trademarks of their respective
manufacturers and sellers.
Indexer: Elizabeth Cunningham
Compositor: Integra Software Services Any fictional data related to persons or companies or URLs used
throughout this book is intended for instructional purposes only.
At the time this book was printed, any such data was fictional
and not belonging to any real persons or companies.
ª Cengage Learning
Cengage Learning reserves the right to revise this publication
ALL RIGHTS RESERVED. No part of this work
and make changes from time to time in its content without
covered by the copyright herein may be
notice.
reproduced, transmitted, stored or used in any
form or by any means graphic, electronic, or The programs in this book are for instructional purposes only.
mechanical, including but not limited to They have been tested with care, but are not guaranteed
photocopying, recording, scanning, digitizing, for any particular intent beyond educational purposes. The
taping, Web distribution, information author and the publisher do not offer any warranties or
networks, or information storage and retrieval representations, nor do they accept any liabilities with respect
systems, except as permitted under Section to the programs.
or of the United States Copyright
Cengage Learning is a leading provider of customized
Act, without the prior written permission of
learning solutions with office locations around the globe,
the publisher.
including Singapore, the United Kingdom, Australia, Mexico,
Brazil and Japan. Locate your local office at:
www.cengage.com/global
Cengage Learning products are represented in Canada
by Nelson Education, Ltd.
To learn more about Cengage Learning, visit
www.cengage.com
Purchase any of our products at your local college store or at
our preferred online store www.CengageBrain.com

Printed in the United States of America


1 2 3 4 5 6 7 16 17 16 15 14 13 12
TO

My Daughter

Shelly Malik
This page intentionally left blank
B RIEF C ONTENTS

PREFACE xxix

1. An Overview of Computers and Programming Languages 1

2. Basic Elements of C++ 27

3. Input/Output 121

4. Control Structures I (Selection) 183

5. Control Structures II (Repetition) 259

6. User-Defined Functions 335

7. User-Defined Simple Data Types, Namespaces,


and the string Type 451

8. Arrays and Strings 505

9. Records (structs) 591

10. Classes and Data Abstraction 629

11. Inheritance and Composition 709

12. Pointers, Classes, Virtual Functions, and Abstract Classes 781

13. Overloading and Templates 853

14. Exception Handling 943

15. Recursion 985

16. Searching, Sorting, and the vector Type 1015

17. Linked Lists 1057

18. Stacks and Queues 1149


vi | C++ Programming: From Problem Analysis to Program Design, Sixth Edition

APPENDIX A Reserved Words 1249

APPENDIX B Operator Precedence 1251

APPENDIX C Character Sets 1253

APPENDIX D Operator Overloading 1257

APPENDIX E Additional C++ Topics 1259

APPENDIX F Header Files 1281

APPENDIX G Memory Size on a System and Random


Number Generator 1291

APPENDIX H Standard Template Library (STL) 1293

APPENDIX I Answers to Odd-Numbered Exercises 1335

INDEX 1371
TABLE OF C ONTENTS

Preface xxix

AN OVERVIEW OF COMPUTERS AND PROGRAMMING


1 LANGUAGES 1
Introduction 2

A Brief Overview of the History of Computers 2

Elements of a Computer System 3


Hardware 4
Central Processing Unit and Main Memory 4
Input /Output Devices 5
Software 6

The Language of a Computer 6

The Evolution of Programming Languages 8

Processing a C++ Program 10

Programming with the Problem


Analysis–Coding–Execution Cycle 12

Programming Methodologies 20
Structured Programming 20
Object-Oriented Programming 20

ANSI/ISO Standard C++ 22

Quick Review 22

Exercises 24
viii | C++ Programming: From Problem Analysis to Program Design, Sixth Edition

BASIC ELEMENTS OF C++ 27


2 A Quick Look at a C++ Program 28

The Basics of a C++ Program 34


Comments 34
Special Symbols 35
Reserved Words (Keywords) 36
Identifiers 36
Whitespaces 37

Data Types 37
Simple Data Types 38
Floating-Point Data Types 41

Data Types and Variables 42

Arithmetic Operators, Operator Precedence,


and Expressions 43
Order of Precedence 46
Expressions 48
Mixed Expressions 49

Type Conversion (Casting) 51

string Type 53

Variables, Assignment Statements, and Input


Statements 54
Allocating Memory with Constants and Variables 54
Putting Data into Variables 57
Assignment Statement 57
Saving and Using the Value of an Expression 61
Declaring and Initializing Variables 62
Input (Read) Statement 63
Variable Initialization 66

Increment and Decrement Operators 70

Output 72

Preprocessor Directives 79
namespace and Using cin and cout in a Program 80
Using the string Data Type in a Program 81
Table of Contents | ix

Creating a C++ Program 81

Debugging: Understanding and Fixing Syntax Errors 85

Program Style and Form 89


Syntax 89
Use of Blanks 90
Use of Semicolons, Brackets, and Commas 90
Semantics 90
Naming Identifiers 90
Prompt Lines 91
Documentation 92
Form and Style 92

More on Assignment Statements 94

Programming Example: Convert Length 96

Programming Example: Make Change 99

Quick Review 103

Exercises 105

Programming Exercises 114

INPUT/OUTPUT 121
3 I/O Streams and Standard I/O Devices 122
cin and the Extraction Operator >> 123

Using Predefined Functions in a Program 128


cin and the get Function 131
cin and the ignore Function 133
The putback and peek Functions 134
The Dot Notation between I/O Stream Variables and I/O
Functions: A Precaution 137

Input Failure 138


The clear Function 140
x | C++ Programming: From Problem Analysis to Program Design, Sixth Edition

Output and Formatting Output 142


setprecision Manipulator 142
fixed Manipulator 143
showpoint Manipulator 144
setw 147

Additional Output Formatting Tools 149


setfill Manipulator 149
left and right Manipulators 151

Input/Output and the string Type 153

Debugging: Understanding Logic Errors and Debugging


with cout Statements 154

File Input/Output 157

Programming Example: Movie Tickets Sale and


Donation to Charity 161

Programming Example: Student Grade 167

Quick Review 170

Exercises 171

Programming Exercises 177

CONTROL STRUCTURES I (SELECTION) 183


4 Control Structures 184

Relational Operators 185


Relational Operators and Simple Data Types 186
Comparing Characters 187
Relational Operators and the string Type 188

Logical (Boolean) Operators and Logical Expressions 190


Order of Precedence 192
int Data Type and Logical (Boolean) Expressions 195
bool Data Type and Logical (Boolean) Expressions 196

Selection: if and if...else 196


One-Way Selection 197
Two-Way Selection 200
Table of Contents | xi

Compound (Block of) Statements 203


Multiple Selections: Nested if 204
Comparing if...else Statements with a Series of if
Statements 206
Short-Circuit Evaluation 207
Comparing Floating-Point Numbers for Equality:
A Precaution 208
Associativity of Relational Operators: A Precaution 209
Avoiding Bugs by Avoiding Partially Understood Concepts
and Techniques 211
Input Failure and the if Statement 214
Confusion between the Equality Operator (==) and the
Assignment Operator (=) 217
Conditional Operator (?:) 219
Program Style and Form (Revisited): Indentation 219

Using Pseudocode to Develop, Test, and Debug


a Program 220

switch Structures 223


Avoiding Bugs by Avoiding Partially Understood Concepts
and Techniques (Revisited) 229

Terminating a Program with the assert Function 231

Programming Example: Cable Company Billing 233

Quick Review 239

Exercises 240

Programming Exercises 251

CONTROL STRUCTURES II (REPETITION) 259


5 Why Is Repetition Needed? 260

while Looping (Repetition) Structure 261


Designing while Loops 263
Case 1: Counter-Controlled while Loops 264
Case 2: Sentinel-Controlled while Loops 268
Telephone Digits 271
xii | C++ Programming: From Problem Analysis to Program Design, Sixth Edition

Case 3: Flag-Controlled while Loops 273


Number Guessing Game 274
Case 4: EOF-Controlled while Loops 277
eof Function 277
More on Expressions in while Statements 282

Programming Example: Fibonacci Number 283

for Looping (Repetition) Structure 287

Programming Example: Classifying Numbers 295

do...while Looping (Repetition) Structure 298


Divisibility Test by 3 and 9 301
Choosing the Right Looping Structure 303

break and continue Statements 303

Nested Control Structures 305

Avoiding Bugs by Avoiding Patches 310

Debugging Loops 313

Quick Review 314

Exercises 315

Programming Exercises 328

USER-DEFINED FUNCTIONS 335


6 Predefined Functions 336

User-Defined Functions 340

Value-Returning Functions 341


Syntax: Value-Returning function 343
Syntax: Formal Parameter List 343
Function Call 343
Syntax: Actual Parameter List 344
return Statement 344
Syntax: return Statement 344
Function Prototype 348
Syntax: Function Prototype 349
Table of Contents | xiii

Value-Returning Functions: Some Peculiarities 350


More Examples of Value-Returning Functions 352
Flow of Execution 361

Void Functions 364

Value Parameters 370

Reference Variables as Parameters 371


Calculate Grade 372

Value and Reference Parameters and Memory Allocation 376

Reference Parameters and Value-Returning Functions 386

Scope of an Identifier 386

Global Variables, Named Constants, and Side Effects 390

Static and Automatic Variables 395

Debugging: Using Drivers and Stubs 396

Function Overloading: An Introduction 399

Functions with Default Parameters 400

Programming Example: Classify Numbers 403

Programming Example: Data Comparison 408

Quick Review 418

Exercises 422

Programming Exercises 436

USER-DEFINED SIMPLE DATA TYPES,


7 NAMESPACES, AND THE STRING TYPE 451

Enumeration Type 452


Declaring Variables 454
Assignment 454
Operations on Enumeration Types 455
Relational Operators 455
Input /Output of Enumeration Types 456
xiv | C++ Programming: From Problem Analysis to Program Design, Sixth Edition

Functions and Enumeration Types 459


Declaring Variables When Defining the Enumeration Type 460
Anonymous Data Types 461
typedef Statement 461

Programming Example: The Game of Rock, Paper,


and Scissors 463

Namespaces 471

string Type 476


Additional string Operations 480

Programming Example: Pig Latin Strings 490

Quick Review 494

Exercises 496

Programming Exercises 501

ARRAYS AND STRINGS 505


8 Arrays 507
Accessing Array Components 509
Processing One-Dimensional Arrays 511
Array Index Out of Bounds 515
Array Initialization During Declaration 516
Partial Initialization of Arrays During Declaration 516
Some Restrictions on Array Processing 517
Arrays as Parameters to Functions 518
Constant Arrays as Formal Parameters 519
Base Address of an Array and Array in Computer Memory 521
Functions Cannot Return a Value of the Type Array 524
Integral Data Type and Array Indices 526
Other Ways to Declare Arrays 527

Searching an Array for a Specific Item 527


Selection Sort 530

C-Strings (Character Arrays) 535


String Comparison 537
Reading and Writing Strings 539
Table of Contents | xv

String Input 539


String Output 540
Specifying Input/Output Files at Execution Time 541
string Type and Input/Output Files 541

Parallel Arrays 542

Two- and Multidimensional Arrays 543


Accessing Array Components 545
Two-Dimensional Array Initialization During Declaration 546
Two-Dimensional Arrays and Enumeration Types 546
Initialization 549
Print 550
Input 550
Sum by Row 550
Sum by Column 551
Largest Element in Each Row and Each Column 551
Passing Two-Dimensional Arrays as Parameters to Functions 552
Arrays of Strings 555
Arrays of Strings and the string Type 555
Arrays of Strings and C-Strings (Character Arrays) 555
Another Way to Declare a Two-Dimensional Array 556
Multidimensional Arrays 557

Programming Example: Code Detection 559

Programming Example: Text Processing 565

Quick Review 572

Exercises 573

Programming Exercises 584

RECORDS ( STRUCTS) 591


9
Records ( structs) 592
Accessing struct Members 594
Assignment 596
Comparison (Relational Operators) 597
Input /Output 598
xvi | C++ Programming: From Problem Analysis to Program Design, Sixth Edition

struct Variables and Functions 598


Arrays versus structs 599
Arrays in structs 600
structs in Arrays 602
structs within a struct 604

Programming Example: Sales Data Analysis 608

Quick Review 622

Exercises 622

Programming Exercises 626

CLASSES AND DATA ABSTRACTION 629


10
Classes 630
Unified Modeling Language Class Diagrams 634
Variable (Object) Declaration 634
Accessing Class Members 635
Built-in Operations on Classes 636
Assignment Operator and Classes 637
Class Scope 637
Functions and Classes 638
Reference Parameters and Class Objects (Variables) 638
Implementation of Member Functions 639
Accessor and Mutator Functions 644
Order of public and private Members of a Class 647
Constructors 649
Invoking a Constructor 651
Invoking the Default Constructor 651
Invoking a Constructor with Parameters 651
Constructors and Default Parameters 654
Classes and Constructors: A Precaution 654
Arrays of Class Objects (Variables) and Constructors 655
Destructors 657

Data Abstraction, Classes, and Abstract Data Types 658

A struct Versus a class 660


Table of Contents | xvii

Information Hiding 661

Executable Code 665

More Examples of Classes 667

Static Members of a Class 673

Programming Example: Juice Machine 679

Quick Review 693

Exercises 695

Programming Exercises 703

INHERITANCE AND COMPOSITION 709


11
Inheritance 710
Redefining (Overriding) Member Functions
of the Base Class 713
Constructors of Derived and Base Classes 720
Destructors in a Derived Class 729
Multiple Inclusions of a Header File 730
C++ Stream Classes 731
Protected Members of a Class 733
Inheritance as public, protected, or private 733
(Accessing protected Members in the Derived Class) 734

Composition (Aggregation) 737

Object-Oriented Design (OOD) and Object-Oriented


Programming (OOP) 742
Identifying Classes, Objects, and Operations 744

Programming Example: Grade Report 745

Quick Review 766

Exercises 767

Programming Exercises 776


xviii | C++ Programming: From Problem Analysis to Program Design, Sixth Edition

POINTERS, CLASSES, VIRTUAL FUNCTIONS,


12 AND ABSTRACT CLASSES 781
Pointer Data Type and Pointer Variables 782
Declaring Pointer Variables 782

Address of Operator (&) 783

Dereferencing Operator (*) 784

Classes, Structs, and Pointer Variables 789

Initializing Pointer Variables 792

Dynamic Variables 792


Operator new 793
Operator delete 794

Operations on Pointer Variables 798

Dynamic Arrays 800


Functions and Pointers 803
Pointers and Function Return Values 803
Dynamic Two-Dimensional Arrays 804

Shallow versus Deep Copy and Pointers 807

Classes and Pointers: Some Peculiarities 809


Destructor 809
Assignment Operator 811
Copy Constructor 812

Inheritance, Pointers, and Virtual Functions 819


Classes and Virtual Destructors 826

Abstract Classes and Pure Virtual Functions 826

Address of Operator and Classes 835

Quick Review 837

Exercises 840

Programming Exercises 849


Table of Contents | xix

OVERLOADING AND TEMPLATES 853


13
Why Operator Overloading Is Needed 854

Operator Overloading 855


Syntax for Operator Functions 856
Overloading an Operator: Some Restrictions 856
Pointer this 857
Friend Functions of Classes 861
Operator Functions as Member Functions and Nonmember
Functions 864
Overloading Binary Operators 867
Overloading the Stream Insertion (<<) and Extraction (>>)
Operators 873
Overloading the Assignment Operator (=) 878
Overloading Unary Operators 886
Operator Overloading: Member versus Nonmember 892
Classes and Pointer Member Variables (Revisited) 893
Operator Overloading: One Final Word 893

Programming Example: clockType 893

Programming Example: Complex Numbers 902

Overloading the Array Index (Subscript) Operator ([]) 907

Programming Example: newString 909

Function Overloading 915

Templates 916
Function Templates 916
Class Templates 918

Quick Review 926

Exercises 928

Programming Exercises 934


xx | C++ Programming: From Problem Analysis to Program Design, Sixth Edition

EXCEPTION HANDLING 943


14
Handling Exceptions within a Program 944
C++ Mechanisms of Exception Handling 948
try/catch Block 948
Using C++ Exception Classes 955

Creating Your Own Exception Classes 959


Rethrowing and Throwing an Exception 968

Exception-Handling Techniques 972


Terminate the Program 972
Fix the Error and Continue 972
Log the Error and Continue 974

Stack Unwinding 974

Quick Review 978

Exercises 980

Programming Exercises 984

RECURSION 985
15
Recursive Definitions 986
Direct and Indirect Recursion 988
Infinite Recursion 988

Problem Solving Using Recursion 989


Tower of Hanoi: Analysis 999

Recursion or Iteration? 999

Programming Example: Converting a Number from


Binary to Decimal 1001

Programming Example: Converting a Number from


Decimal to Binary 1005

Quick Review 1008

Exercises 1009

Programming Exercises 1012


Table of Contents | xxi

SEARCHING, SORTING, AND THE VECTOR TYPE 1015


16 List Processing 1016
Searching 1016
Bubble Sort 1017
Insertion Sort 1021
Binary Search 1025
Performance of Binary Search 1028

vector Type (class) 1029

Programming Example: Election Results 1034

Quick Review 1049

Exercises 1050

Programming Exercises 1053

LINKED LISTS 1057


17
Linked Lists 1058
Linked Lists: Some Properties 1059
Deletion 1065
Building a Linked List 1066

Linked List as an ADT 1071


Structure of Linked List Nodes 1072
Member Variables of the class linkedListType 1072
Linked List Iterators 1073
Print the List 1079
Length of a List 1079
Retrieve the Data of the First Node 1080
Retrieve the Data of the Last Node 1080
Begin and End 1080
Copy the List 1081
Destructor 1082
Copy Constructor 1082
Overloading the Assignment Operator 1083
xxii | C++ Programming: From Problem Analysis to Program Design, Sixth Edition

Unordered Linked Lists 1083


Search the List 1084
Insert the First Node 1085
Insert the Last Node 1086
Header File of the Unordered Linked List 1091

Ordered Linked Lists 1092


Search the List 1093
Insert a Node 1094
Insert First and Insert Last 1098
Delete a Node 1099
Header File of the Ordered Linked List 1100

Print a Linked List in Reverse Order


(Recursion Revisited) 1103
printListReverse 1105

Doubly Linked Lists 1106


Default Constructor 1109
isEmptyList 1109
Destroy the List 1109
Initialize the List 1110
Length of the List 1110
Print the List 1110
Reverse Print the List 1110
Search the List 1111
First and Last Elements 1111

Circular Linked Lists 1117

Programming Example: DVD Store 1118

Quick Review 1138

Exercises 1138

Programming Exercises 1144


Table of Contents | xxiii

STACKS AND QUEUES 1149


18
Stacks 1150
Stack Operations 1152

Implementation of Stacks as Arrays 1154


Initialize Stack 1157
Empty Stack 1158
Full Stack 1158
Push 1158
Return the Top Element 1160
Pop 1160
Copy Stack 1162
Constructor and Destructor 1162
Copy Constructor 1163
Overloading the Assignment Operator (=) 1163
Stack Header File 1164

Programming Example: Highest GPA 1168

Linked Implementation of Stacks 1172


Default Constructor 1175
Empty Stack and Full Stack 1175
Initialize Stack 1176
Push 1176
Return the Top Element 1178
Pop 1178
Copy Stack 1180
Constructors and Destructors 1181
Overloading the Assignment Operator (=) 1181
Stack as Derived from the class unorderedLinkedList 1184

Application of Stacks: Postfix Expressions Calculator 1185


Main Algorithm 1188
Function evaluateExpression 1188
Function evaluateOpr 1190
Function discardExp 1192
Function printResult 1192
xxiv | C++ Programming: From Problem Analysis to Program Design, Sixth Edition

Removing Recursion: Nonrecursive Algorithm to


Print a Linked List Backward 1195

Queues 1199
Queue Operations 1200
Implementation of Queues as Arrays 1202
Linked Implementation of Queues 1211
Queue Derived from the
class unorderedLinkedListType 1216

Application of Queues: Simulation 1217


Designing a Queuing System 1218
Customer 1219
Server 1222
Server List 1225
Waiting Customers Queue 1230
Main Program 1232

Quick Review 1237

Exercises 1238

Programming Exercises 1245

APPENDIX A: RESERVED WORDS 1249

APPENDIX B: OPERATOR PRECEDENCE 1251

APPENDIX C: CHARACTER SETS 1253


ASCII (American Standard Code for Information
Interchange) 1253

EBCDIC (Extended Binary Coded Decimal


Interchange Code) 1254

APPENDIX D: OPERATOR OVERLOADING 1257


Table of Contents | xxv

APPENDIX E: ADDITIONAL C++ TOPICS 1259


Binary (Base 2) Representation of a Nonnegative
Integer 1259
Converting a Base 10 Number to a Binary Number
(Base 2) 1259
Converting a Binary Number (Base 2) to Base 10 1261
Converting a Binary Number (Base 2) to Octal (Base 8)
and Hexadecimal (Base 16) 1262

More on File Input/Output 1264


Binary Files 1264
Random File Access 1270

Naming Conventions of Header Files in ANSI/ISO


Standard C++ and Standard C++ 1278

APPENDIX F: HEADER FILES 1281


Header File cassert (assert.h) 1281

Header File cctype (ctype.h) 1282

Header File cfloat (float.h) 1283

Header File climits (limits.h) 1284

Header File cmath (math.h) 1286


Header File cstddef (stddef.h) 1287
Header File cstring (string.h) 1287

APPENDIX G: MEMORY SIZE ON A SYSTEM AND


RANDOM NUMBER GENERATOR 1291
Random Number Generator 1292

APPENDIX H: STANDARD TEMPLATE LIBRARY (STL) 1293


Components of the STL 1293

Container Types 1294


Sequence Containers 1294
Sequence Container: Vectors 1294
xxvi | C++ Programming: From Problem Analysis to Program Design, Sixth Edition

Member Functions Common to All Containers 1303


Member Functions Common to Sequence Containers 1305
copy Algorithm 1306
Sequence Container: deque 1310
Sequence Container: list 1313

Iterators 1318
IOStream Iterators 1319
Container Adapters 1319

Algorithms 1323
STL Algorithm Classification 1323
STL Algorithms 1326
Functions fill and fill_n 1326
Functions find and find_if 1328
Functions remove and replace 1329
Functions search, sort, and binary_search 1331

APPENDIX I: ANSWERS TO ODD-NUMBERED


EXERCISES 1335
Chapter 1 1335

Chapter 2 1338

Chapter 3 1340

Chapter 4 1341

Chapter 5 1344

Chapter 6 1347

Chapter 7 1350

Chapter 8 1351

Chapter 9 1353

Chapter 10 1354

Chapter 11 1358

Chapter 12 1360
Table of Contents | xxvii

Chapter 13 1361

Chapter 14 1362

Chapter 15 1364

Chapter 16 1364

Chapter 17 1366

Chapter 18 1367

INDEX 1371
This page intentionally left blank
Exploring the Variety of Random
Documents with Different Content
University off Toronto Library DO NOT REMOVE THE CARD
FROM THIS POCKET Acme Library Card Pocket LOWE-MARTIN CO.
UMmro
The text on this page is estimated to be only 0.94%
accurate

";f;.*^«
The text on this page is estimated to be only 0.06%
accurate

**'^#'^:*5' Jt^ rn ;«--,» ■»*:i-jyg:-:ja|«.'^■;*■• 'f^' 1^


^%.f«^%ii^ ■^1^-^^^ r^^^t *^'^^ ■«S«J A'
The text on this page is estimated to be only 1.24%
accurate

'Jl 1 « ' - ^ pp-> a* •*'^ ff^' «irf' I *« "^..^ -« "1* '1^ >i:
rf^;*f*5i>pfi « ^il'iw pd ^^":«. •i6^-,,iJps Mzm, //'
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like