Giải Quyết Vấn Đề Với C++ - Ấn Bản Thứ Chín Của Walter Savitch

Khám phá phương pháp giải quyết vấn đề trong lập trình C qua cuốn sách "Problem Solving with C" của Walter Savitch, ấn bản thứ chín.

Trường đại học

University of California, San Diego

Chuyên ngành

Computer Science

Người đăng

Ẩn danh

Thể loại

textbook

2015

1.1K
0
0

Phí lưu trữ

30 Point

Mục lục chi tiết

Preface

1. CHƯƠNG 1: Introduction to Computers and C++ Programming

1.1. Computer Systems

1.2. Programming and Problem-Solving

1.3. Introduction to C++

1.4. Testing and Debugging

2. CHƯƠNG 2: C++ Basics

2.1. Variables and Assignments

2.2. Input and Output

2.3. Data Types and Expressions

2.4. Simple Flow of Control

2.5. Program Style

3. CHƯƠNG 3: More Flow of Control

3.1. Using Boolean Expressions

3.2. Multiway Branches

3.3. More About C++ Loop Statements

4. CHƯƠNG 4: Procedural Abstraction and Functions That Return a Value

5. CHƯƠNG 5: Functions for All Subtasks

6. CHƯƠNG 6: I/O Streams as an Introduction to Objects and Classes

7. CHƯƠNG 7: Arrays

8. CHƯƠNG 8: Strings and Vectors

9. CHƯƠNG 9: Pointers and Dynamic Arrays

10. CHƯƠNG 10: Defining Classes

11. CHƯƠNG 11: Friends, Overloaded Operators, and Arrays in Classes

12. CHƯƠNG 12: Separate Compilation and Namespaces

13. CHƯƠNG 13: Pointers and Linked Lists

14. CHƯƠNG 14: Recursion

15. CHƯƠNG 15: Inheritance

16. CHƯƠNG 16: Exception Handling

17. CHƯƠNG 17: Templates

18. CHƯƠNG 18: Standard Template Library

Appendices

1. C++ Keywords

2. Precedence of Operators

3. The ASCII Character Set

4. Some Library Functions

5. Inline Functions

6. Overloading the Array Index Square Brackets

7. The this Pointer

8. Overloading Operators as Member Operators

Index

Tóm tắt

I. Tổng Quan Về Giải Quyết Vấn Đề Với C Ấn Bản Thứ Chín

Cuốn sách "Giải Quyết Vấn Đề Với C++ - Ấn Bản Thứ Chín" của Walter Savitch là một tài liệu quan trọng cho những ai muốn bắt đầu học lập trình với ngôn ngữ C++. Cuốn sách này không chỉ cung cấp kiến thức cơ bản mà còn giúp người đọc phát triển kỹ năng giải quyết vấn đề thông qua lập trình. Với cách tiếp cận dễ hiểu, cuốn sách phù hợp cho cả những người mới bắt đầu và những lập trình viên có kinh nghiệm.

1.1. Nội Dung Chính Của Cuốn Sách

Cuốn sách bao gồm nhiều chủ đề từ cơ bản đến nâng cao, bao gồm các khái niệm như biến, kiểu dữ liệu, cấu trúc điều khiển và hàm. Đặc biệt, cuốn sách cũng giới thiệu về C++11, giúp người học nắm bắt các tính năng mới của ngôn ngữ này.

1.2. Đối Tượng Độc Giả

Cuốn sách này hướng đến những người mới bắt đầu học lập trình cũng như những sinh viên ngành khoa học máy tính. Nó cung cấp một nền tảng vững chắc cho việc học lập trình và giải quyết vấn đề trong C++.

II. Các Vấn Đề Thường Gặp Khi Học C

Học lập trình với C++ không phải lúc nào cũng dễ dàng. Nhiều người học gặp phải các vấn đề như hiểu sai về cú pháp, lỗi biên dịch và các khái niệm lập trình cơ bản. Những thách thức này có thể gây khó khăn cho việc tiếp thu kiến thức và kỹ năng lập trình.

2.1. Lỗi Cú Pháp Thường Gặp

Một trong những lỗi phổ biến nhất là sử dụng sai dấu chấm phẩy hoặc dấu ngoặc. Những lỗi này có thể dẫn đến việc chương trình không biên dịch được, gây khó khăn cho người học trong việc tìm ra nguyên nhân.

2.2. Khó Khăn Trong Việc Hiểu Các Khái Niệm Cơ Bản

