C++程序设计 : 第8版
C++程序设计 : 第8版封面图

C++程序设计 : 第8版

(美) 萨维奇 (Savitch,W.) , 著

出版社:清华大学出版社

年代:2014

定价:79.0

书籍简介:

本书是最优秀的C++入门教材之一,在全球已经拥有数十万读者。作者结合自己多年的教学经验,根据教学大纲精心设计并编写了书中内容。与此同时,还采用了很多便于读者巩固所学知识的教学特征,比如各章开始处的小节总览,书中随处可见的总结框、编程提示和编程陷阱,各章结尾处的小结、习题和编程项目等。这些非常适合初学者掌握重要的编程概念。

作者介绍:

Walter Savitch,美国加州大学圣地亚哥分校荣誉退休教授,拥有加州大学伯克利分校博士学位,曾担任加州大学圣地亚哥分校计算机科学系教授和认知科学跨学科博士项目主任。他在复杂性理论和并行计算模型方面具有卓越的贡献,其研究领域包括形式语言理论计算语言学等。Savitch教授还是C++和Java经典教材的缔造者,他的作品通俗易懂,生动有趣,贴近生活,应用性和实用性很强,深受全球数十万读者(包括教师和学生)的欢迎。

书籍目录:

Brief Contents

Table of Location of VideoNotes

Inside front cover and inside back cover

Chapter 1 1Introduction to Computers and C++ Programming 1

Chapter 2 2C++ Basics 39

Chapter 3 3More Flow of Control 109

Chapter 4 4Procedural Abstraction and Functions That Return a Value 177

Chapter 5 5Functions for All Subtasks 247

Chapter 6 6I/O Streams as an Introduction to Objects and Classes 301

Chapter 7 7Arrays 373

Chapter 8 8Strings and Vectors 441

Chapter 9 9Pointers and Dynamic Arrays 493

Chapter 10 0Defining Classes 525

Chapter 11 Friends, Overloaded Operators, and Arrays in Classes 601

Chapter 12 Separate Compilation and Namespaces 685

Chapter 13 Pointers and Linked Lists 721

Chapter 14 Recursion 769

Chapter 15 Inheritance 811

Chapter 16 Exception Handling 867

Chapter 17 Templates 899

Chapter 18 Standard Template Library 931

Appendices

1 C++ Keywords 987

2 Precedence of Operators 988

3 The ASCII Character Set 990

4 Some Library Functions 991

5 Inline Functions 998

6 Overloading the Array Index Square Brackets 999

7 The this Pointer 1001

8 Overloading Operators as Member Operators 1004

Table of Location of VideoNotes

Inside front cover and inside back cover

Chapter 1 1Introduction to Computers and C++ Programming 1

1.1 COMPuTER SYSTEMS 2

Hardware 2

Software 7

High-Level Languages 8

Compilers 9

History Note 12

1.2 PROgRAMMINg AND PROBLEM-SOLVINg 12

Algorithms 12

Program Design 15

Object-Oriented Programming 16

The Software Life Cycle 17

1.3 INTRODuCTION TO C++ 18

Origins of the C++ Language 18

A Sample C++ Program 19

Pitfall: Using the Wrong Slash in \n 23

Programming Tip: Input and Output Syntax 23

Layout of a Simple C++ Program 24

Pitfall: Putting a Space Before the include File Name 26

Compiling and Running a C++ Program 26

Programming Tip: Getting Your Program to Run 27

1.4 TESTINg AND DEBuggINg 29

Kinds of Program Errors 30

Pitfall: Assuming Your Program Is Correct 31

Chapter Summary 31

1Answers to Self-Test Exercises 32

2Programming Projects 35

Chapter 2 C++ Basics 39

2.1 VARIABLES AND ASSIgNMENTS 40

Variables 40

0Names: Identifiers 42

2Variable Declarations 44

4Assignment Statements 45

5Pitfall: Uninitialized Variables 47

7Programming Tip: Use Meaningful Names 49

2.2 INPuT AND OuTPuT 50

Output Using cout 50

Include Directives and Namespaces 52

Escape Sequences 53

Programming Tip: End Each Program with a \n or endl 54

Formatting for Numbers with a Decimal Point 55 Input Using cin 56

Designing Input and Output 58

Programming Tip: Line Breaks in I/O 58

2.3 DATA TYPES AND ExPRESSIONS 60

The Types int and double 60

0Other Number Types 62

