CS 202 Fall 2013 > In-Class Challenge for Tuesday, October 8, 2013 |
CS 202 Fall 2013
In-Class Challenge for Tuesday, October 8, 2013
This challenge deals with C++ class TimeSec
again.
It is implemented in files
timesec.h
and
timesec.cpp
,
unfinished versions of which are on the web page.
You do not need to have made the changes from last time to do this challenge!
You will also be writing a class Event
.
An unfinished version of this can be found on the webpage
in files
event.h
and
event.cpp
.
Our Goal
An Event
object should hold the name
and time-of-day of an event,
as a string
and a TimeSec
,
respectively.
Class Event
should have a constructor
that takes a string
and three int
values.
It should construct the event name from the string
and the time from the three int
s (hours, minutes, seconds).
If the parameters of the constructor are left out,
they should default to the empty string
and 0, 0, 0, respectively.
Class Event should have a stream insertion operator
(<<
),
which should print an event
as the event name, followed by a blank,
followed by the time in parenthesis,
in the same format as member function print
of class TimeSec
.
For example:
[C++]
Event e1("Hello"); cout << e1; // Prints (without quotes): "Hello ( 0:00:00)" Event e2("Goodbye", 12,13,14); cout << e1; // Prints (without quotes): "Goodbye (12:13:14)"
What to Do
Do as many of the following as you can before class ends. After each, please show me your work.
- Add a stream insertion operator (
<<
) to classTimeSec
. This should output a time in the same format as the existing member functionprint
. The resulting class should compile and pass all tests intest4_timesec.cpp
. - Write class
Event
as above. The resulting class should compile and pass all tests intest_event.cpp
.
Some Reminders
- Get things to compile first, right?
- Don’t Repeat Yourself!