Nhiều người học gặp khó khăn trong việc nắm bắt các khái niệm như biến, kiểu dữ liệu và cấu trúc điều khiển. Điều này có thể làm cho việc học trở nên chậm chạp và không hiệu quả.

III. Phương Pháp Giải Quyết Vấn Đề Trong C

Cuốn sách của Walter Savitch cung cấp nhiều phương pháp và kỹ thuật để giải quyết vấn đề trong lập trình C++. Những phương pháp này không chỉ giúp người học hiểu rõ hơn về ngôn ngữ mà còn phát triển tư duy logic và khả năng phân tích.

3.1. Sử Dụng Thuật Toán Để Giải Quyết Vấn Đề

Cuốn sách nhấn mạnh tầm quan trọng của việc sử dụng thuật toán trong lập trình. Việc áp dụng các thuật toán đúng cách giúp người học giải quyết vấn đề một cách hiệu quả hơn.

3.2. Thực Hành Qua Các Bài Tập

Cuốn sách cung cấp nhiều bài tập thực hành để người học có thể áp dụng kiến thức đã học. Những bài tập này giúp củng cố kỹ năng lập trình và giải quyết vấn đề trong C++.

IV. Ứng Dụng Thực Tiễn Của C Trong Lập Trình

Ngôn ngữ C++ được sử dụng rộng rãi trong nhiều lĩnh vực khác nhau, từ phát triển phần mềm đến lập trình hệ thống. Cuốn sách của Walter Savitch cung cấp cái nhìn sâu sắc về cách mà C++ có thể được áp dụng trong thực tế.

4.1. Phát Triển Phần Mềm

Nhiều ứng dụng phần mềm hiện đại được phát triển bằng C++ nhờ vào hiệu suất và khả năng kiểm soát tài nguyên. Cuốn sách giúp người học hiểu rõ hơn về quy trình phát triển phần mềm.

4.2. Lập Trình Hệ Thống

C++ cũng được sử dụng trong lập trình hệ thống, nơi mà hiệu suất và khả năng tương tác với phần cứng là rất quan trọng. Cuốn sách cung cấp các ví dụ cụ thể để minh họa cho điều này.

V. Kết Luận Về Tương Lai Của C

Với sự phát triển không ngừng của công nghệ, C++ vẫn giữ được vị thế quan trọng trong lĩnh vực lập trình. Cuốn sách của Walter Savitch không chỉ giúp người học nắm vững kiến thức mà còn chuẩn bị cho họ những kỹ năng cần thiết để thành công trong tương lai.

5.1. Tương Lai Của Ngôn Ngữ C

Ngôn ngữ C++ tiếp tục phát triển với các phiên bản mới, mang đến nhiều tính năng và cải tiến. Điều này giúp nó duy trì sự hấp dẫn đối với lập trình viên.

5.2. Cơ Hội Nghề Nghiệp Trong Lĩnh Vực C

Với nhu cầu ngày càng tăng về lập trình viên C++, cơ hội nghề nghiệp trong lĩnh vực này rất phong phú. Cuốn sách giúp người học chuẩn bị tốt cho sự nghiệp trong tương lai.

16/07/2025

Trích đoạn nội dung tài liệu

Ninth Edition Problem Solving with C++ This page intentionally left blank Ninth Edition Problem Solving with C++ Walter Savitch University of California, San Diego Contributor Kenrick Mock University of Alaska, Anchorage Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City São Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo Editorial Director: Marcia Horton Acquisitions Editor: Matt Goldstein Program Manager: Kayla Smith-Tarbox Editorial Assistant: Kelsey Loanes Marketing Coordinator: Kathryn Ferranti Production Director: Erin Gregg Managing Editor: Scott Disanno Senior Operations Supervisor: Vincent Scelta Operations Specialist: Linda Sager Cover Designer: Joyce Wells Permissions Manager: Timothy Nicholls Image Permissions Manager: Karen Sanatar Media Producer: Renata Butera Media Project Manager: Wanda Rockwell Full-Service Vendor: Hardik Popli, Cenveo® Publisher Services Composition: Cenveo Publisher Services Printer/Binder: Courier/Westford Cover Printer: Lehigh-Phoenix Color/Hagerstown Credits and acknowledgments borrowed from other sources and reproduced, with permission, in this textbook appear on appropriate page within text. Microsoft® and Windows® are registered trademarks of the Microsoft Corporation in the U. and other coun- tries. Screen shots and icons reprinted with permission from the Microsoft Corporation.

This book is not spon- sored or endorsed by or affiliated with the Microsoft Corporation. Copyright © 2015, 2012, 2009, 2007, 2005, 2003 Pearson Education, Inc. All rights reserved. Manufactured in the United States of America.

