A First Book of C 4th Edition by Gary J Bronson ISBN 1111531005 9781111531003 - Download The Ebook Now and Read Anytime, Anywhere
A First Book of C 4th Edition by Gary J Bronson ISBN 1111531005 9781111531003 - Download The Ebook Now and Read Anytime, Anywhere
_____ Follow the link below to get your download now _____
https://ebookball.com/product/a-first-book-of-c-4th-edition-
by-gary-j-bronson-isbn-1111531005-9781111531003-10080/
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
C++
A First Book of
Fourth Edition
Gary Bronson
Fairleigh Dickenson University
Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States
The programs in this book are for instruc- Purchase any of our products at your local college store or at our preferred
tional purposes only. online store www.cengagebrain.com
Part One
Fundamentals of C++ Programming 1
Chapter 1
Getting Started 3
Chapter 2
Data Types, Declarations, and Displays 37
Chapter 3
Assignment and Interactive Input 79
Chapter 4
Selection 137
Chapter 5
Repetition 179
Chapter 6
Modularity Using Functions 225
Chapter 7
Arrays 291
Chapter 8
Arrays and Pointers 341
Chapter 9
I/O Streams and Data Files 387
Part Two
Object-Oriented Programming 431
Chapter 10
Introduction to Classes 433
Chapter 11
Adding Functionality to Your Classes 491
Chapter 12
Extending Your Classes 539
Chapter 13
The Standard Template Library 573
Part Three
Additional Topics 603
Chapter 14
The string Class and Exception Handling 605
Chapter 15
Strings as Character Arrays 665
Chapter 16
Data Structures 701
Appendixes
Appendix A
Operator Precedence Table 729
Appendix B
ASCII Character Codes 731
Appendix C
Bit Operations Online Only
Appendix D
Floating-Point Number Storage Online Only
Appendix E
Solutions to Selected Exercises 733
Index 753
Part One
Fundamentals of C++ Programming 1
Chapter 1
Getting Started 3
1.1 Introduction to Programming 3
Algorithms and Procedures 5
Classes and Objects 9
Program Translation 9
1.2 Function and Class Names 12
The main() Function 15
1.3 The cout Object 18
1.4 Programming Style 22
Comments 23
1.5 Common Programming Errors 26
1.6 Chapter Summary 27
1.7 Chapter Supplement: Software Development 28
Phase I: Development and Design 28
Phase II: Documentation 32
Phase III: Maintenance 33
Backup 33
Chapter 2
Data Types, Declarations, and Displays 37
2.1 Data Types 37
Integer Data Types 38
Determining Storage Size 42
Floating-Point Types 44
Exponential Notation 45
2.2 Arithmetic Operations 48
Expression Types 51
Integer Division 52
Negation 52
Operator Precedence and Associativity 53
2.3 Variables and Declarations 57
Declaration Statements 59
Multiple Declarations 62
Memory Allocation 64
Contents v
Chapter 3
Assignment and Interactive Input 79
3.1 Assignment Operators 79
Coercion 84
Assignment Variations 85
Accumulating 86
Counting 88
3.2 Formatted Output 93
The setiosflags() Manipulator 97
Hexadecimal and Octal I/O 99
3.3 Mathematical Library Functions 106
Casts 111
3.4 Interactive Keyboard Input 117
A First Look at User-Input Validation 121
3.5 Symbolic Constants 127
Placement of Statements 128
3.6 Common Programming Errors 132
3.7 Chapter Summary 132
3.8 Chapter Supplement: Errors, Testing, and Debugging 133
Compile-Time and Runtime Errors 134
Syntax and Logic Errors 134
Testing and Debugging 135
Chapter 4
Selection 137
4.1 Relational Expressions 137
Logical Operators 139
A Numerical Accuracy Problem 142
4.2 The if-else Statement 143
Compound Statements 146
Block Scope 148
One-Way Selection 149
Problems Associated with the if-else Statement 151
4.3 Nested if Statements 158
The if-else Chain 159
Chapter 5
Repetition 179
5.1 The while Statement 180
5.2 Interactive while Loops 188
Sentinels 194
break and continue Statements 197
The Null Statement 198
5.3 The for Statement 201
Interactive for Loops 208
Nested Loops 209
5.4 The do-while Statement 217
Validity Checks 219
5.5 Common Programming Errors 220
5.6 Chapter Summary 222
Chapter 6
Modularity Using Functions 225
6.1 Function and Parameter Declarations 226
Function Prototypes 227
Calling a Function 228
Defining a Function 229
Placement of Statements 234
Function Stubs 234
Functions with Empty Parameter Lists 235
Default Arguments 236
Reusing Function Names (Overloading) 237
Function Templates 238
6.2 Returning a Single Value 244
Inline Functions 250
Templates with a Return Value 251
6.3 Returning Multiple Values 257
Passing and Using Reference Parameters 258
6.4 Variable Scope 267
Scope Resolution Operator 271
Misuse of Globals 272
Chapter 7
Arrays 291
7.1 One-Dimensional Arrays 292
Input and Output of Array Values 296
7.2 Array Initialization 303
7.3 Arrays as Arguments 307
7.4 Two-Dimensional Arrays 313
Larger Dimensional Arrays 319
7.5 Common Programming Errors 323
7.6 Chapter Summary 324
7.7 Chapter Supplement: Searching and Sorting Methods 325
Search Algorithms 325
Sort Algorithms 333
Chapter 8
Arrays and Pointers 341
8.1 Introduction to Pointers 341
Storing Addresses 344
Using Addresses 345
Declaring Pointers 346
References and Pointers 348
8.2 Array Names as Pointers 354
Dynamic Array Allocation 360
8.3 Pointer Arithmetic 364
Pointer Initialization 368
8.4 Passing Addresses 369
Passing Arrays 374
Advanced Pointer Notation 378
8.5 Common Programming Errors 383
8.6 Chapter Summary 385
Chapter 9
I/O Streams and Data Files 387
9.1 I/O File Stream Objects and Methods 388
Files 388
File Stream Objects 389
File Stream Methods 390
9.2 Reading and Writing Text Files 403
Reading from a Text File 406
Standard Device Files 411
Other Devices 412
9.3 Random File Access 416
9.4 File Streams as Function Arguments 419
9.5 Common Programming Errors 423
9.6 Chapter Summary 423
9.7 Chapter Supplement: The iostream Class Library 426
File Stream Transfer Mechanism 426
Components of the iostream Class Library 426
In-Memory Formatting 428
Part Two
Object-Oriented Programming 431
Chapter 10
Introduction to Classes 433
10.1 Object-Based Programming 433
A Class Is a Plan 436
From Recipe to Class 436
10.2 Creating Your Own Classes 439
Class Construction 440
Terminology 448
10.3 Constructors 452
Calling Constructors 454
Overloaded and Inline Constructors 455
Destructors 458
Arrays of Objects 459
10.4 Examples 463
Example 1: Constructing a Room Object 463
Example 2: Constructing an Elevator Object 467
Chapter 11
Adding Functionality to Your Classes 491
11.1 Creating Class Operators 491
Assignment Operator 499
Copy Constructors 500
Base/Member Initialization 503
Operator Functions as Friends 504
11.2 How Methods Are Shared 508
The this Pointer 509
The Assignment Operator Revisited 511
Objects as Arguments 514
Notation 515
11.3 Data Type Conversions 519
Built-in to Built-in Conversion 520
Class to Built-in Conversion 520
Built-in to Class Conversion 522
Class to Class Conversion 525
11.4 Two Useful Alternatives: operator() and operator[] 529
11.5 Common Programming Errors 533
11.6 Chapter Summary 533
11.7 Chapter Supplement: Insides and Outsides 535
Abstraction and Encapsulation 537
Code Extensibility 537
Chapter 12
Extending Your Classes 539
12.1 Class Inheritance 540
Access Specifications 541
12.2 Polymorphism 547
12.3 Dynamic Object Creation and Deletion 552
12.4 Pointers as Class Members 562
Assignment Operators and Copy Constructors Reconsidered 565
Chapter 13
The Standard Template Library 573
13.1 The Standard Template Library 574
13.2 Linked Lists 579
Using the STL list Class 581
Using User-Defined Objects 586
13.3 Stacks 590
Stack Implementation with the deque Class 592
13.4 Queues 598
Queue Implementation with the deque Class 599
13.5 Common Programming Errors 602
13.6 Chapter Summary 602
Part Three
Additional Topics 603
Chapter 14
The string Class and Exception Handling 605
14.1 The string Class 606
string Class Functions 607
String Input and Output 609
String Processing 613
14.2 Character Manipulation Methods 622
Character I/O 627
A Second Look at User-Input Validation 632
14.3 Exception Handling 634
14.4 Exceptions and File Checking 640
Opening Multiple Files 644
14.5 Input Data Validation 649
14.6 Common Programming Errors 656
14.7 Chapter Summary 656
14.8 Chapter Supplement: Namespaces and Creating a Personal Library 657
Chapter 15
Strings as Character Arrays 665
15.1 C-String Fundamentals 666
C-String Input and Output 666
C-String Processing 670
15.2 Pointers and C-String Library Functions 675
Library Functions 681
Character-Handling Functions 684
Conversion Functions 688
15.3 C-String Definitions and Pointer Arrays 691
Pointer Arrays 693
15.4 Common Programming Errors 698
15.5 Chapter Summary 698
Chapter 16
Data Structures 701
16.1 Single Structures 702
16.2 Arrays of Structures 708
16.3 Structures as Function Arguments 712
Passing a Pointer 716
Returning Structures 718
16.4 Dynamic Structure Allocation 721
16.5 Unions 724
16.6 Common Programming Errors 727
16.7 Chapter Summary 728
Appendixes
Appendix A
Operator Precedence Table 729
Appendix B
ASCII Character Codes 731
Appendix C
Bit Operations Online Only
Appendix D
Floating-Point Number Storage Online Only
Appendix E
Solutions to Selected Exercises 733
Index 753
The main goal of this fourth edition of A First Book of C++ remains the same as in previous
editions: to introduce, develop, and reinforce well-organized programming skills using C++.
All topics are presented in a clear, unambiguous, and accessible manner to beginning students.
Students should be familiar with fundamental algebra, but no other prerequisites are assumed.
Therefore, like the first three editions, this new edition begins by providing a strong foun-
dation in structured programming. This foundation is then expanded to an object-oriented
design and programming approach in a pedagogically sound, achievable progression. In addi-
tion to a number of minor changes throughout the book, the major changes in this edition are
the following:
• Part I has been restructured to include arrays, files, and pointers, so it can be used as
the basis for a complete introductory semester course in C++.
• The four chapters covering object-oriented programming have been revised and
moved to Part II so that they form a logical continuation from structured program-
ming to object-oriented programming.
• More than 50 new exercises have been added, and all exercises are labeled to indicate
their function (Review, Practice, Program, Modify, Debug, Desk check, or For thought).
• Three new Chapter Supplements have been added to introduce the fundamentals of
object-oriented design and the Unified Modeling Language (UML).
• A complete set of case studies has been added and is available on the Cengage Web
site, login.cengage.com, for instructors to distribute.
The following features from the third edition have been retained:
• Fundamentals of software engineering are discussed from both procedural and
object-oriented viewpoints.
• Each chapter contains a Common Programming Errors section that describes prob-
lems beginning C++ programmers typically encounter.
• The ANSI/ISO C++ iostream library and namespace mechanism are used in all
programs.
• Exception handling is discussed in a separate section, with practical applications of
exception handling included throughout the book.
• The C++ string class is covered.
• A thorough discussion is included of input data validation and functions to check the
numerical data type of input items and allow reentering invalid numerical types.
In practical terms, this book has been written to support both a one- and two-semester techni-
cal C++ programming course; the only prerequisite is that students should be familiar with
fundamental algebra. This book is constructed to be flexible enough so that instructors
can mold the book to their preferences for topic sequence. This flexibility is achieved in the
following ways.
Part I includes the basic structured syntax, flow control, and modularity topics needed for
a thorough understanding of C++’s structural features. With the topics of arrays (Chapter 7)
and files (Chapter 9) moved to Part I, this part now provides a comprehensive one-semester
Preface xiii
[1112]
Saucepan Brush.
Tin Bound 0/3 0/4 0/5
Tied in Centre — 0/3½ 0/4½
Sink Brush, Bass.
Handled 0/4½ 0/7
Jug Mop.
0/2 0/3
Cane Handle, Smaller 0/1
Jug Brushes, Stiff Bristle. 0/9½ 0/11½ 1/3½
Furniture Brushes.
No. T U 20. Handled Whisk Furniture Brush.
Prices 1/7 2/0 2/6
No. T U 4000.
Price 2/9
No. T U 21.
Crevice Furniture Brush, made in Soft White Hair.
Price 2/6
Triangle. Whitewood
Boards, Mahogany Veneers,
Polished.
Prices 1/11 2/6 2/11
Westbourne.
Polished Mahogany Backs, White Bristle
Body and Wing, with Pointed Yellow
Bristle Tuft. Prices 2/7 2/11 3/3
New Albert.
Very best Bristles. Prices 3/11 4/11
Porcupine. Polished Mahogany. Made in
Whisk, price 2/3; made in Best Bristles,
3/11
Furniture Brush
BEST ENGLISH MANUFACTURE
HARD
SHINE
BLACKING
Shoe Brushes, in sets of three, all Bristle.
2/7 3/0 3/9 4/9 6/0 6/6 7/6 9/0 10/9 11/9 13/9 per set.
Separately. Prices, 1/0 1/3 1/7 2/2 3/0 each
CAMP SHOE BRUSHES
No. T U 6. The “Camp”
Shoe Brush. Dumb Bell
Pattern, polished. Set of
three, 3/3
Sash Tool.
0/2 0/2½ 0/3 0/4 0/5 0/6½ 0/7 0/9 0/11 1/3 1/6 2/0
Orders by post
carefully and
accurately
executed.
DISTEMPER BRUSHES.
6 oz. 7 oz. 8 oz. 9 oz. 10 oz.
Fibre — 0/6½ 0/8½ 0/10½ 1/0½
Mixed Hair 1/11½ 2/6 2/11 3/3 3/6
All Bristle 5/11 6/6 6/11 7/6 7/11
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.
ebookball.com