We'll continue our tour of C++ in this lecture, with a particular focus on three areas:
Also, this lecture is a bit long. They won't all be like this, I promise!
1: Fundamental Types and Implicit Conversions
Let's take a look at the set of fundamental data types built in to the C++ language, as well as the rules for implicit conversion between them. I'll also point out that explicit conversions are possible, where we directly request a conversion. In some cases this may be necessary. In others, it's stylistically preferrable to make an otherwise implicit conversion more obvious. Here's a few examples:
In C++, the |
2: Functions
In more complex programs, it's essential to define functions to abstract away details. |
3: Standard Library Types
The C++ Standard Library provides a variety of container and utility types. We'll take a look at a few now, including |
4: Iteration
4.1
In imperative programming, loops allow us to iterate through a set of instructions multiple times as long as some condition is true. C++ has two primary looping constructs,
4.1 Exercise: Vector Sum
Fill in the blanks so that the code computes the sum of elements in the vector. If your code compiles, but you're not getting credit, try clicking the "Simulate" button to step through the code and see where it's going wrong. Sample solution…
Make sure to return to finish the video after completing the exercise!
|
5: Branching
5.1
The
5.1 Exercise: Vector Minimum
Fill in the blanks so that the code finds the minimum value in the vector. If your code compiles, but you're not getting credit, try clicking the "Simulate" button to step through the code and see where it's going wrong. Sample solution…
Make sure to return to finish the video after completing the exercise!
|
6: Logical Operations and Short-Circuit Evaluation
Sometimes we need to create compound boolean expressions using the |
7:
break; and continue;
Finally, a miscellaneous topic. C++ also has special |
8: Procedural Abstraction
Switching gears a bit, let's take a look at the high-level organization of a program using procedural abstraction to make our code easier to write, understand, and maintain. |
9: Header Files, Makefiles, and Project 1
9.1
As projects grow more complex, we often need to split the code into several different modules. In C++, we often use use a We'll use project 1 as an example to illustrate each of these. First, we'll look at the role of function prototpyes and header files. Now, some discussion of the overall structure of project 1 and the
9.1 Exercise: Interface vs. Implementation
Categorize each of the following according to whether they are part of the interface or implementation (write "interface" or "implementation" in each box). Function declaration in Function definition in Code inside the function's curly braces Which input values are valid or invalid for the function Comments inside the function to clarify tricky lines of code RME comment before the function declaration in Sample solution… Function declaration in Function definition in Code inside the function's curly braces Which input values are valid or invalid for the function Comments inside the function to clarify tricky lines of code RME comment before the function declaration in |
10: RMEs for Interface Specification
It's useful to adopt a common patten for comments that specify function interfaces. In EECS 280, we'll use RMEs:
|
11: Unit Testing
11.1
Finally, let's take a bit of time to talk about unit testing. We need to make sure the code we write actually works. In particular, we'll look at unit testing as a strategy for making sure that the implementation we write for a function actually works according to the interface we've decided for it to have. We'll look at some examples and general strateiges for writing good tests.
11.1
Which of the following are true statements about unit tests? |