CMSC 202 Computer Science II, Fall 2015, Section 06
Lecture 3: Python vs C++
Thu 09/03, 2015
Assigned Reading: "3.1-3.3, 4.1"
Slides As Shown:
- Continued with array example.
- Version 2 declared a C++ class called myArray
in the header file:
The member functions are implemented in:
Note the existence of a constructor and a destructor.
Two main programs exercise the class:
- Version 3 adds an append() member function.
(See header file:
We now have to maintain, a capacity cap and
an length len. These are private data members.
In the implemtation
note that the capacity of the array is doubled each
time that we run out of space. There are some examples of defensive
programming in this implementation.
Main programs to exercise Version 3:
- Version 4 adds a copy constructor and an overloaded
assginment operator for myArray:
These two features make sure that a copy is made when a myArray
object is assigned, passed as a parameter or returned from a function.
Main programs to exercise Version 4:
- Version 5 adds overloaded [ ] (indexing) and
+ operators. It also has an overlaoded <<
operator outside the class. (See
This allows us to use a myArray object more conveniently.
Main programs to exercise Version 5:
8 Sep 2015 00:50:44 EDT