-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetOfElements.cpp
68 lines (58 loc) · 1.46 KB
/
SetOfElements.cpp
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
//
// Created by 18476 on 3/22/2022.
//
#include "SetOfElements.h"
SetOfElements::SetOfElements() {}
SetOfElements::SetOfElements(ifstream& input)
{
string line;
getline(input, line);
int num = stoi(line);
for (int i = 0; i < num; i++)
{
getline(input, line);
int colon = line.find(':');
string name = line.substr(0, colon);
line = line.substr(colon + 1);
Element e(name);
int comma = line.find(',');
while (comma != -1)
{
e.addPreference(line.substr(0, comma));
line = line.substr(comma + 1);
comma = line.find(',');
}
e.addPreference(line.substr(0, comma));
addElement(e);
}
}
void SetOfElements::addElement(Element e)
{
elementsInSet.push_back(e);
setSize++;
}
Element& SetOfElements::getPerson(string name)
{
for (int i = 0; i < elementsInSet.size(); i++)
{
if (elementsInSet.at(i).getName() == name)
return elementsInSet.at(i);
}
cout << "element not found in set" << endl;
}
vector<Element>& SetOfElements::getElements()
{
return elementsInSet;
}
int SetOfElements::getSize()
{
return setSize;
}
void SetOfElements::printSet()
{
for (int n = 0; n < elementsInSet.size(); n++){
cout << elementsInSet.at(n).getName() << ": ";
elementsInSet.at(n).printPreferences();
}
cout << endl;
}