2The Type char 63

3The Type bool 64

4Introduction to the Class string 65

5Type Compatibilities 66

6Arithmetic Operators and Expressions 68

8Pitfall: Whole Numbers in Division 71

1More Assignment Statements 73

2.4 SIMPLE FLOw OF CONTROL 73

A Simple Branching Mechanism 74

4Pitfall: Strings of Inequalities 79

9Pitfall: Using = in place of == 80

0Compound Statements 81

1Simple Loop Mechanisms 83

Increment and Decrement Operators 86

Programming Example: Charge Card Balance 88

Pitfall: Infinite Loops 89

2.5 PROgRAM STYLE 92

Indenting 92 Comments 92 Naming Constants 94

Chapter Summary 97 Answers to Self-Test Exercises 97

Programming Projects 102

Chapter 3 More Flow of Control 109

3.1 uSINg BOOLEAN ExPRESSIONS 110

Evaluating Boolean Expressions 110

Pitfall: Boolean Expressions Convert to int Values 114

Enumeration Types (Optional) 117

3.2 MuLTIwAY BRANCHES 118

Nested Statements 118

Programming Tip: Use Braces in Nested Statements 119

Multiway if-else Statements 121

Programming Example: State Income Tax 123

The switch Statement 126

Pitfall: Forgetting a break in a switch Statement 130

Using switch Statements for Menus 131

Blocks 133

Pitfall: Inadvertent Local Variables 136

3.3 MORE ABOuT C++ LOOP STATEMENTS 137

The while Statements Reviewed 137

Increment and Decrement Operators Revisited 139

The for Statement 142

Pitfall: Extra Semicolon in a for Statement 147

What Kind of Loop to Use 148

Pitfall: Uninitialized Variables and Infinite Loops 150

The break Statement 151 Pitfall: The break Statement in Nested Loops 152

7387_Savitch_FM_ppi-xxx.indd 18 2/2/11 5:45 PM

contents xix

3.4 DESIgNINg LOOPS 153

Loops for Sums and Products 153 Ending a Loop 155 Nested Loops 158 Debugging Loops 160

Chapter Summary 163 Answers to Self-Test Exercises 164 Programming Projects 170

Chapter 4 4Procedural Abstraction and Functions That Return a Value 177

4.1 TOP-DOwN DESIgN 178

4.2 PREDEFINED FuNCTIONS 179

Using Predefined Functions 179 Random Number Generation 184 Type Casting 186 Older Form of Type Casting 188 Pitfall: Integer Division Drops the Fractional Part 188

4.3 PROgRAMMER-DEFINED FuNCTIONS 189

Function Definitions 189 Functions That Return a Boolean Value 195 Alternate Form for Function Declarations 195 Pitfall: Arguments in the Wrong Order 196 Function Definition–Syntax Summary 197 More About Placement of Function Definitions 198 Programming Tip: Use Function Calls in Branching Statements 199

4.4 PROCEDuRAL ABSTRACTION 200

The Black-Box Analogy 200 Programming Tip: Choosing Formal Parameter Names 203 Programming Tip: Nested Loops 204 Case Study: Buying Pizza 207 Programming Tip: Use Pseudocode 213

4.5 SCOPE AND LOCAL VARIABLES 214

The Small Program Analogy 214 Programming Example: Experimental Pea Patch 217

Global Constants and Global Variables 217 Call-by-Value Formal Parameters Are Local Variables 220 Block Scope 222 Namespaces Revisited 223 Programming Example: The Factorial Function 226

4.6 OVERLOADINg FuNCTION NAMES 228

Introduction to Overloading 228 Programming Example: Revised Pizza-Buying Program 231 Automatic Type Conversion 234 Chapter Summary 236 Answers to Self-Test Exercises 236 Programming Projects 241

Chapter 5 Functions for All Subtasks 247

5.1 void FuNCTIONS 248

Definitions of void Functions 248 Programming Example: Converting Temperatures 251 return Statements in void Functions 251

5.2 CALL-BY-REFERENCE PARAMETERS 255

A First View of Call-by-Reference 255 Call-by-Reference in Detail 258 Programming Example: The swap_values Function 263 Mixed Parameter Lists 264 Programming Tip: What Kind of Parameter to Use 265 Pitfall: Inadvertent Local Variables 266

5.3 uSINg PROCEDuRAL ABSTRACTION 269

