CMSC 202 Computer Science II, Spring 2016, Section 01
Lecture 4: Python vs C++
Thu 02/04, 2016
Assigned Reading: 3.1-3.3, 4.1
Slides As Shown:
- Finish Python vs C++ basic syntax
- Python lists vs C/C++ arrays
- Playing with C/C++ arrays:
- Putting an array and its length in a struct:
- 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:
29 Mar 2016 12:15:35 EDT