Set of Item ( last question )

here is the code that done by me
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <string>
#include <conio.h>

using namespace std;

template< class T >
class Set{
private:
	//Cannot be negative number , validation
	static const size_t N = 100; 
	T Item[N];
	size_t count;
public:
	Set() : count(0){};
	~Set();

	void addNewItem(const T &);
	void RemoveItem(const T &);
	size_t size();
	size_t max_size();
	int FindItem(const T &);

};

template< class T >
void Set<T> :: addNewItem( const T &item){
	int result = FindItem(item);

	//Add new item when FindItem return a value -1
	if( result == -1 ){
		item[++N];
	}
	else
		cout << endl;//Nothing Happen
}

template< class T >
void Set<T> :: RemoveItem( const T &item ){
	int result = FindItem(item);

	if( result >= 0 && result < count ){
		item[--N];
	}
}
	
template< class T >
size_t Set<T> :: size() const{
	return count;
}

template< class T >
size_t Set<T> :: max_size() const{
	return N;
}

template< class T >
int Set<T> :: FindItem( const T &item ){
	int result = -1;
	for( int i = 0 ; i < count ; i++ ){
		if( item == Item[i] ){
			result = i;
			break;
		}
	}
	return result;
}

int main(){
	int choice = 0;
	string title;
	system( "pause" );//Pause window

	cout << "\tSet of items\n--------------------------" << endl
		<< "1.Add New Item " << endl
		<< "2.Remove an Item " << endl
		<< "3.Number of items in the set " << endl
		<< "4.Find Item " << endl
		<< "5.Get all Items " << endl << endl
		<< "Enter Choice : ";

	cin  >> choice;

	switch( choice ){
	case 1:{
			cout << "Enter title : ";
			getline( cin , title );
			Set<string> set;
			set.addNewItem(title);
			break;
		   }
	case 2:
		break;
	case 3:
		break;
	case 4:
		break;
	case 5:
		break;
	default:
		cout << "Invalid Input ! Please re-enter ! "<< endl;
		break;
	}
	system( "pause" );
	return 0;//Exit program
}


so my question is if i Add a new item to the set. If the item is already in the set then nothing happens.
and the remove item Remove an item from the set.

but i think my implementation for add and remove totally concept wrong right? might help ? thanks
In your addNewItem() and RemoveItem() functions, you use item instead of Item[].

Also, that's not how you use an array. If you don't know how to use an array:
http://cplusplus.com/doc/tutorial/arrays/
do you mean i can just use

item++; for it?

and for remove item just use
item--;

isn't right?
item++; and item--; change the value of item, by adding or removing 1.
They don't add it to or remove item from the Set.

To add an item to your Set class means to store it inside the Item[] array.
To remove an item means not storing it in the Item[] array.

I think you don't understand what you have to do. Talk to your teacher.
Topic archived. No new replies allowed.