ENGLISH

Jumping into C++

Book information

Publisher
Cprogramming.com
Year
2013
ISBN
0988927802, 9780988927803
Language
english
Format
PDF
Filesize
6 MB (5951579 bytes)
Pages
536\381
Time added
2022-05-23 20:43:20

Description

Want to learn to code? Want to learn C++? Struggling to follow your lecturer or books and tutorials written for experts? You're not alone. As a professional C++ developer and former Harvard teaching fellow, I know what you need to know to be a great C++ programmer, and I know how to teach it, one step at a time. I know where people struggle, and why, and how to make it clear. I cover every step of the programming process, including: Getting the tools you need to program and how to use them *Basic language feature like variables, loops and functions *How to go from an idea to code *A clear, understandable explanation of pointers *Strings, file IO, arrays, references *Classes and advanced class design *C++-specific programming patterns *Object oriented programming *Data structures and the standard template library (STL) Key concepts are reinforced with quizzes and over 75 practice problems. Part 1: Jumping into C++ Chapter 1: Introduction and Developer Environment Setup What is a programming language? I've heard of a language called C, what’s the difference between C and C++? Do I need to know C to learn C++? Do I need to know math to be a programmer? Terminology Programming Executable Editing and compiling source files A note about sample source code Windows Step 1: Download Code::Blocks Step 2: Install Code::Blocks Step 3: Running Code::Blocks Troubleshooting Environment Setup Compiler Errors What exactly is Code::Blocks? Macintosh XCode Installing XCode 3 Running XCode Creating your first C++ program in XCode Installing XCode 4 Running XCode Creating your first C++ program in XCode Troubleshooting Linux Step 1: Installing g++ Step 2: Running g++ Step 3: Running your program Troubleshooting Step 4: Setting up a text editor Configuring Nano Using Nano Editing text Saving files Opening files Looking at a source file Learning more Chapter 2: The Basics of C++ Intro to the C++ language The simplest C++ program What happens if you don't see your program? The basic structure of a C++ program Commenting your programs Thinking like a programmer and creating reusable code A few words on the joys and pain of practice Quiz yourself Practice problems Chapter 3: User Interaction and Saving Information with Variables Declaring variables in C++ Using variables What if your program exits immediately? Changing, using and comparing variables Shorthand for adding and subtracting one The use and misuse of variables Common errors when declaring variables in C++ Case sensitivity Naming variables Storing strings Okay, I get strings—but why all those other types? The dirty little secret of floating point numbers The dirty little secret of integers Quiz yourself Practice problems Chapter 4: If Statements Basic syntax for if Expressions What is truth? The bool type Else statements Else-if String comparisons More interesting conditions using Boolean operators Boolean and Short circuiting checks Boolean or Combining expressions Order of evaluation Example Boolean expressions Quiz yourself Practice problems Chapter 5: Loops While loops A common mistake For loops Variable initialization Loop condition Variable update Do-while loops Controlling the flow of loops Nested loops Choosing the right kind of loop For loop While loops Do-while loops Quiz yourself Practice problems Chapter 6: Functions Function syntax Local variables and global variables Local variables Global variables A warning about global variables Making functions available for use Function definitions and declarations An example of using a function prototype Breaking down a program into functions When you’re repeating code again and again When you want to make code easier to read Naming and overloading functions Summary of functions Quiz yourself Practice problems Chapter 7: What If You Can’t Figure Out What to Do? All we need to do is check if the number has no remainder when divided by the divisor: A brief aside about efficiency and security What if you don’t know the algorithm? Practice Problems Chapter 8: Switch Case and Enums Comparison of switch case with if-else Creating simple types using enumerations Quiz yourself Practice problems Chapter 9: Randomizing Your Programs Getting random numbers in C++ Bugs and randomness Quiz yourself Practice problems Part 2: Working with Data Chapter 10: Arrays Some basic array syntax Example uses for arrays Using arrays to store orderings Representing grids with multi-dimensional array Using arrays Arrays and for loops Passing arrays to functions Writing off the end of an array Sorting arrays Quiz yourself Practice problems Chapter 11: Structures Associating multiple values together Syntax Passing structures around Quiz yourself Practice problems Chapter 12: Introduction to Pointers Forget everything you’ve ever heard Ok, then—what are pointers? Why should you care? What is memory? Variables vs. addresses A note about terms Memory layout Invalid pointers Memory and arrays Other advantages (and disadvantages) of pointers Quiz yourself Practice problems Chapter 13: Using Pointers Pointer syntax Declaring a pointer Pointing to something: getting the address of a variable Using a pointer Uninitialized pointers and NULL Pointers and functions References References vs. pointers Quiz yourself Practice problems Chapter 14: Dynamic Memory Allocation Getting more memory with new Running out of memory References and dynamic allocation Pointers and arrays Multidimensional arrays Pointer arithmetic Understanding two dimensional arrays Pointers to pointers Pointers to pointers and two dimensional arrays Taking stock of pointers Chapter 15: Introduction to Data Structures with Linked Lists Pointers and structures Creating a linked list First time through Second time through Traversing a linked list Taking stock of linked lists Arrays vs linked lists How much space is required for a linked list? Other considerations General rules of thumb Quiz yourself Practice problems Chapter 16: Recursion How to think about recursion Recursion and data structures Loops and recursion The stack The power of the stack Downsides of recursion Debugging stack overflows Performance Taking stock of recursion Quiz yourself Practice problems Chapter 17: Binary Trees Talking about trees Implementing binary trees Inserting into the tree Searching the tree Destroying the tree Removing from a tree Real world use of binary trees Cost of building trees and maps Quiz yourself Practice problems Chapter 18: The Standard Template Library Vectors, a resizable array Calling methods on vectors Other features of vectors Maps Iterators Checking if a value is in a map Taking stock of the STL Learning more about the STL Quiz yourself Practice problems Chapter 19: More about Strings Reading in strings String length and accessing individual elements Searching and substrings Passing by reference Const propagation Const and the STL Quiz yourself Practice problems Chapter 20: Debugging with Code::Blocks Starting out Breaking in Debugging crashes Breaking into a hung program Modifying variables Summary Practice problems Problem 1: Issues with exponents Problem 2: Trouble adding numbers Problem 3: Bugs with Fibonacci56F Problem 4: Misreading and misreplaying a list Part 3: Writing Larger Programs Chapter 21: Breaking Programs Up Into Smaller Pieces Understanding the C++ build process Preprocessing Compilation Linking Why separate compiling and linking? How to split your program across multiple files Step 1: Splitting our declarations and definitions Step 2: Figure out which functions need to be shared Step 3: Move shared functions into their new files Going through an example orig.cpp orig.cpp linkedlist.h linkedlist.cpp orig.cpp newheader.h orig.cpp Other dos and don'ts of header files Handling multiple source files in your development environment Code::Blocks g++ XCode Quiz yourself Practice problems Chapter 22: Introduction to Program Design Redundant code Assumptions about how data is stored Design and comments Quiz yourself Chapter 23: Hiding the Representation of Structured Data Using functions to hide the layout of a structure Method declaration and call syntax Moving function definitions out of the structure Quiz yourself Practice problems Chapter 24: The Class Hiding how data is stored Declaring an instance of a class The responsibilities of a class What does private really mean? Summary Quiz yourself Practice problems Chapter 25: The Lifecycle of a Class Object construction What happens if you don't create a constructor? Initializing members of the class Using the initialization list for const fields Object destruction Destruction on delete Destruction when going out of scope Destruction due to another destructor Copying classes The assignment operator The copy constructor The full list of compiler generated methods Preventing copying entirely Quiz yourself Practice problems Chapter 26: Inheritance and Polymorphism Inheritance in C++ Other uses and misuses of inheritance Inheritance, object construction and object destruction Polymorphism and object destruction The slicing problem Sharing code with subclasses Protected data Class-wide data How is polymorphism implemented? Quiz yourself Practice problems Chapter 27: Namespaces When to write "using namespace" When should you create a namespace? Quiz yourself Practice problems Chapter 28: File I/O File I/O basics Reading from files File formats End of file Writing files Creating new files File position Accepting command line arguments Dealing with numeric command line arguments Binary file I/O Working with binary files Converting to char* An example of binary I/O Storing classes in a file Reading from a file Quiz yourself Practice problems Chapter 29: Templates in C++ Template functions Type inference Duck typing Template classes Tips for working with templates Templates and header files Summarizing templates Diagnosing template error messages Quiz yourself Practice problems Part 4: Miscellaneous Topics Chapter 30: Formatting Output Using Iomanip Dealing with spacing issues Setting the field width with setw Changing the padding character Permanently changing settings Putting your knowledge of iomanip together Printing numbers Setting the precision of numerical output with setprecision What do you do about money? Output in different bases Chapter 31: Exceptions and Error Reporting Releasing resources during exceptions Manual cleanup of resources in a catch block Throwing exceptions Throw specifications Benefits of exceptions Misuse of exceptions Exceptions in summary Chapter 32: Final Thoughts Chapter 2 quiz solution Chapter 3 quiz solution Chapter 4 quiz solution Chapter 5 quiz solution Chapter 6 quiz solution Chapter 8 quiz solution Chapter 9 quiz solution Chapter 10 quiz solution Chapter 11 quiz solution Chapter 12 quiz solution Chapter 13 quiz solution Chapter 14 quiz solution Chapter 15 quiz solution Chapter 16 quiz solution Chapter 17 quiz solution Chapter 18 quiz solution Chapter 19 quiz solution Chapter 21 quiz solution Chapter 22 quiz solution Chapter 23 quiz solution Chapter 24 quiz solution Chapter 25 quiz solution Chapter 26 quiz solution Chapter 27 quiz solution Chapter 28 quiz solution Chapter 29 quiz solution

Similar books