Functions Calling Functions 269 Preconditions and Postconditions 271 Case Study: Supermarket Pricing 272

5.4 TESTINg AND DEBuggINg FuNCTIONS 277

Stubs and Drivers 278

5.5 gENERAL DEBuggINg TECHNIquES 283

Keep an Open Mind 283 Check Common Errors 283 Localize the Error 284 The assert Macro 286 2/2/11 5:45 PM

Chapter Summary 288

8Answers to Self-Test Exercises 289

9Programming Projects 292

Chapter 6 6I/O Streams as an Introduction to Objects and Classes 301

6.1 STREAMS AND BASIC FILE I/O 302

Why Use Files for I/O? 303

3File I/O 304

4Introduction to Classes and Objects 308

8Programming Tip: Check Whether a File Was Opened

d Successfully 310

0Techniques for File I/O 312

2Appending to a File (Optional) 316

6File Names as Input (Optional) 317

6.2 TOOLS FOR STREAM I/O 319

Formatting Output with Stream Functions 319

9Manipulators 325

5Streams as Arguments to Functions 328

8Programming Tip: Checking for the End of a File 328

8A Note on Namespaces 331

1Programming Example: Cleaning Up a File Format 332

6.3 CHARACTER I/O 334

The Member Functions get and put 334

4The putback Member Function (Optional) 338

8Programming Example: Checking Input 339

9Pitfall: Unexpected '\n' in Input 341

1Programming Example: Another new_line Function 343

3Default Arguments for Functions (Optional) 344

4The eof Member Function 349

9Programming Example: Editing a Text File 351

1Predefined Character Functions 352

2Pitfall: toupper and tolower Return Values 354

Chapter Summary 356

6Answers to Self-Test Exercises 357

7Programming Projects 364

Chapter 7 Arrays 373

7.1 INTRODuCTION TO ARRAYS 374

Declaring and Referencing Arrays 374 Programming Tip: Use for Loops with Arrays 376 Pitfall: Array Indexes Always Start with Zero 376 Programming Tip: Use a Defined Constant for the Size of an Array 376 Arrays in Memory 378 Pitfall: Array Index Out of Range 379 Initializing Arrays 381

7.2 ARRAYS IN FuNCTIONS 383

Indexed Variables as Function Arguments 383 Entire Arrays as Function Arguments 385 The const Parameter Modifier 388 Pitfall: Inconsistent Use of const Parameters 391 Functions That Return an Array 391 Case Study: Production Graph 392

7.3 PROgRAMMINg wITH ARRAYS 405

Partially Filled Arrays 405 Programming Tip: Do Not Skimp on Formal Parameters 408 Programming Example: Searching an Array 408 Programming Example: Sorting an Array 411

7.4 MuLTIDIMENSIONAL ARRAYS 415

Multidimensional Array Basics 416 Multidimensional Array Parameters 416 Programming Example: Two-Dimensional Grading Program 418 Pitfall: Using Commas Between Array Indexes 422

Chapter Summary 423 Answers to Self-Test Exercises 424 Programming Projects 428

Chapter 8 Strings and Vectors 441

8.1 AN ARRAY TYPE FOR STRINgS 443

C-String Values and C-String Variables 443 Pitfall: Using = and == with C Strings 446 2/2/11 5:45 PM

contents xxiii

Other Functions in 448

8C-String Input and Output 453

3C-String-to-Number Conversions and Robust Input 455

8.2 THE STANDARD string CLASS 461

Introduction to the Standard Class string 461

1I/O with the Class string 464

4Programming Tip: More Versions of getline 467

7Pitfall: Mixing cin >> variable; and getline 468

8String Processing with the Class string 469

9Programming Example: Palindrome Testing 473

3Converting Between string Objects and C Strings 476

8.3 VECTORS 477

Vector Basics 477 Pitfall: Using Square Brackets Beyond the Vector Size 480 Programming Tip: Vector Assignment Is Well Behaved 481 Efficiency Issues 481

Chapter Summary 483

3Answers to Self-Test Exercises 484

4Programming Projects 486

Chapter 9 Pointers and Dynamic Arrays 493

9.1 POINTERS 494

Pointer Variables 495

5Basic Memory Management 502

2Pitfall: Dangling Pointers 503

3Static Variables and Automatic Variables 504

4Programming Tip: Define Pointer Types 504

9.2 DYNAMIC ARRAYS 507

Array Variables and Pointer Variables 507

