Topical Information
This lab will help you practice with vectors and templates.
Program Information
Write a function to remove all duplicates from a vector sent as its sole argument.
Since that specification doesn't specify what type of data is present,
make sure your function can run with any [reasonable] type as the vector's base type.
Of course, you'll need to write a little driver program to make sure your
function is working properly...
Thought Provoking Questions
- What types of elements can your function's vector argument hold? (i.e. What's the vector's base type?)
- How can you go through all of the elements in a vector? Do you know how long a vector is? How does one access the content of an
individual position? What is the data type of a position — not
the content of the position, but the position itself! — ?
- How can you detect that an element is repeated? (i.e. "is the same as one
'already' seen?") (*nudge* "is the same as the one I'm examining right
now?") (*wink* "while I'm looking at a certain one, I notice that one of
those following is the same...") (*shrug* *waves and points*)
- How can you remove a found repeat? Do you have to code removal of an
element from a vector or is there already a
function for this action?
- Would functions help to make this program more manageable? If so,
describe your design for each. If not, why the heck did we learn about
those darn things?!? *(&^&%^%$ Jason! *(^&*^%$%$^ C++!
*(&)^&% programming!
This assignment is (Level 2.5).
Options
Add (Level 1) to overload your function to
also handle vectors of doubles — definitely an unreasonable type.
And why not overload it to remove duplicate characters from a string, too! Too much? *sigh* Okay, then add
another (Level 0.5) for this one. *shakes
head* "Entitlement"...Bah! (*grin*)
Add a further (Level 1.5) to overload your
function to also handle arrays of any base
type and length.
Add (Level 1) to place your function(s) in a
library.