As we continue our timer journey...
Better output
Up to this point in your journeyings of the wonderful world of C++ you
have been using cout to do output. This is soooooo boring. WIBNIF
we could make a 7-segment timer display? Lets try.
A 7-segment display looks like the following:
But before we can get an oject of type 7-segment display we need to first
define a segment object. And not only do we need to define it, but we must
make it general enough so that we could use it in many applications.
Lets look at a header file for our segement called segment.h
Lets examine the file segment.cpp
- We get the class segment declaration via:
#include "segment.h"
- Contained in segment.cpp are the member function definitions for a
segment object.
- We change the display only when the on/off stage changes for a segment.
And how about a demo of our segment segmentTest.cpp
- This is a simple driver program to test and see if the segment class
has been defined correctly and is in working condition.
- It is always a good idea to write a simple driver to check out a class
before using it in something that is complicated.
Now lets design another class sevenSegDisplay which is in the file
7seg.h
- This file contains the class declaration for a sevenSegDisplay.
- We again use the #ifndef, #define, #endif construct.
- The member functions are constructors, clear, and show.
- The private data are color, objects for each of the seven segments.
- Notice that we included this line:
#include "segment.h"
This ensures that the segment class is known to the compiler.
Now lets look at 7seg.cpp
Make sure you check out the driver 7segTest.cpp
Now lets make a class for a counter in file counterDisp.h
- Notice the statement
#include "7seg.h"
- We have numerous constructors which gives us lots of flexibility.
- The private data is two sevenSegDisplays plus limits and the current
value. This makes 2 * 7 = 14 segments all together. So we start to see
the power we have by being able to manipulate 14 segments and have them
work independently of each other.
Now lets examine a test run of our new counter
See Demo counterDispTest.cpp
Now let's look at HMStimer.h
- Private member data includes 3 counters, which gives 3 * 2 * 7 = 42
segments.
- Also upper and lower limits for hours.
- Here we have a private member function showColon().
- Needed only by other member functions.
- Never called by any function outside the timer class.
And we run HMStimer.cpp
The geometry involved in the timer is given below:
- Notice that showColon() is called only in constructor, since it is
never erased.
- Notice also the other member functions: ++, set(), and show().
See Demo HMSTimerTest.cpp for test run of timer.
A few notes about Assignment #10
- Add an alarm feature.
- Handout mentions two things you will have to do.
To Index
Previous
Next