This publication is protected by Copyright, and permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission(s) to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, 501 Boylston Street, Suite 900, Boston, Massachusetts 02116. Many of the designations by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed in initial caps or all caps.

    Library of Congress Cataloging-in-Publication Data Savitch, Walter J., 1943- Problem solving with C++ / Walter Savitch ; contributor, Kenrick Mock. pages cm Includes index.13'3--dc23 2013048487 10 9 8 7 6 5 4 3 2 1—CW—15 14 13 12 11 ISBN 10: 0-13-359174-3 www.com ISBN 13: 978-0-13-359174-3 Preface This book is meant to be used in a first course in programming and computer science using the C++ language. It assumes no previous programming experi- ence and no mathematics beyond high school algebra. If you have used the previous edition of this book, you should read the following section that explains the changes to this ninth edition and then you can skip the rest of this preface.

If you are new to this book, the rest of this preface will give you an overview of the book. Changes to the Ninth Edition This ninth edition presents the same programming philosophy as the eighth edition. All of the material from the eighth edition remains, but with the fol- lowing enhancements: ■ End-of-chapter programs are now split into Practice Programs and Program- ming Projects. Practice Programs require a direct application of concepts presented in the chapter and solutions are usually short.

Practice Programs are appropriate for laboratory exercises. Programming Projects require ad- ditional problem solving and solutions are generally longer than Practice Programs. Programming Projects are appropriate for homework problems. ■ Introduction to C++11 in the context of C++98.

Examples of C++11 content includes new integer types, the auto type, raw string literals, strong enumera- tions, nullptr, ranged for loop, conversion between strings and integers, member initializers, and constructor delegation. ■ Additional material on sorting, secure programming (e., overflow, array out of bounds), and inheritance. ■ Correction of errata. ■ Twenty-one new Practice Programs and ten new Programming Projects.

■ Ten new VideoNotes for a total of sixty-four VideoNotes. These VideoNotes walk students through the process of both problem solving and coding to help reinforce key programming concepts. An icon appears in the margin of the book when a VideoNote is available regarding the topic covered in the text. If you are an instructor already using the eighth edition, you can continue to teach your course almost without change.

Flexibility in Topic Ordering This book was written to allow instructors wide latitude in reordering the material. To illustrate this flexibility, we suggest two alternative ways to order v vi Preface the topics. There is no loss of continuity when the book is read in either of these ways. To ensure this continuity when you rearrange material, you may need to move sections rather than entire chapters.

However, only large sec- tions in convenient locations are moved. To help customize a particular order for any class’s needs, the end of this preface contains a dependency chart, and each chapter has a “Prerequisites” section that explains what material needs to be covered before each section in that chapter. Reordering 1: Earlier Classes To effectively design classes, a student needs some basic tools such as control structures and function definitions. This basic material is covered in Chapters 1 through 6.

After completing Chapter 6, students can begin to write their own classes. One possible reordering of chapters that allows for such early coverage of classes is the following: Basics: Chapters 1, 2, 3, 4, 5, and 6. This material covers all control struc- tures, function definitions, and basic file I/O. Chapter 3, which covers ad- ditional control structures, could be deferred if you wish to cover classes as early as possible.

Classes and namespaces: Chapter 10, Sections 11.2 of Chapter 11, and Chapter 12. This material covers defining classes, friends, overloaded operators, and namespaces. Arrays, strings and vectors: Chapters 7 and 8 Pointers and dynamic arrays: Chapter 9 Arrays in classes: Sections 11.4 of Chapter 11 Inheritance: Chapter 15 Recursion: Chapter 14 (Alternately, recursion may be moved to later in the course.) Pointers and linked lists: Chapter 13 Any subset of the following chapters may also be used: Exception handling: Chapter 16 Templates: Chapter 17 Standard Template Library: Chapter 18 Reordering 2: Classes Slightly Later but Still Early This version covers all control structures and the basic material on arrays be- fore doing classes, but classes are covered later than the previous ordering and slightly earlier than the default ordering. Basics: Chapters 1, 2, 3, 4, 5, and 6.

This material covers all control struc- tures, function definitions, and the basic file I/O. Preface vii Arrays and strings: Chapter 7, Sections 8.2 of Chapter 8 Classes and namespaces: Chapter 10, Sections 11.2 of Chapter 11, and Chapter 12. This material covers defining classes, friends, overloaded operators, and namespaces. Pointers and dynamic arrays: Chapter 9 Arrays in classes: Sections 11.4 of Chapter 11 Inheritance: Chapter 15 Recursion: Chapter 14.

