This is not a complete review of everything you guys have seen since the first midterm. Be sure to go through all of Professor Radke's lecture slides for more details and examples. This review is only meant to jog your memory on key things we've covered in discussion.
A copy of the input is made and the copy is passed into the function, meaning any changes made to the input variable will not be reflected in the original variables. For example,
No copy of the input is made so the actual variable itself is passed into the function, meaning any changes made to the input variable WILL change the original variable. For example,
No copy of the input is made so the actual variable itself is passed into the function, but the
const keyword guarantees no changes can be made. For example,
There are examples in Professor Radke's lecture slides that force us to really understand the implications of pass-by-value vs pass-by-reference.
Using the same function name with different function definitions. This is allowed only if these functions can be differentiated by the input parameter types! Note that we cannot distinguish between pass-by-value, pass-by-reference, pass-by-const-reference. For example,
This is the act of redefining operators so that they are compatible with our own user-defined classes. Operators include
<, <=, >, >=, ==, +, -, *, / etc.
We need to include two libraries to generate random numbers:
srand(time(0)) is for seeding the random number generator, and it ONLY GOES AT THE VERY TOP OF
int r = rand() % (b-a+1) + a
double u = (double)(rand())/RAND_MAX;
double r = u * (b-a) + a
Look at the last slide of Lecture 18.
Know all the pieces of defining a class:
Here's a pretty in-depth coding practice problem where you need to define the member functions for the
Rectangle class and a non-member function
Rectangle max(const vector<Rectangle>& vec); so that the
int main() code included will compile and run correctly.