7Creating and Using Dynamic Arrays 508

8Pointer Arithmetic (Optional) 514

4Multidimensional Dynamic Arrays (Optional) 516

Chapter Summary 518

8Answers to Self-Test Exercises 518

8Programming Projects 519

Chapter 10 0Defining Classes 525

10.1 STRuCTuRES 526

Structures for Diverse Data 526

Pitfall: Forgetting a Semicolon in a Structure Definition 531

Structures as Function Arguments 532

Programming Tip: Use Hierarchical Structures 533

Initializing Structures 535

10.2 CLASSES 538

Defining Classes and Member Functions 538 Public and Private Members 543 Programming Tip: Make All Member Variables Private 551 Programming Tip: Define Accessor and Mutator Functions 551 Programming Tip: Use the Assignment Operator with Objects 553 Programming Example: BankAccount Class—Version 1 554 Summary of Some Properties of Classes 558 Constructors for Initialization 560 Programming Tip: Always Include a Default Constructor 568 Pitfall: Constructors with No Arguments 569

10.3 ABSTRACT DATA TYPES 571

Classes to Produce Abstract Data Types 572 Programming Example: Alternative Implementation of a Class 576

10.4 INTRODuCTION TO INHERITANCE 581

Derived Classes 582 Defining Derived Classes 583

Chapter Summary 587 Answers to Self-Test Exercises 588 Programming Projects 594

Chapter 11 1Friends, Overloaded Operators, and Arrays in Classes 601

11.1 FRIEND FuNCTIONS 602

Programming Example: An Equality Function 602 Friend Functions 606 Programming Tip: Define Both Accessor Functions and Friend Functions 608 2/2/11 5:45 PM

contents xxv

Programming Tip: Use Both Member and Nonmember Functions 610 Programming Example: Money Class (Version 1) 610 Implementation of digit_to_int (Optional) 617 Pitfall: Leading Zeros in Number Constants 618 The const Parameter Modifier 620 Pitfall: Inconsistent Use of const 621

11.2 OVERLOADINg OPERATORS 625

Overloading Operators 626

6Constructors for Automatic Type Conversion 629

9Overloading Unary Operators 631

1Overloading >> and

内容摘要:


  《C++程序设计(第8版 影印版)》是最优秀的C++入门教材,深受师生欢迎。作者结合自己多年的教学经验,根据教学大纲精心设计并编写了书中内容。与此同时,本书还采用了很多便于读者巩固所学知识的教学特征,比如各章开始处的小节总览,书中随处可见的总结框、编程提示和编程陷阱,各章结尾处的小结、习题和编程项目等。这些非常适合初学者掌握重要的编程概念。
  《C++程序设计(第8版 影印版)》共18章,8个附录。在讲解C++基础知识之后,直接引导学生深入函数、I/O流、类、控制流程、命名空间、数组、字符串、指针和动态数组、递归、模板、指针和链表、派生类、异常以及标准模板库。
  Original edition, entitled PROBLEM SOLVING WITH C++, 8E, 9780132162739 by SAVITCH,
  WALTER, published by Pearson Education, Inc, publishing as Addison-Wesley, Copyright ? 2012 Pearson Education, Inc..
  All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording or by any information storage retrieval system, without permission from Pearson Education, Inc.
  China edition published by PEARSON EDUCATION ASIA LTD., and TSINGHUA UNIVERSITY PRESS LIMITED Copyright ? 2014.
  This edition is manufactured in the People’s Republic of China, and is authorized for sale and distribution in the People’s Republic of China exclusively (except Taiwan, Hong Kong SAR and Macau SAR).
  《C++程序设计(第8版 影印版)》影印版由Pearson Education授权给清华大学出版社在中国境内(不包括中国台湾、香港特别行政区和澳门特别行政区)出版发行。

书籍规格:

书籍详细信息
书名C++程序设计 : 第8版站内查询相似图书
9787302386445
如需购买下载《C++程序设计 : 第8版》pdf扫描版电子书或查询更多相关信息,请直接复制isbn,搜索即可全网搜索该ISBN
出版地北京出版单位清华大学出版社
版次影印本印次1
定价(元)79.0语种英文
尺寸23 × 19装帧平装
页数印数 2500

书籍信息归属:

C++程序设计 : 第8版是清华大学出版社于2015.出版的中图分类号为 TP312 的主题关于 C语言-程序设计-教材-英文 的书籍。