Gee, it is a lot of work to transfer my book notes from paper page to digital internet, but it does help me to understand and recall everything better. I won’t be summarizing everything as I had with the Python book(before I returned it to the MSU library at the end of spring, anyway), and everything is much more chaotic. Terms and ideas are listed in a long list below; some are defined/otherwise elucidated, and others are not.
“The ability to ignore details is characteristic of maturing technologies.”
“Much of the C++ language—especially the harder parts—exists mostly for the benefit of library authors. Library users don’t need to know those parts of the language at all.”
{ or }, indicate scope and are used for functions and various statements. Objects defined inside braces are limited in scope to the function or statement defined with the braces… At the terminating brace, the object is destroyed and lost forever. Obviously, it is possible to define objects that are global in scope…std::ostreamstd::cout operand.:::: scope operator, and the function or type name… For example: std::vector.<string>std::endl is called.+ symbol, which can be used for addition arithmetic or for concatenating strings together.constconst is used when initiating a variable/object and declares that a variable cannot be modified… It will remain constant. Example: const int xyz = 5; // this will always equal 5while() statementwhile ( condition ) { ... } It works as in any other language…while ( rows < 10 ) { ... rows += 1; } …then the loop invariant would be the property: I have looped through rows rows of data so far… Pretty straightforward, but determining it and commenting it out makes program that much easier to understand and write. The final task of any loop must be to modify objects to make the loop invariant true for the subsequent iteration.std::string::size_typesize_type data type dynamically changes to allocate enough memory for the job. Less work for the library user, me.using x::yusing x::y declaration. For the rest of the scope that the declaration is made within, you can call the name by just calling y.!= inequality operator instead of greater-than or less-than operators to terminate the loop, which consequently tells us the explicit value of the sentry variable at the end of a loop(infinite quantity of values may be greater or less than, but only one explicit value is not equal to…)setprecision(x)setprecision(x) is an ostream manipulator that sets the amount of significant digits to display for a floating-point number in an ostream output stream.float and double is negligible. And according to the author, on some implementations double is even faster? A double typically saves fifteen significant digits to the float’s six.istream Type as a Conditionistream as a condition in a while() statement. Example: while(cin >> x) { ... } This is because the istream class provides a conversion for the type to true or false… Any class type or method that likewise provides a true or false conversion may be used as the condition in a statement.vector Type“A
vectorholds a sequence of values of a given type, grows as needed to accomodate additional values, and lets us get at each individual value efficiently.”
“All the values in an individual vector are the same type, but different vectors can hold objects of different types.”
For chapter exercise, on utility of this vector abstraction: “…even though ourhomeworkvector will grow as needed to accomodate grades for as many homework assignments as our students can tolerate, our program doesn’t need to worry about obtaining the memory to store all those grades. The standard library does all that work for us.”
vector<double>::size_type Typetypedeftypedef is used to create synonyms for a specific data type. Example: typedef vector<double>::size_type vec_sz; Following this declaration, I can use vec_sz to refer to the type of `vector%, returns the remainder of a division operation. For example, randomInteger % 2 will return zero if the integer is divisible by 2 — aka an even number.int myAge = ( myName == "Patrick" ) ? 20 : 65; If myName is Patrick, then myAge will be declared to be 20, else if myName is not Patrick, it will be declared to be 65…vectorName.begin()vectorName.end()vectorName.push_back(newData)newData to the end of a vector container.vectorName[i]i location in vector container.vectorName.size()sort(begin, end, [comparison] )<algorithm> and rearranges a container ascendingly(lowest to highest). If you supply a comparison which returns one of two values supplied from a container, you can pass types other than integer. You can write your own comparison function which takes the two values and returns the “greater” value to sort ascendingly.max(a, b)ostreamName.precision(x)ostream’s precision for significant digits to x, AND returns former value.“If we name a computation [when declaring a function], we can think about it more abstractly—we can think more about what it does and less about how it works. If we can identify important parts of our problems, and create named pieces of our programs that correspond to those parts, then our programs will be easier to understand and the problems easier to solve.”
Much of the chapter is then spent paring computations from the main source file, and re-writing them as stand-alone functions that take in parameters and return a value(the result of the task of the function).
const double& midtermGrade As a constant, you will have a new name to identify the referenced object with, and when used as a parameter for a function, a new space in memory is never allocated to duplicate the object passed as a parameter because it is only referencing the already-existing spot in memory… Long-winded explanation. Lots of cool things can be done with references(and later, pointers as well, I imagine)—but can’t discuss it all in one post, let alone one definition in this quasi-glossary I’ve written!grade() that only differ in the parameters they take. In fact, the C++ implementation will know which grade() function to call depending on the parameters you pass. This is very useful—especially if you can arrive at the same result from computations on different parameters, but don’t want the programmer overhead and naming separate functions for the different computations; you can name your functions based on the result they give and not the ingredients they take(in this chapter’s exercise, grade() returns a computed grade).x.clear()clear() is an overloaded function from the standard library. For vectors, it clears or discards the entire list—all values stored are erased. For an input stream istream type, it resets the error state and any exceptions thrown.const reference, so that no new memory is spent to pass the value. Obviously, this is only useful if you only need to read the parameter and not operate on it.try { ... } catch ( exception ) { ... return 1; }try/catch statement will try to run all of the computations within the first set of braces adjacent to try, and if these fail it will stop and skip to run the second set of braces following catch. Useful for handling exceptions.int main() or any source file, so there must be some thought to declaring functions ahead of time — typically in a header file.struct structName { ... }exceptionName.what()what() is a method function that returns any of the string argument passed when an exception is thrown. This is a string the programmer usually writes when handling errors in his code, so should tell you precisely where the problem is occuring.using library::function declarations in a header?using declarations in a header file because they may clash with existing declared functions in the source. So no.#ifndef, #define, and #endif.“A function must be declared in every source file that uses it [e.g. by means of a header file], and defined only once [e.g. once in the relevant source file].” (72)
[blah blah exercise here’s the quote:]
“Imagine a course in which each student’s final exam counts for 40% of the final grade, the midterm exam counts for 20%, and the average homework grade makes up the remaining 40%. Here is our first try at a program that helps students compute their final grades…”(35)