|
C M S C 2 1 4 C o m p u t e r S c i e n c e I I F a l l 2 0 0 2 |
| Item |
| Declaration | Description |
| string name | Holds the name of a food item (as passed in by the constructor). You can assume the name only contains alphabetic characters. |
| int points | The number of "points" the item is worth |
Note: all the comparison operators do case-insensitive comparisons.
| Item( const string & nameIn = "NONE", int pointsIn = 0 ) ; |
| Default constructor. Sets name to nameIn,
and points to pointsIn. Use initializer lists.
Do NOT change the case of the name to lowercase. |
| string getName() const ; |
| Returns name. |
| int getPoints() const ; |
| Returns points. |
| bool setPoints( int pointsIn ) ; |
| Set points to pointsIn, but only if pointsIn is non-negative. If it's negative, don't change the value of points and return false. If it's non-negative, then update the points, and return true. |
| bool operator==( const Item & other ) const ; |
| Returns true if name and other.name are the same (case-insensitive). Implement using compare() (a private method). |
| bool operator!=( const Item & other ) const ; |
| Returns true if name and other.name are different (case-insensitive). Implement using compare() (a private method). |
| bool operator<( const Item & other ) const ; |
| Returns true if name is "less than" other.name (case-insensitive). Implement using compare() (a private method). |
| bool operator<=( const Item & other ) const ; |
| Returns true if name is "less than or equal to" other.name are different (case-insensitive). Implement using compare() (a private method). |
| bool operator>( const Item & other ) const ; |
| Returns true if name is "greater than" other.name (case-insensitive). Implement using compare() (a private method). |
| bool operator>=( const Item & other ) const ; |
| Returns true if name is "greater than or equal to" other.name are different (case-insensitive). Implement using compare() (a private method). |
| string toString() ; |
| Returns a string, which, when printed, prints the item name and points, appropriate to be used in printing ItemArrayList and ItemSortedList. That is, it should be used by their toString() method. |
The following methods should be implemented, if you feel they are NECESSARY (meaning that the implicit versions of these methods are inadequate).
| Item( const Item &other ) ; |
| Copy constructor. If you choose to implement, you must use helper methods: freeMem(), init(), and/or copy(). |
| Item &operator=( const Item &other ) ; |
| Assignment operator. If you choose to implement, you must use helper methods: freeMem(), init(), and/or copy(). |
| ~Item(); |
| Destructor. If you choose to implement, you must use helper methods: freeMem(), init(), and/or copy(). |
| static int compare( const string & one, const string & second ) ; |
| Does a case-insensitive comparison of one and
two, the parameters of this static method (this can be done by
converting both to lower case---hint: use transform in STL).
If one is less than two, return -1.
This method behaves very much like strcmp in its return value (i.e., using -1, 0, and 1). |
If you do choose to implement the copy constructor, assignment operator, and destructor, implement the following methods and use them as helper functions for the three methods.
There should be a file in the posting account (under Tutorial directory) on writing copy constructors, assignment operator, destructors. You should read that.
| void init() ; |
| Behaves like default constructor. |
| void copy( const Item & other ) ; |
| Behaves like copy constructor (no deleting of nodes). |
| void freeMem() ; |
| Behaves like destructor. |
You may add other private methods.
|
See the class syllabus for policies concerning email Last Modified: Tue Sep 17 19:01:23 EDT 2002 |
|
|
|
|
|