1 Computers and Computing Fundamentals 1 1.1 History of Electronic Computers 1 1.2 Architecture 4 1.2.1 Main Memory 1.2.2 Central Processing Unit 1.2.3 Peripheral Devices 1.2.4 Controllers and Communication to Peripheral Devices 1.3 Networks 10 1.4 Using Bits to Represent Characters and Symbols, Integers, Real Numbers, Addresses, and Instructions 11 1.4.1 Characters and Symbols 1.4.2 Integers 1.4.3 Real Numbers 1.4.4 Hexadecimal and Octal Notation 1.4.5 Addresses 1.4.6 Instructions l 1.4.7 Comment 1.5 Programming Languages 17 1.5.1 Assembly Language 1.5.2 High Level Languages 1.6 Software 19 1.6.1 System Software 1.6.2 Application Software 1.7 Software Engineering 23 1.7.1 Top-down Modular Design, Structure Charts, and Data Flow Diagrams 1.7.2 Functions 1.8 The C Language, ANSI C, and C Compilers 29 1.8.1 C and ANSI C 1.8.2 C Compilers 1.9 About This Textbook and How to Get the Most Out of It 32 1.9.1 The Lessons 1.9.2 The Application Programs Exercises 33 Application Exercises 34 2 Getting Started-Program Structure, Printing, and Comments 37 Lesson 2.1 Basic Structure 37 Lesson 2.2 Writing Comments 46 Lesson 2.3 Formatting Output 50 Lesson 2.4 More Escape Sequences 53 Lesson 2.5 Review of Chapter and Comments About Errors and Debugging 58 Application Program 2.1 Printing Engineering Logo to the Screen 62 Application Program 2.2 Debugging 63 Application Exercises 72 3 The Basics of C-Variables, Arithmetic Operations, Math Functions, and Input/Output 75 Lesson 3.1 Data and Variables: Naming, Declaring, Assigning, and Printing Values 75 Lesson 3.2 Constant Macros and More About Printing Variable Values 84 Lesson 3.3 Arithmetic Operators and Expressions 95 Lesson 3.4 Mixed Type Arithmetic, Compound Assignment, Operator Precedence, and Type Casting 101 Lesson 3.5 Reading Data from the Keyboard 115 Lesson 3.6 Reading Data from a File 120 Lesson 3.7 Math Library Functions 126 Lesson 3.8 Writing Output to a File 132 Lesson 3.9 Single Character Data 135 Application Program 3.1 Area Calculation-Compound Operators and Program Development (1) 149 Application Program 3.2 Temperature Units Conversion-Compound Operators and Program Development (2) 153 Application Program 3.3 Frictional Resistance-Arithmetic Operators, fscanf, and Constant Macros 157 Application Exercises 161 4 Beginning Decision Making and Looping 169 Lesson 4.1 If Control Structure and Relational Expressions 169 Lesson 4.2 Simple If-Else Control Structures 175 Lesson 4.3 Nested If-Else Control Structures 178 Lesson 4.4 Logical Expressions 182 Lesson 4.5 Precedence of Logical Operators 186 Lesson 4.6 Switch and If-Else-If Control Structures 191 Lesson 4.7 While Loop (1) 199 Lesson 4.8 While Loop (2) 203 Lesson 4.9 Do-While Loops 208 Lesson 4.10 Simple For Loop 211 Lesson 4.11 Nested For Loops 217 Application Program 4.1 Girder Intersection-If-Else Control Structure 225 Application Program 4.2 Area Calculation (1)-For Loop 229 Application Program 4.3 Area Calculation (2)-For Loop 232 Application Program 4.4 Temperature Unit Conversions-For Loop 234 Application Program 4.5 Engineering Economics, Interest-Nested For Loops 236 Application Program 4.6 Mathematical Series-For Loop, Do-While Loop, If-Else Control Structure (Numerical Method Example) 243 Application Program 4.7 Solving a Quadratic Equation-If-Else Control Structure (Numerical Method Example) 250 Application Program 4.8 Engineering Economics, Computing Tax-Switch and If-Else-If Control Structures, Compound Relational Expressions 255 Application Exercises 260 5 Functions 265 Lesson 5.1 Functions That Do Not Return a Value 267 Lesson 5.2 Functions That Return Just One Value 284 Lesson 5.3 Scope and Mechanics of Passing Values to Functions 290 Lesson 5.4 Functions That "Return" More Than One Value 298 Lesson 5.5 Mechanics of "Returning" More Than One Value from a Function Addresses and Pointer Variables 302 Application Program 5.1 Passing Many Values to a Function and Returning One Value-Integration with the Trapezoidal Rule (Numerical Method Example) 311 Application Program 5.2 Using Functions with Complex Loops, Working with Grids, a Logic Example 316 Application Program 5.3 Modular Program Design-Area of Parallelogram, Volume of Parallelepiped (Numerical Method Example) 325 Application Exercises 338 6 Numeric Arrays 348 Lesson 6.1 Introduction to 1-D Arrays and Printing Array Elements 349 Lesson 6.2 Array Initialization 356 Lesson 6.3 Basic Array Input/Output 361 Lesson 6.4 Multidimensional Arrays 368 Lesson 6.5 Functions and 1-D Arrays 379 Lesson 6.6 Functions and 2-D Arrays 385 Lesson 6.7 Bubble Sort, Exchange Maximum Sort, and Exchange Minimum Sort 393 Application Example 6.1 Linear Interpolation-Evaluating Voltage Measurement Data (Numerical Method Example) 402 Application Example 6.2 Mean and Median of Measured Wave Heights (Numerical Method Example) 407 Application Example 6.3 Matrix-Vector Multiplication (Numerical Method Example) 413 Application Example 6.4 Best Fit Line-Linear Regression, Modular Design (Numerical Method) 418 Application Example 6.5 Searching and File Compression 429 Application Exercises 438 7 Strings and Pointers 445 Lesson 7.1 Declaring, Initializing, and Printing Strings and Understanding Memory Arrangement 445 Lesson 7.2 Determining Information About Strings and Characters and Using Printf 456 Lesson 7.3 2-D Character Arrays 464 Lesson 7.4 Reading Strings from the Keyboard and Files 471 Lesson 7.5 Pointer Variables vs. Array Variables 480 Lesson 7.6 Initializing Within a Declaration 489 Lesson 7.7 Passing Strings to User-Defined Functions 496 Lesson 7.8 Standard Character String Functions 503 Lesson 7.9 Pointer Notation vs. Array Notation 519 Lesson 7.10 Dynamic Memory Allocation 530 Program Development Methodology 541 Application Program 7.1 Creation of a Spreadsheet Type Program; Individual Character Operations 541 Application Program 7.2 Units Conversion Program; String Operations 550 Application Program 7.3 Pipe Fluid Velocity, Checking Input Data, Modular Design 555 Application Program 7.4 Earthquake Anecdotal Report Analysis, String Operations and Using Dynamic Storage 567 Application Exercises 581 8 Data Structures and Large Program Design 587 Structures in C 588 Lesson 8.1 Structures-Declaring, Initializing, Reading, and Printing 590 Lesson 8.2 Structures and Pointers as Structure Members 597 Lesson 8.3 Pointers to Structures 601 Lesson 8.4 Structures and Functions 605 Lesson 8.5 Arrays of Structures 607 Lesson 8.6 Creating a Linked List 610 Lesson 8.7 Stacks 621 Lesson 8.8 Queues 628 Lesson 8.9 Binary Trees 632 Lesson 8.10 Functions with One Recursive Call 646 Lesson 8.11 Creating Header Files 655 Lesson 8.12 Use of Multiple Source Code Files and Storage Classes 657 Lesson 8.13 Bitwise Manipulations 660 Lesson 8.14 Binary Files 672 Lesson 8.15 Pointers to Functions and Functions Returning Pointers 679 Lesson 8.16 Pointers to Arrays 684 Lesson 8.17 Pointers to Pointers 689 Lesson 8.18 Typedef, Unions, Enumerations * Lesson 8.19 Function-Like Macros * Lesson 8.20 Conditional Inclusion * Lesson 8.21 Arguments to Main * Lesson 8.22 Random File Access * Application Program 8.1 Underground Pollution Plume Boundaries Determining If a Point Is in a Polygon (Numerical Method Example) 692 Application Program 8.2 Recursive Function-Calculation of Pi (Numerical Method Example) 703 Application Program 8.3 Sorting-Quicksort Algorithm 708 Application Program 8.4 Performing Arithmetic Operations; Using a Binary Tree 72] Application Exercises 729 9 Introduction to C++ * Lesson 9.1 C++ Comments and Basic Stream I/O * Lesson 9.2 Manipulators and Formatting Output * Lesson 9.3 Function Overloading * Lesson 9.4 Default Function Arguments * Lesson 9.5 Inline Functions and Position of Variable Declarations * Lesson 9.6 C++ Classes and Objects with Data Members Only * Lesson 9.7 Classes with Data and Function Members, Encapsulation * Lesson 9.8 Constructor and Destructor Functions * Lesson 9.9 Inheritance * Lesson 9.10 Virtual Functions and Polymorphism Application Program 9.1 Electrical Circuits * Application Program 9.2 Building Foundation * Application Exercises * Appendix A: C Operators 733 Appendix B: ASCII Table 736 Appendix C: ANSI Standard Functions and Macros 739 Index 744