//
Programming with C++

Contents.Preface.
.Read This Before You Begin. x i v
.An Introduction to Programming. x v i i i
C h a p ter 1.Programming a Computer. 1
.The Programmer’s Job. 2
.Employment Opportunities. 2
.A Brief History of Programming Languages. 2
.Machine Languages. 3
.Assembly Languages. 3
.High-Level Languages. 3
.Control Structures. 4
.The Sequence Structure. 5
.The Selection Structure. 5
.The Repetition Structure. 6
. .LAB 1-1 8
.LAB .Stop and Analyze 1-2 10
.LAB .Plan and Create 1-3 10
.LAB .Modify 1-4  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  11
.Chapter Summary.What’s Missing? 11
.Key Terms. 12
.Review Questions. 12
.Exercises. 13
.Beginning the Problem-Solving Process. 14
Chapter 2.Problem Solving. 23
.Solving Everyday Problems. 24
.Creating Computer Solutions to Problems. 24
.Step 1—Analyze the Problem. 25
.Hints for Analyzing Problems. 26
.Step 2—Plan the Algorithm. 26
.Step 3—Desk-Check the Algorithm. 28
.The Gas Mileage Problem. 31
. .LAB 2-1 34
.LAB .Stop and Analyze 2-2 36
.LAB .Plan and Create 2-3 36
.LAB .Modify 2-4  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 39
.LAB .What’s Missing? 2-5 39
.LAB .Desk-Check 2-6 40
.Chapter Summary.Debug 40
.Key Terms. 42
.Review Questions. 43
.Exercises. 43
.Variables and Constants. 45
Chapter 3.Beginning Step 4 in the Problem-Solving Process. 51
.Internal Memory. 52
.Selecting a Name for a Memory Location. 52
.Revisiting the Addison O’Reilly Problem from Chapter 2. 53
.Selecting a Data Type for a Memory Location. 54
.How Data Is Stored in Internal Memory. 55
.Selecting an Initial Value for a Memory Location. 57
.Declaring a Memory Location. 60
. .LAB 3-1 62
.LAB .Stop and Analyze 3-2 64
.LAB .Plan and Create 3-3 65
.LAB .Modify 3-4  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  67
.LAB .What’s Missing? 3-5 67
.LAB .Desk-Check 3-6 67
.Chapter Summary.Debug 68
.Key Terms. 68
.Review Questions. 69
.Exercises. 70
.Completing the Problem-Solving Process. 71
Chapter 4.Finishing Step 4 in the Problem-Solving Process. 7 5
.Getting Data from the Keyboard. 76
.Displaying Messages on the Computer Screen. 76
.Arithmetic Operators in C++. 78
.Type Conversions in Arithmetic Expressions. 81
.The static_cast Operator. 82
.Assignment Statements. 83
.Arithmetic Assignment Operators. 84
.Step 5—Desk-Check the Program. 87
.Step 6—Evaluate and Modify the Program. 88
. .LAB 4-1 90
.LAB .Stop and Analyze 4-2 94
.LAB .Plan and Create 4-3 95
.LAB .Modify 4-4 98
.LAB .What’s Missing? 4-5 98
.LAB .Desk-Check 4-6 99
.Chapter Summary.Debug 99
.Key Terms. 99
.Review Questions. 101
.Exercises. 102
.The Selection Structure. 104
C h a p ter 5.Making Decisions. 1 1 3
.Flowcharting a Selection Structure. 114
.Coding Selection Structures in C++. 116
.Comparison Operators. 118
.Swapping Numeric Values. 120
.Displaying the Area or Circumference. 121
.Logical Operators. 124
.Using the Truth Tables. 126
.A Different Version of the Area or Circumference Program. 129
.Summary of Operators. 130
.Converting a Character to Uppercase or Lowercase. 132
.Formatting Numeric Output. 133
. .LAB 5-1 134
.LAB .Stop and Analyze 5-2 137
.LAB .Plan and Create 5-3 138
.LAB .Modify 5-4 143
.LAB .What’s Missing? 5-5 143
.LAB .Desk-Check 5-6 143
.Chapter Summary.Debug 144
.Key Terms. 144
.Review Questions. 145
.Exercises. 146
.More on the Selection Structure. 147
Chapter 6.Nested Selection Structures. 1 5 7
.Flowcharting a Nested Selection Structure. 158
.Coding a Nested Selection Structure. 161
.Logic Errors in Selection Structures. 163
.First Logic Error: Using a Compound Condition Rather Than a Nested. 165
.Selection Structure.
.Second Logic Error: Reversing the Outer and Nested Decisions. 167
.Third Logic Error: Using an Unnecessary Nested Selection Structure. 169
.Fourth Logic Error: Including an Unnecessary Comparison in a Condition. 169
.Multiple-Alternative Selection Structures. 170
.The switch Statement. 173
. .LAB 6-1 174
.LAB .Stop and Analyze 6-2 177
.LAB .Plan and Create 6-3 178
.LAB .Modify 6-4 182
.LAB .What’s Missing? 6-5 182
.LAB .Desk-Check 6-6 183
.Chapter Summary.Debug 183
.Key Terms. 184
.Review Questions. 184
.Exercises. 185
.The Repetition Structure. 187
Chapter 7.Repeating Program Instructions. 2 0 1
.Using a Pretest Loop to Solve a Real-World Problem. 202
.Flowcharting a Pretest Loop. 204
.The while Statement. 206
.Using Counters and Accumulators. 208
.The Stock Price Program. 211
.Counter-Controlled Pretest Loops. 213
.The for Statement. 217
.The Total Payroll Program. 219
.The Tip Program. 220
.Another Version of the Commission Program. 223
.The Even Integers Program. 224
. .LAB 7-1 226
.LAB .Stop and Analyze 7-2 229
.LAB .Plan and Create 7-3 230
.LAB .Modify 7-4 234
.LAB .What’s Missing? 7-5 234
.LAB .Desk-Check 7-6 234
.Chapter Summary.Debug 234
.Key Terms. 235
.Review Questions. 236
.Exercises. 236
.More on the Repetition Structure  .  .  .  .  .  .  .. 239
Chapter 8.Posttest Loops. .  .  .  .  .  . 2 4 7
.Flowcharting a Posttest Loop. 248
.The do while Statement. 250
.Nested Repetition Structures. 252
.The Clock Program. 254
.The Car Depreciation Program. 255
. .LAB 8-1 258
.LAB .Stop and Analyze 8-2 262
.LAB .Plan and Create 8-3 263
.LAB .Modify 8-4 267
.LAB .What’s Missing? 8-5 267
.LAB .Desk-Check 8-6 267
.Chapter Summary.Debug 268
.Key Terms. 268
.Review Questions. 268
.Exercises. 269
.Value-Returning Functions. 270
Chapter 9.Functions. 2 7 9
.Value-Returning Functions. 280
.The pow Function. 281
.The sqrt Function. 281
.The Hypotenuse Program. 282
.The rand, srand, and time Functions. 283
.The Guessing Game Program. 285
.Creating Program-Defined Value-Returning Functions. 289
.Calling a Function. 291
.The Savings Account Program. 293
.Function Prototypes. 295
.Completing the Savings Account Program. 298
.The Scope and Lifetime of a Variable. 298
. .LAB 9-1 304
.LAB .Stop and Analyze 9-2 305
.LAB .Plan and Create 9-3 307
.LAB .Modify 9-4 314
.LAB .What’s Missing? 9-5 314
.LAB .Desk-Check 9-6 315
.Chapter Summary.Debug 316
.Key Terms. 316
.Review Questions. 317
.Exercises. 318
.. 320
.Void Functions.
C h a p ter 10.Functions. 3 2 9
.Creating Program-Defined Void Functions. 330
.Passing Variables to a Function. 331
.Reviewing Passing Variables by Value. 337
.Passing Variables by Reference. 338
. .LAB 10-1 341
.LAB .Stop and Analyze 10-2 345
.LAB .Plan and Create 10-3 347
.LAB .Modify 10-4 356
.LAB .What’s Missing? 10-5 356
.LAB .Desk-Check 10-6 356
.Chapter Summary.Debug 357
.Key Terms. 357
.Review Questions. 358
.Exercises. 358
.One-Dimensional Arrays. 360
Chapter 11.Arrays. 3 6 9
.One-Dimensional Arrays. 370
.Declaring and Initializing a One-Dimensional Array. 370
.Entering Data into a One-Dimensional Array. 371
.Displaying the Contents of a One-Dimensional Array. 373
.The Calories Program. 375
.Passing a One-Dimensional Array to a Function. 376
.Calculating a Total and an Average. 382
.The Social Media Program—Searching an Array. 384
.The Currency Converter Program—Accessing an Individual Element. 385
.The Highest Number Program—Finding the Highest Value. 388
.Parallel One-Dimensional Arrays. 391
.Sorting the Data Stored in a One-Dimensional Array. 396
. .LAB 11-1 399
.LAB .Stop and Analyze 11-2 406
.LAB .Plan and Create 11-3 407
.LAB .Modify 11-4 411
.LAB .What’s Missing? 11-5 411
.LAB .Desk-Check 11-6 411
.Chapter Summary.Debug 412
.Key Terms. 413
.Review Questions. 413
.Exercises. 414
.Two-Dimensional Arrays. 416
Chapter 12.Using Two-Dimensional Arrays. 4 2 5
.Declaring and Initializing a Two-Dimensional Array. 426
.Entering Data into a Two-Dimensional Array. 427
.Displaying the Contents of a Two-Dimensional Array. 428
.The Chapton Company Program. 431
.Accumulating the Values Stored in a Two-Dimensional Array. 432
.Searching a Two-Dimensional Array. 434
.Passing a Two-Dimensional Array to a Function. 436
. .LAB 12-1 443
.LAB .Stop and Analyze 12-2 444
.LAB .Plan and Create 12-3 446
.LAB .Modify 12-4 449
.LAB .What’s Missing? 12-5 449
.LAB .Desk-Check 12-6 449
.Chapter Summary.Debug 450
.Key Terms. 450
.Review Questions. 450
.Exercises. 451
.Strings. 452
Chapter 13.The string Data Type. 4 6 1
.Getting String Input from the Keyboard. 462
.The Primrose Auction House Program. 462
.The ignore Function. 464
.Determining the Number of Characters in a string Variable. 468
.Accessing the Characters in a string Variable. 471
.Searching the Contents of a string Variable. 473
.Removing Characters from a string Variable. 477
.Replacing Characters in a string Variable. 481
.Inserting Characters Within a string Variable. 484
.Duplicating a Character Within a string Variable. 485
.Concatenating Strings. 487
. .LAB 13-1 489
.LAB .Stop and Analyze 13-2 491
.LAB .Plan and Create 13-3 492
.LAB .Modify 13-4 497
.LAB .What’s Missing? 13-5 497
.LAB .Desk-Check 13-6 498
.Chapter Summary.Debug 498
.Key Terms. 499
.Review Questions. 500
.Exercises. 501
.Sequential Access Files. 504
C h a p ter 14.File Types. 5 1 1
.Creating File Objects. 512
.Opening a Sequential Access File. 512
.Determining Whether a File Was Opened Successfully. 514
.Writing Data to a Sequential Access File. 516
.Reading Information from a Sequential Access File. 518
.Testing for the End of a Sequential Access File. 519
.Closing a Sequential Access File. 522
.The eBook Collection Program. 522
. .LAB 14-1 523
.LAB .Stop and Analyze 14-2 528
.LAB .Plan and Create 14-3 530
.LAB .Modify 14-4 539
.LAB .What’s Missing? 14-5 540
.LAB .Desk-Check 14-6 540
.Chapter Summary.Debug 541
.Key Terms. 541
.Review Questions. 542
.Exercises. 543
.Classes and Objects. 544
Chapter 15.Object-Oriented Terminology. 5 5 1
.Defining a Class in C++. 552
.Instantiating an Object and Referring to a Public Member. 553
.Example 1—A Class That Contains a Private Data Member. 556
.Header Files. .  .  .  .  .  .  557
.Example 2—A Class That Contains a Parameterized Constructor. 561
.Example 3—Reusing a Class. 562
.Example 4—A Class That Contains Overloaded Methods. 565
. .LAB 15-1 566
.LAB .Stop and Analyze 15-2 569
.LAB .Plan and Create 15-3 571
.LAB .Modify 15-4 576
.LAB .What’s Missing? 15-5 576
.LAB .Desk-Check 15-6 576
.Chapter Summary.Debug 578
.Key Terms. 578
.Review Questions. 579
.Exercises. 580
.C++ Keywords  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . . 581
Appendix A.ASCII Codes. 5 9 3
Appendix B.Common Syntax Errors. 5 9 5
Appendix C.How To Boxes. 5 9 7
Appendix D.Index. 5 9 9
.. 6 0 3
Advertisements

Đã đóng bình luận.

Các tác giả

Chuyên mục

Tháng Chín 2018
H B T N S B C
« Th8    
 12
3456789
10111213141516
17181920212223
24252627282930

NCT Computer

Flickr Photos

Thống kê

  • 375 684 lượt xem

pascalteacher.nct@gmail.com


Trang huấn luyện học sinh giỏi Tin học

Advertisements
%d bloggers like this: