Random set numbers and its size

I've begun to do a new program, but I've hit a roadblock and need help. I'm trying to enter the size of a set that has a random number generator in it. So when I enter in the size should be 3 I should get 3 random numbers, but that doesn't happen. The code will look a bit off since I wanted to see if the function actually worked before progressing further.

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
  #include <iostream>
#include <set>
#include <ctime>
#include <cstdlib>
using namespace std;

class Set {

public:


	//default constructor
	Set();
	//add element to set
	void addElement(int element);
	//remove element from set
	void removeElement(int element);
	//check for membership
	bool isMember(int element);
	//set union, modifies curremtn set
	void Union(Set s);
	//set difference modifiers current set
	void difference(Set s);
	//size of set
	int size();
	//get element i
	int getElement(int i);

private:

	//binary search for element, returns index
	bool search(int element, int& index);
	//set members
	//int elements[maxElements];
	//next empty position in elements
	int next;
};

Set::Set()
{
	
}

int Set::size()
{
	srand(time(0));
	set<int> s{ rand() % 25 + 1 };
	int S_size;
	cout << "Enter in the size of the set" << endl;
	cin >> S_size;
	for (int i = 0;i < S_size;i++)
	{
		cout << s.size();
	}
	return s.size();
}

int main(set<int>&)
{
	Set enter;
	enter.size();
	
}
set s is destroyed after size() is done.
it seems like you should have that as a class member, not a local?
it also seems like the loop should add a random number to s every iteration, and the initial set should be empty instead of having 1 random value.
also, consider <random> instead of C's random tools.
Registered users can post here. Sign in or register to post.