Đây là quyển sách tiếng anh về lĩnh vực công nghệ thông tin cho sinh viên và những ai có đam mê. Quyển sách này trình về lý thuyết ,phương pháp lập trình cho ngôn ngữ C và C++.
C++ for Computer Science and Engineering (4th Edition) Vic Broquard Broquard eBooks 103 Timberlane East Peoria, IL 61611 author@Broquard-eBooks.com ISBN: 0-9705697-2-6 C++ for Computer Science and Engineering Vic Broquard Copyright 2000, 2002, 2003, 2006 by Vic Broquard All rights reserved No part of this book may be reproduced or transmitted in any form without written permission of Vic Broquard Fourth Edition ISBN: 0-9705697-2-6 Brief Table of Contents 10 11 12 13 Introduction to Programming Numerical Processing Additional Processing Details Decisions Files and Loops Writing Your Own Functions More on Functions Character Processing and Do Case Arrays Using Arrays Strings Multidimensional Arrays Structures Appendix A: How to Use Microsoft’s Visual C++ NET 2005 Compiler Appendix B: How to Use Microsoft’s Visual C++ NET 2002 Compiler Appendix C: How to Use Microsoft’s Visual C++ Version 6.0 Compiler Index To all of my dedicated, persevering students, and to L Ron Hubbard, who taught me to “Simplify” Preface This book assumes you have no previous programming background It uses a step-by-step building block approach to gradiently learn how to solve computer science and engineering problems in the C++ language Each chapter has three sections Section A presents the basic theory and principles of the current topic Section B illustrates these basic principles by using applications that are often found in computer science Section C illustrates these basic principles by using applications that may be found in the various engineering disciplines You should study the basic theory Section A and then study the appropriate application section Of course, anyone can benefit by also reviewing the other application area, since they are frequently interrelated The book comes with a self-extracting zip file containing all of the sample programs in the book along with all of the test data required for the programming assignments At the end of each chapter are Design Exercises, Stop Exercises and Programming Problems Before you tackle any programming assignments, you should both the Design and Stop exercises The Design Exercises are paper and pencil activities that assist in solidifying the basic design principles covered in the chapter The Stop Exercises cover the new syntax of the language, illustrating many of the more common errors beginners make in coding the language If you dutifully these two sets of exercises before you start in on your programming assignments, you will have a much better chance of success with drastically lower frustration level If you find any errors or have any suggestions or comments, please email me at author@Broquard-eBooks.com v Contents Chapter — Introduction to Programming Section A: Basic Theory Introduction What is a Computer? Designing Solutions — the Cycle of Data Processing 10 Building a Program 11 The Steps Needed to Create a Program — or — 13 How to Solve a Problem on the Computer 13 The Early Retirement Program 17 The Mechanical Robot Problem 19 The Mechanical Mouse Problem 20 Basic Computer Architecture 22 The C++ Language and the Hello World Program 23 Design Exercises 32 Stop! Do These Exercises Before Programming 33 Programming Problems 37 Chapter — Numerical Processing 40 Section A: Basic Theory 40 Introduction 40 Variables and Constants 40 Integer Versus Floating Point (Real) Numbers 40 Which Type of Data Do You Use for Which Variable? 41 Definition of Variables 42 The Issue of the Case of a Variable Name 44 Defining More Than One Variable in the Same Statement 44 Where Are Variable Definitions Placed in a Program? 46 Initializing Variables and the Assignment Operator 46 Multiple Assignments — Chaining the Assignment Operator 48 Input of Data Values into Variables 49 Chaining Extraction Operators 49 Always Prompt the User Before Inputting the Data 50 Output of a Variable 51 The setw() Function 53 Insertion of Floating Point Numbers into an Output Stream - setprecision and fixed 53 Labeling Output 55 Math Operators — Calculations 56 Precedence or Priority of Operators 57 vi Constant Data Objects 58 Math Library Functions 60 The Most Nearly Accurate Value of PI 62 Other Math Functions 62 Some Additional Insertion Operator Details 63 Breaking a Complex Calculation Down into Smaller Portions 63 Section B: Computer Science Example 66 Cs02a — Ticket Prices for a Concert 66 Section C: Engineering Example 70 Engr02a — Pressure Drop in a Fluid Flowing Through a Pipe (Civil Engineering) 70 Design Exercises 76 Stop! Do These Exercises Before Programming 77 Programming Problems 81 Chapter — Additional Processing Details 84 Section A: Basic Theory 84 Introduction 84 The Complete Integer Data Types 84 Which Type of Data Do I Use in My Program? 85 How Integer Data Is Stored in Memory 86 Integer Variable Overflow 87 The Complete Floating Point Data Types 88 Principles of Data Conversion 89 Assigning Smaller Sized Integers to Larger Sized Integers 90 Assigning Larger Sized Integers to Smaller Sized Integer Variables (The Typecast) 91 Calculations Involving Multiple Floating Point Data Types 93 Mixed Mode Math 94 Constants and Data Types 95 Additional Operators 98 The Increment and Decrement Operators 98 The Compound Assignment Operators 99 Section B: Computer Science Examples 100 CS03a — Vote Tally Program 100 Section C: An Engineering Example 102 Engr03a—Calculating the Power Supplied to a Load (Electrical Engineering 102 Design Exercises 106 Stop! Do These Exercises Before Programming 107 Programming Problems 109 Chapter — Decisions 113 vii Section A: Basic Theory 113 Introduction 113 The Components of an If-Then-Else Decision Structure 113 The If-Then-Else Syntax 113 The Test Condition 115 Nested Decisions 117 Compound Test Conditions 121 The Logical Not Operator — ! 123 Data Type and Value of Relational Expressions — The bool Data Type 124 The bool Data Type 124 The Most Common Test Condition Blunder Explained 126 The Conditional Expression 127 The Precedence of Operators 128 Testing of Real Numbers 129 Section B: Computer Science Example 131 Cs04a — Compute the Total Bill By Finding the Sales Tax Rate 131 Section C: An Engineering Example 136 Engr04a — Quadratic Root Solver 136 Design Exercises 141 Stop! Do These Exercises Before Programming 143 Programming Problems 146 Chapter — Files and Loops 150 Section A: Basic Theory 150 Introduction 150 Input Files 151 I/O Stream States 152 Testing for Goodness 153 Testing for Bad Data Entry 154 The End of File 155 Closing a File 156 The Iterative Instructions 157 Loops That Are to Be Executed a Known Number of Times 158 Loops to Input All Data in a File 160 Sentinel Controlled Input Loops 160 Keyboard Data Entry Sentinel Controlled Loops 162 Menus as Sentinel Controlled Loops 162 Primed Input Loops that Detect End of File 163 A More Compact Loop That Detects End of File 165 Applications of Loops 166 Application: The Summation of a Series 166 Counters and Totals — Grand Totals 167 Finding the Maximum and Minimum Values 170 viii Bulletproofing Programs 173 Creating Output Files 174 The Do Until Instruction — An Alternative to the Do While 178 The Do Loop or for Statement 179 Efficient Loops 183 Nesting of Loops 184 An Example of Nested Loops 185 Section B: Computer Science Examples 186 Cs05a — Acme Ticket Sales Summary Program 186 Cs05b — Calculating N! (N factorial) 191 Section C: Engineering Examples 194 Engr05a — Summation of Infinite Polynomials 194 Engr05b — Artillery Shell Trajectory 198 New Syntax Summary 204 Design Exercises 205 Stop! Do These Exercises Before Programming 206 Programming Problems 212 Chapter — Writing Your Own Functions 216 Section A: Basic Theory 216 Introduction 216 Principles of Top-Down Design 217 Writing your own functions 220 Step A Define the Function’s Prototype 221 Step B Define the Function Header 223 Step C Code the Function’s Body 225 Step D Invoke or Call the Function 226 A Second Example, calcTax() 228 How Parameters Are Passed to Functions 231 The Types, Scope and Storage Classes of Variables 232 Registers and the Stack — a Bit of Computer Architecture 235 How a Function Returns a Value 236 More on the bool Data Type and Functions that Return a bool 239 The Shipping Cost Function 239 Functions that Return No Value 240 Where Should Error Messages Be Displayed? 241 Controlling Leading 0's on Output — the setfill() Function 242 Inputting Integers that have Leading Zeros — The dec Manipulator Function 242 Section B: Computer Science Example 244 Cs06-1 — Employee Payroll Program 244 Section C: An Engineering Example 249 Introduction to Numerical Analysis 249 ix Numerical Analysis: Root Solving, the Bisection Method 251 Engr06a — Root Solving, the Bisection Method 254 Design Exercises 261 Stop! Do These Exercises Before Programming 262 Programming Problems 266 Chapter — More on Functions 272 Section A: Basic Theory 272 Introduction 272 Reference Variables 272 The Need for Reference Variables 272 The Reference Variable Solution 277 The Static Storage Class 281 The Global/External Storage Class 284 Using Global Variables in Other Cpp Files — the extern Keyword 287 Where are Global and Static Variables Actually Stored? 288 Philosophy on the Use of Global Variables 289 How to Pass iostreams to Functions 290 Section B: Computer Science Examples 293 Cs07c — Acme Ticket Sales Report — a Multi-page Report 293 Cs07a — Multiple Level Control Break Processing 299 Cs07b — Summary Reports Based upon Control Break Processing 307 Section C: Engineering Examples 310 Bisection Revisited — Writing a Generic Bisection Function 310 Engr07a — Using a Generic bisect() Function 312 Engr07b — Molar Volume of Non-Ideal Gases 315 Faster Alternative Root Solving Methods 319 The Regula Falsi Root Solving Method 320 Engr07c — Molar Volume of Non-Ideal Gases — Using Regula Falsi Method 320 Newton’s Method of Root Solving 324 Engr07d — Molar Volume of Non-Ideal Gases — Using Newton’s Method 326 The Secant Method of Root Solving 331 Engr07e — Molar Volume of Non-Ideal Gases — Using the Secant Method 332 Summary of Root Solving Techniques 336 Design Exercises 338 Stop! Do These Exercises Before Programming 338 Programming Problems 344 Chapter — Character Processing and Do Case 351 x Appendix C: How to Use Microsoft’s Visual C++ 6.0 Compiler 688 Choice A file of data is needed to be input using DOS redirection or the program produces more lines than can be shown in a dos window When using this choice, it does not matter whether you are in DOS full screen mode or using DOS in a window To use DOS input redirection, insert a < sign and the full path to where the data file is located DOS input redirection works as follows When a program asks dos for another keystroke which would normally be come from the keyboard, the input redirection causes the next character in the data file to be given to the program as if the corresponding key on the keyboard had been pressed It is a bit of DOS internal trickery Assume that our program 2e actually needed a test data file that you downloaded from school called 2e1.txt and that you had placed that file in the A:\Cs125 folder You would then enter K:\Cs125\2e\Debug>2e < A:\Cs125\2e.1 I would run it this way with all the output going to the screen to make sure all is well If you get bad command or file not found, then DOS cannot find either 2e.exe or the file 2e1.txt Double check your folders using Explorer When all looks well, then get the printed copy by appending the > PRN (redirection to the printer option) or > results.txt K:\Cs125\2e\Debug>2e < A:\Cs125\2e.1 > PRN or K:\Cs125\2e\Debug>2e < A:\Cs125\2e.1 > results.txt Tip: if you have to much of this redirection stuff, copy the test data file into the debug folder It simplifies the command to just K:\Cs125\2e\Debug>2e < 2e.1 > PRN Choice 3: Your program is actually using input file operations (an instance of ifstream) This is the easiest one to handle To run the program and see the results on screen, just enter the name of the program K:\Cs125\2e\Debug>2e When all is ready for the print out, enter the > PRN or > results.txt K:\Cs125\2e\Debug>2e > PRN or K:\Cs125\2e\Debug>2e > results.txt Note that suggested that these output files have the txt extension This way, simply double clicking on them in the Explorer will launch Notepad to view and print it Index 689 Index ? : 127 += operator 99 ^Z 155 #define 371, 372, 415, 511, 546, 589 #include 596 To include user header files, use double quote marks 596 #include 30 #include 30 #include directive 30 _MAX_PATH 511, 517 A More Compact Loop That Detects End of File 165 abs 62 Accessing Array Elements 415 AND logic 121 AND operator 122 AND operator has a higher precedence than does the OR operato 122 Appendix A: How to Use Microsoft’s Visual Studio NET 2005 Compi 631 Applications of Loops 166 Arrays 414 binary search 462 Defining Arrays 414 Initializing an Array 422 Inputting a Known Number of Elements 417 Inputting an Unknown Number of Elements Until EOF Is Reached 419 Inputting the Number of Array Elements To Be Input 418 Inserting Another Element into an Unsorted Array 461 Merging Arrays 467, 476 Methods of Inputting Data into an Array 417 Ordered (Sorted) Lists 462 Parallel Arrays and Sequential Searches 459 Passing Arrays to Functions 422 Sorting an Array 465 Straight Selection Sort 465 subscript out of bounds 416 the Output Process 421 Using an Array for Direct Lookup Operations 458 Using Arrays 458 Working with Arrays 420 Arrays of Strings 557 ASCII 356, 357 Assigning Larger Sized Integers to Smaller Sized Integer Variabl 91 Index 690 Assigning Smaller Sized Integers to Larger Sized Integers 90 assignment instruction 47 Assignment Operator 46-48 assigns a floating point number to any of the integer 95 bad () 152 Basic Computer Architecture 21 binary file 598 Mechanics of Binary Files 598 Reading a Binary File 612 Writing a Binary File 609 binary number system 11 binary search 462 bisect() 255, 310-312 Bisection Method Generic Bisection Function 310 Using a Generic bisect() Function 312 blank lines to separate key lines 30 bool 239, 461 Functions that Return a bool 239 bool Data Type 124 convert an integer relational expression result into a bool 125 false 124 true 124 break Statement 370 Breaking a Complex Calculation Down 63 Bulletproofing Programs 173, 174, 196 C++ startup code 25 calcTax() 228 Calculating N! 191 case 369, 386 Case of a Variable Name 44 cctype 361 cerr 241 chaining 29 char 91, 351 Character Processing 351 Character Processing Functions 361 character variable can be initialized 352 Defining Variables to Hold a Character of Data 351 How Are Character Data Stored? 356 insertion operator can be used 355 Numbers and Letters 359 Output of Character Data 355 Index 691 The escape sequences 358 The Processing of Character Data 351 The put() function 356 Using the Extraction Operator to Input a Character 352 Using the get() Function 354 cin 49, 50, 151 clog 242 close() 156, 174 Closing a File 156 coefficient of variance 488 Comments in C++ 31 compiler 12 Compound Assignment Operators 99 Conditional Expression 127 syntax of the conditional expression 127 const 458, 594 const char* 515 const int 275, 372, 415, 458, 507, 546 Constant Data Objects 58 Constants and Data Types 95 double 95 floating point constants 97 int 95 long 95 suffixes 96 unsigned int 95 unsigned long 95 continue Statement 370 Controlling Leading 0's on Output 242 converging series 195 CopyPartialString() 523 cos() 61 Counters and Totals 167 cout 28, 54 Creating Output Files 174 CS02-1 Ticket Prices for a Concert 66 ctype.h 361 current position within the stream pointer 154 Cycle of Data Processing 11, 157, 217 data conversion 48, 598 All types of char and short (signed and unsigned) are automa 89 assigning any floating point type to any of the integer 95 Assigning Smaller Sized Integers to Larger Sized Integers 90 Index 692 Calculations Involving Multiple Floating Point Data Types 93 converts the final value of an expression to the data type of th 91 converts the one of the lesser rank 90 Data Type Ranking 89 Mixed Mode Math 94 Principles of Data Conversion 89 when assigning any float data type to any of the integer data ty 95 data segment 288 Data Type Ranking 89 daysInMonth() 369 debugging dec 353 dec Manipulator Function 242 Decisions 113 decrement operator 98 define multiple variables of the same data type with a single st 44 Definition of Variables 42, 44-46 Designing Solutions 10, 13, 15, 40 diverging series 195 Do Case 351 Do Case Structure 365 Do Case syntax 366 switch 366 Do Loop 179 Do Until Instruction 178 syntax of the Do Until 178 What is the difference between a Do While and a Do Until 178 Do While 178 dot (.) operator 592 double 42, 61, 88, 93 Efficient Loops 183 eject to a new page 282 element 414 End of File 155 endl 29 Engr02a - Pressure Drop 70 entering some real or floating point constant numbers 41 enum 372-374, 376-378, 381, 386 Anonymous enums 377, 404 Enumerated Data Types 371 enum 372-374 eof () 152 Escape Sequences 358 Index 693 exp 62 exp() 198 extern 287 extraction operator 49, 154 fabs 62 file can have no data in it 173 Files 150 How are the input files created 150 ifstream 151 Input Files 151 findAverage() 425 findRanges() 425 float 88, 93 Floating Point Data Types 88 double 88 float 88 long double 88 for Statement 179, 182, 183, 192 for syntax 180 fstream.h 151 function 12 calctax() 229, 230 Code the Function’s Body 225 Define the Function Header 223 Define the Function’s Prototype 221 function coding must be outside of any other block 223 higher() 220 Invoke or Call the Function 226 Writing Your Own Functions 220 function body 26 function header 25 function prototype 29 functional decomposition 216 functions functions are often written to unclutter the main() 291 Functions that Return No Values 240 How a Function Returns a Value 236 More on Functions 272 pass parameters by address 231 variable is passed by value 231 Writing Your Own Functions 216 Gauss elimination 568 Gauss Jordan method 570 Index 694 get() 272, 273, 354, 508, 510, 512 getline() 508, 511, 512 global optimize for speed 181 global variables 284 Global Variables in Other Cpp Files 287 Use of Global Variables 289 Global/External Storage Class 284 lifetime of a global/external variable 284 good () 152 good() 153 Grand Totals 167 headings() 244, 281, 282, 293 hexadecimal 243, 353 higher() 226, 233, 237 hms_to_totsec() 274 How Integer Data Is Stored in Memory 86 How much you indent? 26 How Parameters Are Passed to Functions 231 How to Pass iostreams to Functions 290 I/O Stream States 152 IDE 13 if (!infile) 153, 156 if (!x) 125 if (x = y) 126 if (x) 125, 126 If-then-else 113, 118 AND or OR relational operators 121 a single statement can be a null statement 115 Components of an If-then-else 113 Compound Test Conditions 121 Decisions can be nested 117 efficiency concern 121 else 114 else-clause is optional 114 If-then-else Syntax 113 Nested Decisions 117 nothing to when the statement is false 115 only a single statement to 115 provide the missing else-clause 117 The Test Condition 115 ifstream 151-153, 508, 517 Increment and Decrement Operators 98 increment operator 98, 181 Index 695 postfix inc 98 prefix inc 98 index 414 Initializing Variables and the Assignment Operator 46 Input of Data Values into Variables 49 inputData() 292 Inputting Integers that have Leading Zeros 242 inquiry program 459 Insertion of Floating Point Numbers into an Output Stream 53 insertion operator 28, 51, 52 Additional Insertion Operator Details 63 int 42 Integer Data Types 84, 85 Which Type of Data Do I Use in My Program? 85 integer division 56 Integer Versus Floating Point (Real) Numbers 40 Integration Using Simpson’s Rule 396 iomanip.h 30, 54 ios::adjustfield 513 ios::binary 598 ios::fixed 54, 55 ios::floatfield 55 ios::left 513 ios::right 513 ios::scientific 55 ios::showpoint 54 iostream 290 iostream.h 30, 49 istream 49 Testing for Goodness 153 Iterative Instructions 157 Keyboard Data Entry Sentinel Controlled Loops 162 Labeling Output 55 left justification 513 lineCount 281, 300 Linker program 12 list 458 literal constants 27 loadArray() 422-424, 601, 617 LoadBudget() 550 local heap 288 logic error 16 Logical Not Operator - ! 123 Index 696 long double 89 loop control variable 158, 183 Loops 150 Loops That Are to Be Executed a Known Number of Times 158 Loops to Input All Data in a File 160 main() function 25, 59 MatchId() 460 Math Library Functions 60, 62 Math Operators 56 Matrix Algebra 564 Addition and Subtraction operations 565 column matrix 565 Determinants 566 diagonal matrix 566 Gauss-Jordan Method of Solving Simultaneous Linear Equations 570 identity matrix 566 Mathematical Theorems of Determinants 567 Matrix multiplication 566 Multiplication of a Matrix 565 row matrix 565 square matrix 565 The Gauss Method for Solving a System of Linear Equations 568 Two matrices are said to be equal 565 Maximum and Minimum Values 170 Rule: when finding the maximum or minimum values 170 mean value 488 meaningful names 43 Mechanical Mouse Problem 20 Mechanical Robot Problem 19 member variable 592 Menus as Sentinel Controlled Loops 162 mixed mode math 94, 95 Multi Dimensioned Arrays 545 All elements of every row are entered, but not all rows are inpu 550 column offset 549 Defining Multi Dimensional Arrays 545 Initialization of Multi Dimensional Arrays 548 Input - All elements of every row and all rows are entered 550 Loading a Multi Dimensional Array from an Input File 549 Matrices 564 Passing Multi Dimensioned Arrays to Functions 549 Physical Memory Layout Versus Logical Layout 547 row offset 549 Index 697 Working with Multi Dimensioned Arrays 551 Multiple Assignments 48 Multiple Level Control Break Processing 293, 299 control fields 300 processing steps 301 name of a function is the memory address 311 namespace 30 namespace std 361 NameToCommaForm() 524 NameToParts() 524 Nesting of Loops 184, 185 new line code 28, 29 Newton’s Method of Root Solving 324 null terminated strings 506 Numerical Analysis 249, 251 desired degree of accuracy 249 estimate of the error 249 limited range 249 rapidity of convergence 250 Numerical Integration 391 Integration Using Simpson’s Rule 396 Simpson’s Rule 396 trapezoid method 391 Numerical Processing 40 object file 12 octal 243 ofstream 174 open() 151, 517 OR || operators 122 OR logic 121 || 121 ostream 28, 53, 293 output file 174 How you write data to the file 175 output manipulator 29 Output of a Variable 51, 56 output stream 28 overflow 87 Integer Variable Overflow 87, 88 pageNum 282 parallel arrays 458 PI Most Accurate Value of PI 62 Index 698 Plot() 442, 443 Plotting Graphs 440 pow() 61 Precedence of Operators 128, 129 Precedence or Priority of Operators 57 Use () to override the precedence of operators 57 Primed Input Loops that Detect End of File 163 primed loop 163, 164 PrintReport() 601, 617 printResults() 425 pseudocode 14 put() 356, 444 quadratic equation 136 read() 598, 599 reference variable 272 Reference Variables 272 Need for Reference Variables 272 reference variable 277 To make a reference variable 278 register 235 Registers and the Stack 235 Regula Falsi Root Solving Method 320 remainder operator 56 Right alignment 513 Root Solving 251 Bisection Revisited 310 Newton’s method 324 Regula Falsi 320 secant method 331 Summary of Root Solving Techniques 336 the Bisection Method 251, 254 Rules 25-27, 30, 31, 42, 43, 46, 47, 50 All automatic and parameter storage class variables are stored o 236 Data Conversion Rule 89 Data Conversion Rule 90 Data Conversion Rule 91 Data Conversion Rule 95 entire If-then-else must be within the loop 184 For local type variables, the scope is from the point of their d 232 For parameter type variables, the scope is from the point of the 232 If a valid character to be input could contain white space 355 inner loop must be entirely contained within the outer loop 184 pass iostreams and file streams by reference 291 Index 699 Rule All while loops can be rewritten as a more compact for 181 Rule: when finding the maximum or minimum values, initialize 170 Rules of Use for Structure Variables 593 The function coding must be outside of any other block of coding 223 The rules for counters and totals 168 scope of a variable 232 variables to become hidden within blocks of coding 234 Secant Method of Root Solving 331 Sentinel Controlled Input Loops 160 sentinel value 160 setf() 54, 161, 513 setfill() 242 setprecision() 54, 55 setprecision 55 setup floating point format 160, 175 setw() 53, 355 setw() Function 53 short 87, 88 Simp() 397 sin() 61 sizeof() 510, 517, 552 SortArray() 559, 601 SortArrays() 466 source program 11 spreadsheet 545 sqrt() 60 stack 236, 288 standard deviation 488 static 283 Static Storage Class 281 global/external storage 284 lifetime of a static variable 283 main storage classes 289 scope of a static variable 283 static 283 Statistical Computations 488 stdlib.h 511 storage classes 234 automatic 234 parameter 234 strcat() 517, 519 strchr() 520 strcmp() 515, 518, 519 Index 700 strcpy() 516, 520, 560 stricmp() 515, 518, 519, 559 String Functions 518 string.h 515 Strings 506 array of character strings 557 Character String Manipulation 523 Defining Character Strings 506 extraction operator 507 get() 508 getline() 508 How Could String Functions Be Implemented 522 Input - All strings Are Delimited 512 Input - All Strings Have the Same Length 509 Input - Is the Last Field on a Line 511 Inputting Character Strings 507 Left alignment 513 null terminator 506 null-terminator 506 Outputting Character Strings 512 Passing a String to a Function 514 string functions 518 trailing blanks can be removed 509 Working with Strings 514 strlen() 517, 518 strlwr() 521 strrev() 522 strstr() 520 structure variable 592 Structured programming 23, 24 Structures 588 arrays of structures 590 Binary Files and Structures 597 can also contain instances of other structures and arrays of oth 591 can contain arrays 589 Creating Instances of a Structure 590 Defining Structures 588 How are Structure Members Accessed? 592 How are Structures Initialized? 592 pass the structure variable by reference 594 struct 588 structure members 589 structure tag 588 Index 701 structure template 588 structure variable 590 structure variable can be passed to a function 593 Structure variables can be used for 593 Where are the structure templates located 589 strupr() 521 subscript 414 subscript out of bounds 416 sumcol() 552 Summary Reports Based upon Control Break Processing 307 Summation of a Series 166 Summation of Infinite Polynomials 194 sumrow() 551 switch 366-369, 386 syntax error 16 table 458 table lookup 458 tan() 61 Test conditions 115, 127, 157 basic format 115 Data Type and Value of Relational Expressions 124 result of any test condition or relational expression 124 six comparison operators 115 testing floating point numbers 130 Testing for Bad Data Entry 154 Testing of Real Numbers 129 To develop a total 158 Top-down design 216-218, 245, 254, 301 totsec_to_hms() 278 toupper 361 Trap() 397 Trapezoid Method of Numerical Integration 391 Typecast 91, 92 typedef 311 types of variables 232 global 232 local 232 parameter 232 Types, Scope and Storage Classes of Variables 232 unsigned char 87 User Written Header Files 596 Using a Generic processFile() Function 385 Using Menus to Control Program Operation 399 Index 702 variables 22, 40, 46 variance 488 Vector Coordinate Conversions 437 What is a Computer 7-9 What is a program? Where are Global and Static Variables Actually Stored 288 Where are the variable definitions placed within a program? 46 Where Should Error Messages Be Displayed 241 Which Type of Data Do I Use in My Program? 85 Which Type of Data Do You Use for Which Variable? 41 while 157-163, 165, 167, 173, 178, 179, 181, 182, 184, 196, 292, 419, 459, 510, 595, 599 while (cin >> quantity >> cost) 165 while (infile) 163-165 White space, 26 write() 598 ws is another manipulator 419 .. .C++ for Computer Science and Engineering Vic Broquard Copyright 2000, 2002, 2003, 2006 by Vic Broquard All rights reserved No part of this book may be reproduced or transmitted in any form... the C++ language was formally standardized by ISO (International Standards Organization) This means that now your C++ program can be written and compiled on any computer platform (PCs, minicomputers,... assignments and should definitely lower the frustration level What is a Computer? A definition of a computer is an electronic device that can input data, process data and output data, accurately and