Lecture 3
Learning objectives
After this class (which reviews C++ material that you should already know!), you should be able to:
- Mention two benefits of data hiding.
- Mention which type of file typically contains the interface, and which the implementation, in C++.
- Give examples of some common errors with the use of pointers.
- Given code with incorrect use of pointers, identify the problems and correct them.
- Explain when "deep copy" is needed, why it is needed, and what are the typical features that need to be implemented to ensure deep copy.
- Explain why self-assignment can lead to incorrect code, when we overload assignment to ensure deep copy.
Reading assignment
- Chapter 1, sections 1.4-1.5.
- Lecture: C++ review.
- Review templates from COP 3330. Section 1.6 will help you with this material.
Exercises and review questions
- Exercises and review questions on current lecture's material
- What are two benefits of information hiding?
- Will the interface normally be in a .h file or in a .cpp file?
- Will the implementation normally be in a .h file or in a .cpp file?
- Questions on next lecture's material
- Write a template class called
complex
, which stores a complex number. The components may either be int, float, or double. Include an operator for adding two complex numbers, and for outputting a complex number. (Note: A complex number is a pair of numbers (x,y). The sum of complex numbers c1 = (x1, y1) and c2 = (x2, y2) is defined as the complex number (x1+x2, y1+y2).)- Can you find out where the STL header files are, on the machine
linprog
?
Last modified: 2 Sep 2011