CS12, Lab 3
Topics:
·
Memberwise copy
·
Constructors
·
Functions with default
parameters
·
Overloading (two
functions with the same name)
·
Private methods
·
Methods calling other
methods.
You will be modifying the
files from Lab 2.
To do:
· &nbsC;
Copy the files counter.h
and counter.cpp from Lab 2 into a new folder.
·
Add a
private mutator method
setCount(int value)that sets the value of count to value.
·
Change the constructor
(or add a constructor) so that a Counter object can be initialized with or
without a starting value. The default
start value for the counter, if none was specified, should be zero. When setting the value of the counter, the
constructor should use the private method setCount(int).
·
In your main program (main.cpp),
·
Create a Counter object
with some initial value other than zero.
·
Create a second Counter
object with no initial value specified.
·
Verify the values of
the Counters (print them out).
·
Assign to one of your
objects the value of the other.
·
Compare the values of
the two counters to see that they are indeed the same. Do private data members get copied on direct
assignment?
Extra credit
Experiment: