
Sams Teach Yourself C++ in One Hour a Day, 9th edition
BRAND: PEARSON
eBook edition. 1 Year Subscription. Dành cho Cá nhân | Trường ĐH, Nhóm, Thư Viện: Gọi 0915920514 để báo giá Pearson, Vital Source eBook hoặc mua Sách In
Tổng quan sách
Phiên bản thứ chín của Sams Tự học C++ trong một giờ mỗi ngàyBắt đầu với một giờ mỗi ngày, bạn có thể đạt được tất cả các kỹ năng cần thiết để bắt đầu lập trình bằng C++. Hướng dẫn đầy đủ này sẽ giúp bạn nhanh chóng nắm vững các khái niệm cơ bản về lập trình hướng đối tượng và dạy cho bạn các tính năng và khái niệm nâng cao của ngôn ngữ C++. Được cập nhật đầy đủ theo tiêu chuẩn C++20, cuốn sách thực tế này được thiết kế để giúp bạn viết mã C++ nhanh hơn, đơn giản hơn và đáng tin cậy hơn.* Nắm vững các nguyên tắc cơ bản của C++ và lập trình hướng đối tượng* Sử dụng Thư viện mẫu tiêu chuẩn (STL) để nhanh chóng phát triển các ứng dụng trong thế giới thực mạnh mẽ và đáng tin cậy hơn* Tìm hiểu các tính năng hiện đại của C++ 20 như khái niệm, phạm vi, dạng xem, bộ điều hợp và mô-đun* Áp dụng những Điều Nên và Không nên làm đã được chứng minh để tận dụng những phương pháp hay nhất và tránh những cạm bẫy ngay từ ngày đầu tiên* Kiểm tra kiến thức và chuyên môn của bạn bằng các bài tập tập trung sau mỗi bài học* Học cách sử dụng gần 300 mẫu mã biên dịch có sẵn để tải xuống miễn phí và đã được giải thích chi tiết trong sáchHọc theo thời gian riêng của bạn, theo tốc độ của riêng bạn* Không cần kinh nghiệm lập trình: bắt đầu viết các chương trình C++ hiệu quả, được tổ chức tốt một cách nhanh chóng!* Nắm vững các khái niệm hướng đối tượng như lớp, kế thừa, đa hình, đóng gói và trừu tượng hóa* Tạo các chương trình đáng tin cậy, giàu tính năng với các lớp, vùng chứa và thuật toán STL* Đơn giản hóa mã của bạn bằng cách sử dụng tính năng khấu trừ kiểu tự động và các tính năng khác* Lập trình các đối tượng hàm với biểu thức Lambda C++ hiện đại* Tăng tốc quá trình học tập bằng cách sử dụng gần 300 mẫu mã được giải thích bên trong* Tận dụng tối đa các khái niệm, phạm vi, chế độ xem, bộ điều hợp và mô-đun C++20 mới* Xem trước các cải tiến dự kiến có trong C++23
Introduction xxviPART I: The BasicsLesson 1:Getting StartedA Brief History of C++ Connection to C Advantages of C++ Evolution of the C++ Standard Who Uses Programs Written in C++?Programming a C++ Application Steps in Building an Executable Analyzing Errors and Debugging Integrated Development Environments Programming Your First C++ Application Building and Executing Your First C++ Application Understanding Compiler ErrorsWhat’s New in C++20?SummaryQ&AWorkshop Quiz ExercisesLesson 2:The Anatomy of a C++ ProgramParts of the Hello World ProgramPreprocessor Directive #includeThe Body of Your Program: main() Returning a ValueThe Concept of NamespacesComments in C++ CodeFunctions in C++Basic Input Using std::cin and Output Using std::coutSummaryQ&AWorkshop Quiz ExercisesLesson 3:Using Variables, Declaring ConstantsWhat Is a Variable? Memory and Addressing in Brief Declaring Variables to Access and Use Memory Declaring and Initializing Multiple Variables of a Type Understanding the Scope of a Variable Global Variables Naming ConventionsCommon Compiler-Supported C++ Variable Types Using Type bool to Store Boolean Values Using Type char to Store Character Values The Concept of Signed and Unsigned Integers Signed Integer Types short, int, long, and long long Unsigned Integer Types unsigned short, unsigned int, unsigned long, and unsigned long long Avoiding Overflow Errors by Selecting Correct Data Types Floating-Point Types float and doubleDetermining the Size of a Variable by Using sizeof() Avoid Narrowing Conversion Errors by Using List InitializationAutomatic Type Inference Using autoUsing typedef to Substitute a Variable’s TypeWhat Is a Constant? Literal Constants Declaring Variables as Constants Using const Constant Expressions Using constexpr C++20 Immediate Functions Using consteval Enumerations Scoped Enumerations Defining Constants by Using #defineKeywords You Cannot Use as Variable or Constant NamesSummaryQ&AWorkshop Quiz ExercisesLesson 4:Managing Arrays and StringsWhat Is an Array? The Need for Arrays Declaring and Initializing Static Arrays How Data Is Stored in an Array Accessing Data Stored in an Array Modifying Data Stored in an ArrayMultidimensional Arrays Declaring and Initializing Multidimensional Arrays Accessing Elements in a Multidimensional ArrayDynamic ArraysC-Style Character StringsC++ Strings: Using std::stringSummaryQ&AWorkshop Quiz ExercisesLesson 5:Working with Expressions, Statements, and OperatorsStatementsCompound Statements, or BlocksUsing Operators The Assignment Operator (=) Understanding l-Values and r-Values Operators to Add (+), Subtract (-), Multiply (*), Divide (/), and Modulo Divide (%) Operators to Increment (++) and Decrement (--) To Postfix or to Prefix? Equality Operators (== and !=) Relational Operators C++20 Three-Way Comparison Operator (<=>) Logical Operations NOT, AND, OR, and XOR Using C++ Logical Operators NOT (!), AND (&&), and OR (||) Bitwise NOT (~), AND (&), OR (|), and XOR (^) Operators Bitwise Right Shift (>>) and Left Shift (<<) Operators Compound Assignment Operators Using the sizeof() Operator to Determine the Memory Occupied by a Variable Operator Precedence and AssociativitySummaryQ&AWorkshop Quiz ExercisesLesson 6:Controlling Program FlowConditional Execution Using if.else Conditional Programming Using if.else Conditional Execution of Statements Within a Block Nested if Statements Conditional Processing Using switch-case Conditional Execution Using the ?: OperatorGetting Code to Execute in Loops A Rudimentary Loop Using goto The while Loop The do.while Loop The for Loop The Range-Based for LoopModifying Loop Behavior Using continue and break Loops That Don’t End: Infinite Loops Controlling Infinite LoopsProgramming Nested Loops Using Nested Loops to Walk a Multidimensional Array Using Nested Loops to Calculate Fibonacci NumbersSummaryQ&AWorkshop Quiz ExercisesLesson 7:Organizing Code with FunctionsThe Need for Functions What Is a Function Prototype? What Is a Function Definition? What Is a Function Call, and What Are Arguments? Programming a Function with Multiple Parameters Programming Functions with No Parameters or No Return Values Function Parameters with Default Values Recursion: Functions That Invoke Themselves Functions with Multiple Return Statements Using Functions to Work with Different Forms of Data Overloading Functions Passing an Array of Values to a Function Passing Arguments by ReferenceHow Function Calls Are Handled by the Microprocessor Inline Functions Automatic Return Type Deduction Lambda FunctionsSummaryQ&AWorkshop Quiz ExercisesLesson 8:Pointers and References ExplainedWhat Is a Pointer? Declaring a Pointer Determining the Address of a Variable by Using the Reference Operator (&) Using Pointers to Store Addresses Accessing Pointed Data Using the Dereference Operator (*) What Is the Size of a Pointer?Dynamic Memory Allocation Using the Operators new and delete to Allocate and Release Memory Dynamically Effects of the Increment (++) and Decrement (--) Operators on Pointers Using the const Keyword on Pointers Passing Pointers to Functions Similarities Between Arrays and PointersCommon Programming Mistakes When Using Pointers Memory Leaks Pointers Pointing to Invalid Memory Locations Dangling Pointers (Also Called Stray or Wild Pointers) Checking Whether an Allocation Request Using new SucceededPointer Programming Best Practices What Is a Reference? What Makes References Useful? Using the Keyword const on References Passing Arguments by Reference to FunctionsSummaryQ&AWorkshop Quiz ExercisesPART II: Fundamentals of Object-Oriented C++ ProgrammingLesson 9:Classes and ObjectsThe Concept of Classes and Objects Declaring a Class An Object as an Instance of a Class Accessing Members by Using the Dot Operator (.) Accessing Members by Using the Pointer Operator (->)The Keywords public and private Abstraction of Data via the Keyword private Constructors Declaring and Implementing a Constructor When and How to Use Constructors Overloading Constructors A Class Without a Default Constructor Constructor Parameters with Default Values Constructors with Initialization ListsDestructor Declaring and Implementing a Destructor When and How to Use a DestructorThe Copy Constructor Shallow Copying and Associated Problems Ensuring a Deep Copy Using a Copy Constructor Using Move Constructors to Improve PerformanceDifferent Uses of Constructors and the Destructor A Class That Does Not Permit Copying A Singleton Class That Permits a Single Instance A Class That Prohibits Instantiation on the Stack Using Constructors to Convert TypesThe this PointerUsing sizeof() with a ClassThe Keyword struct and Its Differences from class Declaring a friend of a classUnion: A Special Data Storage Mechanism Declaring a Union Where Would You Use a Union?Using Aggregate Initialization on Classes and structs constexpr with Classes and ObjectsSummaryQ&AWorkshop Quiz ExercisesLesson 10:Implementing InheritanceBasics of Inheritance Inheritance and Derivation C++ Syntax of Derivation The Access Specifier Keyword protected Base Class Initialization: Passing Parameters to the Base Class A Derived Class Overriding the Base Class’s Methods Invoking Overridden Methods of a Base Class Invoking Methods of a Base Class in a Derived Class A Derived Class Hiding the Base Class’s Methods Order of Construction Order of Destruction Private InheritanceProtected InheritanceThe Problem of SlicingMultiple InheritanceAvoiding Inheritance Using finalSummaryQ&AWorkshop Quiz ExercisesLesson 11:PolymorphismBasics of Polymorphism Need for Polymorphic Behavior Polymorphic Behavior Implemented Using Virtual Functions Need for Virtual Destructors How Do Virtual Functions Work? Understanding the Virtual Function Table Abstract Base Classes and Pure Virtual FunctionsUsing Virtual Inheritance to Solve the Diamond ProblemUsing the Specifier override to Indicate the Intention to OverrideUsing final to Prevent Function Overriding Virtual Copy Constructors?SummaryQ&AWorkshop Quiz ExercisesLesson 12:Operator Types and Operator OverloadingWhat Are Operators in C++?Unary Operators Unary Increment (++) and Decrement (--) Operators Conversion Operators The Dereference Operator (*) and Member Selection Operator (->)Binary Operators The Binary Addition (a+b) and Subtraction (a-b) Operators The Addition Assignment (+=) and Subtraction Assignment (-=) Operators The Equality (==) and Inequality (!=) Operators The <, >, <=, and >= Operators The C++20 Three-Way Comparison Operator (<=>) The Copy Assignment Operator (=) The Subscript Operator ([]) The Function Operator (())The Move Constructor and Move Assignment Operator for High-Performance Programming The Problem of Unwanted Copy Steps Declaring a Move Constructor and Move Assignment Operator User-Defined LiteralsOperators That Cannot Be OverloadedSummaryQ&AWorkshop Quiz ExercisesLesson 13:Casting OperatorsThe Need for Casting Why C-Style Casts Are Not Popular with Some C++ Programmers The C++ Casting Operators Using static_cast Using dynamic_cast and Runtime Type Identification Using reinterpret_cast Using const_castProblems with the C++ Casting OperatorsSummaryQ&AWorkshop Quiz ExercisesLesson 14:An Introduction to Macros and TemplatesThe Preprocessor and the CompilerUsing the Macro #define to Define Constants Using Macros for Protection Against Multiple InclusionUsing #define to Write Macro Functions Why All the Parentheses? Using the assert Macro to Validate Expressions Advantages and Disadvantages of Using Macro Functions An Introduction to Templates Template Declaration Syntax The Different Types of Template Declarations Template Functions Templates and Type Safety Template Classes Declaring Templates with Multiple Parameters Declaring Templates with Default Parameters Sample Template Class: HoldsPair Template Instantiation and Specialization Template Classes and static Members Variable Templates Using static_assert to Perform Compile-Time Checks Using Templates in Practical C++ ProgrammingSummaryQ&AWorkshop Quiz ExercisesPART III: Learning the Standard Template Library (STL)Lesson 15:An Introduction to the Standard Template LibrarySTL Containers Sequential Containers Associative Containers Container AdaptersSTL Iterators STL AlgorithmsInteraction Between Containers and Algorithms Using Iterators Using the Keyword auto to Let a Compiler Define TypeChoosing the Right Container STL String ClassesSummaryQ&AWorkshop Quiz Lesson 16:The STL String ClassThe Need for String Manipulation Classes Working with the STL string Class Instantiating the STL string Class and Making Copies Accessing Character Contents of std::string Concatenating One String to Another Finding a Character or Substring in a String Truncating an STL String String Reversal String Case ConversionTemplate-Based Implementation of an STL Stringoperator ""s in std::stringUsing std::string_view (Amended in C++20)SummaryQ&AWorkshop Quiz ExercisesLesson 17:STL Dynamic Array ClassesThe Characteristics of std::vector Typical Vector Operations Instantiating a Vector Inserting Elements at the End of a Vector by Using push_back() List Initialization Inserting Elements at a Given Position by Using insert() Accessing Elements in a Vector by Using Array Semantics Accessing Elements in a Vector by Using Pointer Semantics Removing Elements from a VectorUnderstanding the Concepts of Size and CapacityThe STL deque ClassSummaryQ&AWorkshop Quiz ExercisesLesson 18:STL list and forward_listThe Characteristics of std::listBasic list Operations Instantiating a std::list Object Inserting Elements at the Front or Back of a List Inserting Elements in the Middle of a List Erasing Elements from a ListReversing and Sorting Elements in a List Reversing Elements by Using list::reverse() Sorting Elements Sorting and Removing Elements from a List That Contains Instances of a Class std::forward_listSummaryQ&AWorkshop Quiz ExercisesLesson 19:STL set and multisetAn Introduction to STL Set Classes Basic STL set and multiset Operations Instantiating a std::set Object Inserting Elements in a Set or Multiset Finding Elements in an STL set or multiset Container Erasing Elements in an STL set or multiset ContainerPros and Cons of Using STL set and multisetSTL Hash Set Implementation: std::unordered_set and std::unordered_multisetSummaryQ&AWorkshop Quiz ExercisesLesson 20:STL map and multimapAn Introduction to STL Map ClassesBasic std::map and std::multimap Operations Instantiating std::map or std::multimap Inserting Elements in an STL Map or Multimap Finding Elements in an STL map Container Finding Elements in an STL multimap Container Erasing Elements from an STL map or multimap ContainerSupplying a Custom Sort PredicateSTL’s Hash Table–Based Key/Value Container How Hash Tables Work Using unordered_map and unordered_multimapSummaryQ&AWorkshop Quiz ExercisesPART IV: Lambda Expressions and STL AlgorithmsLesson 21:Understanding Function ObjectsFunction Objects and Predicates Typical Applications of Function Objects Unary Functions Unary Predicates Binary Functions Binary PredicatesSummaryQ&AWorkshop Quiz ExercisesLesson 22:Lambda ExpressionsWhat Is a Lambda Expression?How to Define a Lambda Expression Capturing Variables Parameters Return TypesA Lambda Expression for a Unary FunctionA Lambda Expression for a Unary PredicateA Lambda Expression with State via Capture Lists ([.])A Lambda Expression for a Binary FunctionA Lambda Expression for a Binary PredicateSummaryQ&AWorkshop Quiz ExercisesLesson 23:STL AlgorithmsWhat Are STL Algorithms?Classification of STL Algorithms Non-mutating Algorithms Mutating AlgorithmsUsage of STL Algorithms Finding Elements, Given a Value or a Condition Counting Elements Given a Value or a Condition Searching for an Element or a Range in a Collection Initializing Elements in a Container to a Specific Value Using std::generate() to Initialize Elements to a Value Generated at Runtime Processing Elements in a Range by Using for_each() Performing Transformations on a Range by Using std::transform() Copy and Remove Operations Replacing Values and Replacing Elements Given a Condition Sorting and Searching in a Sorted Collection and Erasing Duplicates Partitioning a Range Inserting Elements in a Sorted Collection Performing Fold Operations Using std::accumulate() in C++20C++20 Constrained Algorithms SummaryQ&AWorkshop Quiz ExercisesLesson 24:Adaptive Containers: Stack and QueueThe Behavioral Characteristics of Stacks and Queues Stacks QueuesUsing the STL stack Class Instantiating a Stack Stack Member Functions Insertion and Removal at the Top, Using push() and pop()Using the STL queue Class Instantiating a Queue Member Functions of the queue Class Insertion at the End and Removal at the Beginning of a Queue via push() and pop()Using the STL Priority Queue Instantiating the priority_queue Class Member Functions of priority_queue Insertion at the End and Removal at the Beginning of a Priority Queue via push() and pop()SummaryQ&AWorkshop Quiz ExercisesLesson 25:Working with Bit Flags Using the STLThe bitset Class Instantiating std::bitsetUsing std::bitset and Its Members Useful Operators in std::bitset std::bitset Member Methods The vector<bool> Class Instantiating vector<bool> vector<bool> Functions and OperatorsSummaryQ&AWorkshop Quiz ExercisesPART V: Advanced C++ ConceptsLesson 26:Understanding Smart PointersWhat Are Smart Pointers? The Problem with Using Conventional (Raw) Pointers How Do Smart Pointers Help? How Are Smart Pointers Implemented?Types of Smart Pointers Deep Copy Copy on Write Reference-Counted Smart Pointers Reference-Linked Smart Pointers Destructive Copy Using std::unique_ptrPopular Smart Pointer LibrariesSummaryQ&AWorkshop Quiz ExercisesLesson 27:Using Streams for Input and OutputThe Concept of StreamsImportant C++ Stream Classes and ObjectsUsing std::cout for Writing Formatted Data to the Console Changing the Display Number Format by Using std::cout Aligning Text and Setting Field Width by Using std::coutUsing std::cin for Input Using std::cin for Input into a Plain Old Data Type Using std::cin::get for Input into the char* Buffer Using std::cin for Input into std::stringUsing std::fstream for File Handling Opening and Closing a File Using open() and close() Creating and Writing a Text File by Using open() and the Operator << Reading a Text File by Using open() and the Operator >> Writing to and Reading from a Binary File Using std::stringstream for String ConversionsSummaryQ&AWorkshop Quiz ExercisesLesson 28:Exception HandlingWhat Is an Exception?What Causes Exceptions?Implementing Exception Safety via try and catch Using catch(.) to Handle All Exceptions Catching Exceptions of a Type Throwing Exceptions of a Type by Using throw How Exception Handling WorksClass std::exception A Custom Exception Class Derived from std::exceptionSummaryQ&AWorkshop Quiz ExercisesLesson 29:C++20 Concepts, Ranges, Views, and AdaptorsConcepts Using Concepts Provided by the Standard Library Defining Custom Concepts by Using the Keyword requires Using Concepts with Classes and ObjectsThe Ranges Library, Views, and Adaptors Views and Adaptors Adaptors Provided by the Ranges Library Combining Multiple AdaptorsSummaryQ&AWorkshop Quiz ExercisesLesson 30:C++20 ThreadsMultithreading What Is a Thread? Why Program Multithreaded Applications? Using the C++20 Thread Library How Can Threads Transact Data? Using Mutexes and Semaphores to Synchronize ThreadsSummaryQ&AWorkshop ExerciseLesson 31:C++20 Modules and C++23Modules The Problem with #include<header> C++20 Modules Programming a Module Consuming a Module Why import Module; Is Superior to the Preprocessor #include<header> C++23 Expected FeaturesLearning C++ Doesn’t Stop Here! Online Documentation Communities for Guidance and HelpSummaryQ&AWorkshop ExercisePART VI: AppendixesAppendix A:Working with Numbers: Binary and HexadecimalAppendix B:C++ KeywordsAppendix C:Writing Great C++ CodeAppendix D:ASCII CodesAppendix E:Answers9780137334681 TOC 12/20/2021