2.1 Another example/exercise with C++ references
On the accompanying slide we have shown a number of examples that illustrate different uses of reference types in C++.
Your task in this exercise is to come up with yet another good and convincing example of reference types in C++. (Please use your own fantasy - not some internet fantasy).
Your program can be seen as the solution to a programming exercise about references. Please provide a short formulation of this exercise.
2.2 Pointers in combination with references
In this exercise we will explore pointers and references relative to each other. Play and learn! We do this in context of a function that returns the maximum of two doubles. Here is the function with call-by-value parameters:
double max(double a, double b){ return a < b ? b : a; }
In all cases below, program the max function, call it, make make sure you get the expected result from the call.
Please be aware that the cases become increasingly strange...
Can you imagine other interesting variations?
2.3 Contrasting use of C# and C++ classes: Class Point
In this exercises we will explore some basic similarities and differences between use of classes in Java/C# and C++. (In the scope of this lecture we will NOT be concerned with class definition details. This belongs to a forthcoming lecture). In particular we will study creation/allocation of objects, and parameter passing of objects to a function/method.
The starting point is the simple Point class in C# and a sample C# client program that creates and operates on points. On purpose, I do not use C# properties - but simple accessor methods (ala Java). Make sure that you familiarize yourself with the correct output of this program. Predict it before you run it.
We provide a similar Point class in C++. The C++ definitions of the Point functions are also provided (but they are not important for this exercise). You are supposed to explore various uses of class Point in C++.
Feel free to do other experiments based on the Point classes that help you understand the similarities and differences between use of C# and C++ classes, pointers, references, and stack allocation of C++ objects.
Generated: Tuesday August 1, 2017, 13:25:57