C++ for Computer Science and Engineering 4th ......Page 1 Table of Contents ......Page 4 What is a Computer?......Page 14 Designing Solutions - the Cycle of Data Processing......Page 17 Building a Program......Page 18 How to Solve a Problem on the Computer......Page 20 The Early Retirement Program......Page 24 The Mechanical Robot Problem......Page 26 The Mechanical Mouse Problem......Page 27 Basic Computer Architecture......Page 29 The C++ Language and the Hello World Program......Page 30 Design Exercises......Page 39 Stop! Do These Exercises Before Programming......Page 40 Programming Problems......Page 44 Integer Versus Floating Point \(Real\) Numbers......Page 47 Which Type of Data Do You Use for Which Variable?......Page 48 Definition of Variables......Page 49 Defining More Than One Variable in the Same Statement......Page 51 Initializing Variables and the Assignment Operator......Page 53 Multiple Assignments - Chaining the Assignment Operator......Page 55 Chaining Extraction Operators......Page 56 Always Prompt the User Before Inputting the Data......Page 57 Output of a Variable......Page 58 Insertion of Floating Point Numbers into an Output Stream......Page 60 Labeling Output......Page 62 Math Operators - Calculations......Page 63 Precedence or Priority of Operators......Page 64 Constant Data Objects......Page 65 Math Library Functions......Page 67 Other Math Functions......Page 69 Breaking a Complex Calculation Down into Smaller Portions......Page 70 Cs02a - Ticket Prices for a Concert......Page 73 Engr02a - Pressure Drop in a Fluid Flowing Through a Pipe (Civil Engineering)......Page 77 New Syntax Summary......Page 80 Design Exercises......Page 83 Stop! Do These Exercises Before Programming......Page 84 Programming Problems......Page 88 The Complete Integer Data Types......Page 91 Which Type of Data Do I Use in My Program?......Page 92 How Integer Data Is Stored in Memory......Page 93 Integer Variable Overflow......Page 94 Table 3.2 The Floating Point Data Types......Page 95 Principles of Data Conversion......Page 96 Assigning Smaller Sized Integers to Larger Sized Integers......Page 97 Assigning Larger Sized Integers to Smaller Sized Integer Variables \(The......Page 98 Calculations Involving Multiple Floating Point Data Types......Page 100 Mixed Mode Math......Page 101 Constants and Data Types......Page 102 The Increment and Decrement Operators......Page 105 The Compound Assignment Operators......Page 106 CS03a - Vote Tally Program......Page 107 Engr03a - Calculating the Power Supplied to a Load (Electrical Engineering)......Page 109 Design Exercises......Page 113 Stop! Do These Exercises Before Programming......Page 114 Programming Problems......Page 116 The If-Then-Else Syntax......Page 120 The Test Condition......Page 122 Nested Decisions......Page 124 Compound Test Conditions......Page 128 The Logical Not Operator Š !......Page 130 The bool Data Type......Page 131 The Most Common Test Condition Blunder Explained......Page 133 The Conditional Expression......Page 134 The Precedence of Operators......Page 135 Testing of Real Numbers......Page 136 Cs04a - Compute the Total Bill By Finding the Sales Tax Rate......Page 138 Engr04a - Quadratic Root Solver......Page 143 New Syntax Summary......Page 147 Design Exercises......Page 148 Stop! Do These Exercises Before Programming......Page 150 Programming Problems......Page 153 Introduction......Page 157 Input Files......Page 158 I/O Stream States......Page 159 Testing for Goodness......Page 160 Testing for Bad Data Entry......Page 161 The End of File......Page 162 Closing a File......Page 163 The Iterative Instructions......Page 164 Loops That Are to Be Executed a Known Number of Times......Page 165 Sentinel Controlled Input Loops......Page 167 Menus as Sentinel Controlled Loops......Page 169 Primed Input Loops that Detect End of File......Page 170 A More Compact Loop That Detects End of File......Page 172 Application: The Summation of a Series......Page 173 Counters and Totals Š Grand Totals......Page 174 Finding the Maximum and Minimum Values......Page 177 Bulletproofing Programs......Page 180 Creating Output Files......Page 181 The Do Until Instruction Š An Alternative to the Do While......Page 185 The Do Loop or for Statement......Page 186 Efficient Loops......Page 190 Nesting of Loops......Page 191 Section B: Computer Science Examples......Page 192 Cs05a - Acme Ticket Sales Summary Program......Page 193 Cs05b - Calculating N! (N factorial)......Page 198 Engr05a - Summation of Infinite Polynomials......Page 201 Engr05b - Artillery Shell Trajectory......Page 205 New Syntax Summary......Page 209 Stop! Do These Exercises Before Programming......Page 212 Programming Problems......Page 219 Introduction......Page 223 Principles of Top-Down Design......Page 224 Writing your own functions......Page 227 Step A. Define the FunctionTMs Prototype......Page 228 Step B. Define the Function Header......Page 230 Step C. Code the FunctionTMs Body.......Page 232 Step D. Invoke or Call the Function......Page 233 A Second Example, calcTax\(\)......Page 235 How Parameters Are Passed to Functions......Page 238 The Types, Scope and Storage Classes of Variables......Page 239 Registers and the Stack Š a Bit of Computer Architecture......Page 242 How a Function Returns a Value......Page 243 More on the bool Data Type and Functions that Return a bool......Page 246 Functions that Return No Value......Page 247 Where Should Error Messages Be Displayed?......Page 248 Inputting Integers that have Leading Zeros Š The dec Manipulator......Page 249 Cs06-1 - Employee Payroll Program......Page 251 Introduction to Numerical Analysis......Page 256 Numerical Analysis: Root Solving, the Bisection Method......Page 258 Engr06a - Root Solving, the Bisection Method......Page 261 New Syntax Summary......Page 267 Design Exercises......Page 268 Stop! Do These Exercises Before Programming......Page 269 Programming Problems......Page 273 The Need for Reference Variables......Page 279 The Reference Variable Solution......Page 284 The Static Storage Class......Page 288 The Global/External Storage Class......Page 291 Using Global Variables in Other Cpp Files Š the extern Keyword......Page 294 Where are Global and Static Variables Actually Stored?......Page 295 Philosophy on the Use of Global Variables......Page 296 How to Pass iostreams to Functions......Page 297 Section B: Computer Science Examples......Page 301 Cs07c - Acme Ticket Sales Report Š a Multi-page Report......Page 300 Cs07a - Multiple Level Control Break Processing......Page 306 Cs07b - Summary Reports Based upon Control Break Processing......Page 314 Bisection Revisited Š Writing a Generic Bisection Function......Page 317 Engr07a - Using a Generic bisect() Function......Page 319 Engr07b - Molar Volume of Non-Ideal Gases (Chemical Engineering)......Page 322 Faster Alternative Root Solving Methods......Page 326 Engr07c - Molar Volume of Non-Ideal Gases - Using Regula Falsi......Page 327 NewtonTMs Method of Root Solving......Page 331 Engr07d - Molar Volume of Non-Ideal Gases - Using NewtonTMs......Page 333 The Secant Method of Root Solving......Page 338 Engr07e - Molar Volume of Non-Ideal Gases - Using the Secant......Page 339 Summary of Root Solving Techniques......Page 343 Design Exercises......Page 344 Stop! Do These Exercises Before Programming......Page 345 Programming Problems......Page 351 Defining Variables to Hold a Character of Data......Page 358 Using the Extraction Operator to Input a Character......Page 359 Hexadecimal Numbers......Page 360 Using the get() Function......Page 361 Output of Character Data Š the put\(\) Function......Page 362 How Are Character Data Stored?......Page 363 The Escape Sequences......Page 365 Numbers and Letters......Page 366 Basic08a - A Word Counter Program......Page 368 The Do Case Structure......Page 372 More on the break Statement and the continue Statement......Page 377 Enumerated Data Types......Page 378 Aborting the Program......Page 384 Cs08a - Inventory on Hand Program......Page 385 Cs08b Š Inventory on Hand Program - Using a Generic......Page 392 The Trapezoid Method of Numerical Integration......Page 398 Engr08a - Numerical Integration with the Trapezoid Rule......Page 401 Integration Using SimpsonTMs Rule......Page 403 Engr08b - Numerical Integration with SimpsonTMs Rule......Page 404 Engr08c - Using Menus to Control Program Operation......Page 406 New Syntax Summary......Page 410 Design Exercises......Page 412 Stop! Do These Exercises Before Programming......Page 413 Programming Problems......Page 416 Defining Arrays......Page 421 Accessing Array Elements......Page 422 Method A: Inputting a Known Number of Elements......Page 424 Method B: Inputting the Number of Array Elements To Be Input......Page 425 Method C: Inputting an Unknown Number of Elements Until EOF Is......Page 426 Working with Arrays - The Calculations......Page 427 Working with arrays: the Output Process......Page 428 Passing Arrays to Functions......Page 429 Cs09a - Sales Data Analysis......Page 436 Section C: Engineering Examples......Page 443 Engr09a - Vector Coordinate Conversions......Page 444 Engr09b - Plotting Graphs......Page 447 New Syntax Summary......Page 453 Stop! Do These Exercises Before Programming......Page 455 Programming Problems......Page 460 Using an Array for Direct Lookup Operations......Page 465 Parallel Arrays and Sequential Searches Š Inquiry Programs......Page 466 Inserting Another Element into an Unsorted Array......Page 468 Ordered (Sorted) Lists......Page 469 Inserting New Data into a Sorted List......Page 471 Sorting an Array......Page 472 Cs10B - Account Processing using a Menu and Sorted Arrays......Page 474 Cs10A - Merging Arrays......Page 483 Engr10a - Statistical Computations......Page 495 Least Squares Curve Fitting......Page 499 New Syntax Summary......Page 501 Stop! Do These Exercises Before Programming......Page 502 Programming Problems......Page 504 Defining Character Strings......Page 513 Using the Extraction Operator......Page 514 Method A Š All Strings Have the Same Length......Page 516 Method B Œ String Contains Only the Needed Characters, But Is the Last......Page 518 Outputting Character Strings......Page 519 Working with Strings......Page 521 Comparing Strings......Page 522 Copying Strings......Page 523 Concatenating or Joining Two Strings into One Larger String......Page 524 The String Functions......Page 525 Section B: A Computer Science Example......Page 529 Cs11a Š Character String Manipulation - Customer Names......Page 530 Engr11a - Weather Statistics Revisited......Page 539 New Syntax Summary......Page 542 Design Exercises......Page 544 Stop! Do These Exercises Before Programming......Page 545 Programming Problems......Page 547 Defining Multidimensional Arrays......Page 552 Physical Memory Layout Versus Logical Layout......Page 554 Initialization of Multidimensional Arrays......Page 555 Loading a Multidimensional Array from an Input File......Page 556 Working with Multidimensional Arrays......Page 558 Section B: A Computer Science Example......Page 563 Cs12a - Arrays of Strings......Page 564 Matrix Algebra......Page 571 Matrix Math Operations Summary......Page 572 Mathematical Theorems of Determinants......Page 574 The Gauss Method for Solving a System of Linear Equations......Page 575 Gauss-Jordan Method of Solving Simultaneous Linear Equations......Page 577 Engr12a - Aligning the Mirrors of a Telescope (Astronomy)......Page 582 Design Exercises......Page 584 Stop! Do These Exercises Before Programming......Page 585 Programming Problems......Page 588 Defining Structures......Page 595 Creating Instances of a Structure......Page 597 How are Structure Members Accessed?......Page 599 Rules of Use for Structure Variables......Page 600 User-Written Header Files......Page 603 Binary Files and Structures......Page 604 Mechanics of Binary Files......Page 605 Cs13-1 - Credit Card Application with Sorting......Page 607 Cs13-2 - Writing a Binary File......Page 616 Cs13-3 - Reading a Binary File......Page 619 Engr13a - Weather Statistics Revisited......Page 623 Stop! Do These Exercises Before Programming......Page 628 Programming Problems......Page 631 C++ DOS Console Applications......Page 638 Making a New Programming Solution Š......Page 639 Continue to Work on an Existing Program Š Starting Visual Studio......Page 644 Building a New Project in Which the Cpp Files Already Exist......Page 645 Compiling and Running Your Program......Page 646 Getting Source File Printouts......Page 648 Case 2: Using cout and There Are Too Many Lines To Capture With a Screen......Page 649 Case 3: Using an Output File Stream......Page 650 Visual Studio Operational Tips......Page 651 Debug Versus Release Builds......Page 652 A Primer on Using the Debugger......Page 653 C++ DOS Console Applications......Page 660 Making a New Programming Solution......Page 661 Continue to Work on an Existing Program — Starting Visual Studio......Page 665 Building a New Project in Which the Cpp Files Already Exist......Page 666 Compiling and Running Your Program......Page 668 Case 1: The Entire Output Fits on One Screen Without Scrolling......Page 669 Case 2: Using cout and There Are Too Many Lines To Capture With a ScreenShot......Page 670 Visual Studio Operational Tips......Page 671 Debug Versus Release Builds......Page 675 A Primer on Using the Debugger......Page 676 Step 0. Get Organized......Page 683 Step 1: Building the Program Project......Page 685 Step 2. Transporting Programs to and from School Computers......Page 689 Step 4. Compiling the Program......Page 690 Step 6. Where Is the Executable File \(*.exe\) Located?......Page 691 Step 7. Running The Program......Page 692 Step 8. Program Debugging and Execution......Page 694 Step 9. The Help System......Page 696 Step 10. Some VC6 Options......Page 697 Step 11. Getting the hardcopy documentation for programs to hand in to your......Page 698 Index......Page 702