-1

The positionOf() method, it is declared as private in the private section of the set class declared in the .h file. You define the method the exact same way you define public methods, in the .cpp implementation file for the class. The private means you can call this method from any class method but not from outside the class, for instance, in the main method.

int set::positionOf(SET_ELEMENT_TYPE searchElement)

Returns the position of searchElement or -1 if not found by sequentially searching the vector for the searchElement.

Use a for loop to locate the searchElement if it is in the vector. Use the four iterator methods in the for loop: first(); !isDone(); next() and use currentItem() to check if it is equivalent to the searchElement. If the searchElement is found return the value stored in my_index.

If not found, outside the for loop return -1, meaning the searchElement was not found

Votes + Comments
Not here to do your work for you. At least attempt it first then come here where you get stuck and tell us what you tried
3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Fbody
0

Yeah I wish I could just use that but this is the first part of an assignment an I have to use the positionOf.

0

So figure out how to define set::positionOf(). Once you have made an attempt, let us know how you did.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.