(Alternately, recursion may be moved to later in the course.3 Pointers and linked lists: Chapter 13 Any subset of the following chapters may also be used: Exception handling: Chapter 16 Templates: Chapter 17 Standard Template Library: Chapter 18 Accessibility to Students It is not enough for a book to present the right topics in the right order. It is not even enough for it to be clear and correct when read by an instructor or other experienced programmer. The material needs to be presented in a way that is accessible to beginning students. In this introductory textbook, I have endeav- ored to write in a way that students find clear and friendly.

Reports from the many students who have used the earlier editions of this book confirm that this style makes the material clear and often even enjoyable to students. ANSI/ISO C++ Standard This edition is fully compatible with compilers that meet the latest ANSI/ISO C++ standard. At the time of this writing the latest standard is C++11. Advanced Topics Many “advanced topics” are becoming part of a standard CS1 course.

Even if they are not part of a course, it is good to have them available in the text as enrichment material. This book offers a number of advanced topics that can be integrated into a course or left as enrichment topics. It gives thorough cov- erage of C++ templates, inheritance (including virtual functions), exception handling, and the STL (Standard Template Library). Although this book uses libraries and teaches students the importance of libraries, it does not require any nonstandard libraries.

This book uses only libraries that are provided with essentially all C++ implementations. viii Preface Dependency Chart The dependency chart on the next page shows possible orderings of chapters and subsections. A line joining two boxes means that the upper box must be covered before the lower box. Any ordering that is consistent with this partial ordering can be read without loss of continuity.

If a box contains a section number or numbers, then the box refers only to those sections and not to the entire chapter. Summary Boxes Each major point is summarized in a boxed section. These boxed sections are spread throughout each chapter. Self-Test Exercises Each chapter contains numerous Self-Test Exercises at strategic points.

Com- plete answers for all the Self-Test Exercises are given at the end of each chapter. VideoNotes VideoNote VideoNotes are designed for teaching students key programming concepts and techniques. These short step-by-step videos demonstrate how to solve ­problems from design through coding. VideoNotes ­allow for self-paced ­instruction with easy navigation including the ability to select, play, rewind, fast-forward, and stop within each VideoNote exercise.

Online Practice and Assessment with MyProgrammingLab MyProgrammingLab helps students fully grasp the logic, semantics, and syn- tax of programming. Through practice exercises and immediate, personalized feedback, MyProgrammingLab improves the programming competence of be- ginning students who often struggle with the basic concepts and paradigms of popular high-level programming languages. A self-study and homework tool, a MyProgrammingLab course consists of hundreds of small practice problems organized around the structure of this textbook. For students, the system automatically detects errors in the logic and syntax of their code submissions and offers targeted hints that enable students to figure out what went wrong—and why.

For instructors, a comprehensive gradebook tracks correct and incorrect answers and stores the code inputted by students for review. MyProgrammingLab is offered to users of this book in partnership with Turing’s Craft, the makers of the CodeLab interactive programming exer- cise system. For a full demonstration, to see feedback from instructors and students, or to get started using MyProgrammingLab in your course, visit www. Preface ix DISPLAY P.1   Dependency Chart Chapter 1 Chapter 2 Chapter 4 Chapter 5 Introduction C++ Basics Functions 1 Functions 2 Chapter 3 Chapter 6 More Flow I/O Streams of Control Chapter 7 Chapter 14 Chapter 10 Arrays Recursion Classes 1 7.3 Chapter 7 Chapter 11 *Chapter 16 7.4 Multi- Classes 2 Exception Dimensional 11.2 Handling Arrays Chapter 12 Chapter 8 Chapter 11 Separate Strings and 11.3 Classes & ­Compilation Vectors Arrays & Namespaces Chapter 9 Chapter 11 Chapter 13 Pointers and 11.4 Classes & Pointers and Dynamic Dynamic Linked Lists Arrays Arrays Chapter 15 Inheritance Chapter 17 Templates *Chapter 16 contains occasional references to derived classes, Chapter 18 but those references STL can be omitted x Preface Support Material There is support material available to all users of this book and additional material available only to qualified instructors.

Materials Available to All Users of this Book ■ Source Code from the book ■ PowerPoint slides ■ VideoNotes To access these materials, go to: www.com/savitch Resources Available to Qualified Instructors Only Visit Pearson Education’s instructor resource center at www.

Nội dung được bảo vệ bản quyền — Tải xuống đầy đủ