Repository navigation
Expand file tree
/
Copy pathq035.cpp
More file actions
117 lines (98 loc) · 3.01 KB
/
Copy pathq035.cpp
File metadata and controls
117 lines (98 loc) · 3.01 KB
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
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <string>
using namespace std;
class ArraySet {
private:
string array[10];
int quantity;
public:
ArraySet() {
quantity = 0;
}
int size() {
// retorna a quantidade de elementos do conjunto
return quantity;
}
bool isEmpty() {
// o conjunto estará vazio quando quantity == 0
if (quantity == 0){
return true;
}
else {
return false;
}
}
bool contains(string s) {
for (int i = 0; i<quantity; i++){
if (array [i] == s){
return true;
}
}
return false; // so retorna false depois de olhar o array inteiro
}
bool add(string s) {
if (contains(s)){ //chamada de funcao precisa de argumento
return false;
}
if (quantity < 10){ // verifica se quantity é menor que 10
array[quantity] = s;
quantity = quantity + 1;
return true;
}
return false;
}
void print() {
cout << "[ ";
for(int i = 0; i < quantity; i++) {
cout << array[i] << " ";
}
cout << "]" << endl;
}
};
int main() {
ArraySet set; //o array teste
cout << "============================" << endl;
cout << "TESTE 1 - CONJUNTO VAZIO" << endl;
cout << "============================" << endl;
cout << "Conjunto vazio? ";
cout << set.isEmpty() << endl;
cout << endl;
cout << "============================" << endl;
cout << "TESTE 2 - ADICIONANDO" << endl;
cout << "============================" << endl;
cout << "Add Ana: ";
cout << set.add("Ana") <<endl;
cout << "Add Carlos: ";
cout << set.add("Carlos") <<endl;
cout << "Add Maria: ";
cout << set.add("Maria")<<endl;
cout << "Add Ana novamente: ";
cout << set.add("Ana")<<endl;
cout << endl;
cout << "============================" << endl;
cout << "TESTE 3 - PRINT" << endl;
cout << "============================" << endl;
set.print();
cout << endl;
cout << "============================" << endl;
cout << "TESTE 4 - SIZE" << endl;
cout << "============================" << endl;
cout << "Quantidade: ";
cout << set.size();
cout << endl;
cout << "============================" << endl;
cout << "TESTE 5 - CONTAINS" << endl;
cout << "============================" << endl;
cout << "Existe Maria? ";
cout << set.contains("Maria")<<endl;
cout << "Existe Joao? ";
cout << set.contains("Joao")<<endl;
cout << endl;
cout << "============================" << endl;
cout << "TESTE 6 - CONJUNTO VAZIO" << endl;
cout << "============================" << endl;
cout << "Conjunto vazio? ";
cout << set.isEmpty();
cout << endl;
return 0;
}