1. Trang chủ
  2. » Công Nghệ Thông Tin

Fundamentals of Programming doc

566 4,9K 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 566
Dung lượng 5,68 MB

Nội dung

Fundamentals of Programming C ++ DRAFT Richard L. Halterman School of Computing Southern.Adventist University January 27, 2013 Copyright © 2013 Richard L. Halterman. All rights reserved. i Contents 1 The Context of Software Development 1 1.1 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 Development Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.3 Learning Programming with C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2 Writing a C++ Program 7 2.1 General Structure of a Simple C++ Program . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.2 Compiling the source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.3 Variations of our simple program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.4 Template for simple C++ programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3 Values and Variables 21 3.1 Integer Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.2 Variables and Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.3 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.4 Floating-point Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.5 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 3.6 Other Numeric Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 3.7 Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.8 Enumerated Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.9 Type Inference with auto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 3.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 ©2013 Richard L. Halterman Draft date: January 27, 2013 CONTENTS ii 3.11 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 4 Expressions and Arithmetic 41 4.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.2 Mixed Type Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 4.3 Operator Precedence and Associativity . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 4.4 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 4.5 Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 4.6 Errors and Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 4.6.1 Compile-time Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 4.6.2 Run-time Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 4.6.3 Logic Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 4.6.4 Compiler Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 4.7 Arithmetic Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 4.8 More Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 4.9 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 4.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 4.11 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 5 Conditional Execution 75 5.1 Type bool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 5.2 Boolean Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 5.3 The Simple if Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 5.4 Compound Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 5.5 The if/else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 5.6 Compound Boolean Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 5.7 Nested Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 5.8 Multi-way if/else Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 5.9 Errors in Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 5.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 5.11 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 6 Iteration 107 6.1 The while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 6.2 Nested Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 ©2013 Richard L. Halterman Draft date: January 27, 2013 CONTENTS iii 6.3 Abnormal Loop Termination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 6.3.1 The break statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 6.3.2 The goto Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 6.3.3 The continue Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 6.4 Infinite Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 6.5 Iteration Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 6.5.1 Drawing a Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 6.5.2 Printing Prime Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 6.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 6.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 7 Other Conditional and Iterative Statements 147 7.1 The switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 7.2 The Conditional Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 7.3 The do/while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 7.4 The for Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 7.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 7.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 8 Using Functions 167 8.1 Introduction to Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 8.2 Standard Math Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 8.3 Maximum and Minimum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 8.4 clock Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 8.5 Character Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 8.6 Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 8.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 8.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 9 Writing Functions 187 9.1 Function Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 9.2 Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 9.3 Call by Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 9.4 Function Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 9.4.1 Better Organized Prime Generator . . . . . . . . . . . . . . . . . . . . . . . . . . 202 ©2013 Richard L. Halterman Draft date: January 27, 2013 CONTENTS iv 9.4.2 Command Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 9.4.3 Restricted Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 9.4.4 Better Die Rolling Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 9.4.5 Tree Drawing Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 9.4.6 Floating-point Equality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 9.4.7 Multiplication Table with Functions . . . . . . . . . . . . . . . . . . . . . . . . . 213 9.5 Commenting Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 9.6 Custom Functions vs. Standard Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 218 9.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 9.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 10 More on Functions 227 10.1 Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 10.2 Static Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 10.3 Overloaded Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 10.4 Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 10.5 Making Functions Reusable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 10.6 Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 10.7 Call by Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 10.7.1 Call by Reference via Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 10.7.2 Call by Reference via References . . . . . . . . . . . . . . . . . . . . . . . . . . 257 10.8 Function Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 10.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 10.10Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 11 Arrays 269 11.1 Declaring and Using Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 11.2 Arrays and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 11.3 Prime Generation with an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 11.4 Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 11.5 Pointers and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 11.6 Array Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 11.7 C Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 11.8 Dynamic Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 11.9 The sizeof Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300 ©2013 Richard L. Halterman Draft date: January 27, 2013 CONTENTS v 11.10Copying an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 11.11Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 11.12Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 11.13Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 12 Array Algorithms 313 12.1 Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 12.2 Flexible Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 12.3 Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 12.3.1 Linear Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 12.3.2 Binary Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 12.4 Array Permutations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330 12.5 Randomly Permuting an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 12.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 12.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 13 Standard C++ Classes 347 13.1 String Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 13.2 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351 13.2.1 Declaring and Using Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352 13.2.2 Copying Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354 13.2.3 Vectors and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360 13.3 Input/Output Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362 13.4 File Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366 13.5 Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370 13.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 13.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 14 Custom Objects 375 14.1 Object Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 14.2 Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 14.3 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 14.4 Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390 14.5 Destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392 14.6 Defining a New Numeric Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394 ©2013 Richard L. Halterman Draft date: January 27, 2013 CONTENTS vi 14.7 Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396 14.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 14.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400 15 More on Objects 407 15.1 Pointers to Objects and Object Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 15.2 The this Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410 15.3 const Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412 15.4 Separating Method Declarations and Definitions . . . . . . . . . . . . . . . . . . . . . . . 414 15.5 Preventing Multiple Inclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421 15.6 Overloaded Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424 15.6.1 Operator Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424 15.6.2 Operator Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428 15.7 static Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429 15.8 Classes vs. structs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433 15.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434 15.10Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 16 Building some Useful Classes 437 16.1 A Better Rational Number Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 16.2 Stopwatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440 16.3 Sorting with Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446 16.4 Linked Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450 16.5 Automating Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 16.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 16.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 17 Inheritance and Polymorphism 467 17.1 I/O Stream Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467 17.2 Inheritance Mechanics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469 17.3 Uses of Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472 17.4 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479 17.5 Protected Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485 17.6 Fine Tuning Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 17.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 ©2013 Richard L. Halterman Draft date: January 27, 2013 CONTENTS vii 17.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506 18 Generic Programming 509 18.1 Function Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509 18.2 Class Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516 18.3 The Standard Template Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526 18.4 Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526 18.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 18.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 19 Exception Handling 529 19.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529 19.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529 Appendices 533 A Visual C++ Command Line Development 533 B Developing C++ Programs under Unix/Linux with the GNU Tools 537 C Introduction to Binary Numbers and Computer Arithmetic 539 C.1 The Integer Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539 C.2 The Floating-Point Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544 D Bitwise Operators 549 Bibliography 553 Index 554 ©2013 Richard L. Halterman Draft date: January 27, 2013 CONTENTS viii ©2013 Richard L. Halterman Draft date: January 27, 2013 [...]... large collection of code developed in C C++ is widely used in industry for commercial software development It is an industrial strength programming language used for developing complex systems in business, science, and engineering Examples of software written in C++ include Microsoft Windows 8, Microsoft Of ce, Mac OS X, and Adobe Creative Suite In order to meet the needs of commercial software development... plethora of tools (and tool vendors’ claims), the programming process for all but trivial programs is not automatic Good tools are valuable and certainly increase the productivity of developers, but they cannot write software There are no substitutes for sound logical thinking, creativity, common sense, and, of course, programming experience 1.3 Learning Programming with C++ Bjarne Stroustrup of AT&T... 1.1 2 Software A computer program is an example of computer software Software makes a computer a truly universal machine transforming it into the proper tool for the task at hand One can refer to a program as a piece of software as if it were a tangible object, but software is actually quite intangible It is stored on a medium A hard drive, a CD, a DVD, and a USB pen drive are all examples of media... in any copies of this document made in whole or in part • None of material herein can be sold or otherwise distributed for commercial purposes without written permission of the copyright holder • Instructors at any educational institution may freely use this document in their classes as a primary or optional textbook under the conditions specified above A local electronic copy of this document may be... main purpose of profiling is to find the parts of a program that can be improved to make the program run faster The programming components of the development process are illustrated in Figure 1.1 Many developers use integrated development environments (IDEs) An IDE includes editors, debuggers, and other programming aids in one comprehensive program Examples of IDEs for C++ include Microsoft’s Visual... both hardware and software to operate Software consists of instructions that control the hardware • At the lowest level, the instructions for a computer program can be represented as a sequence of zeros and ones The pattern of zeros and ones determine the instructions performed by the processor • Two different kinds of processors can have different machine languages • Application software can be written... programmers today write software at this higher, more abstract level also An accomplished computer programmer can develop sophisticated software with little or no interest or knowledge of the actual computer system upon which it runs Powerful software construction tools hide the lower-level details from programmers, allowing them to solve problems in higher-level terms The concepts of computer programming are... without the use of a computer Programmers can discuss the viability of a program and reason about its correctness and efficiency by examining abstract symbols that correspond to the features of real-world programming languages but appear in no real-world programming language While such exercises can be very valuable, in practice computer programmers are not isolated from their machines Software is written... in the mid 1980s C++ is an extension of the programming language C, a product of AT&T Bell Labs from the early 1970s C was developed to write the Unix operating system, and C is widely used for systems-level software and embedded systems development C++ initially provided object-oriented programming features (see Chapter 13 and Chapter 14) and later added generic programming capabilities C++’s close... Computing professionals known as software engineers develop software to drive particular systems These systems are defined by their underlying hardware and operating system Developers use concrete tools like compilers, debuggers, and profilers This chapter examines the context of software development, including computer systems and tools ©2013 Richard L Halterman Draft date: January 27, 2013 1.1 SOFTWARE . Examples of software written in C ++ include Microsoft Windows 8, Microsoft Of ce, Mac OS X, and Adobe Creative Suite. In order to meet the needs of commercial. all examples of media upon which software can reside. The CD is not the software; the software is a pattern on the CD. In order to be used, software must

Ngày đăng: 08/03/2014, 11:20

TỪ KHÓA LIÊN QUAN

w