-
Notifications
You must be signed in to change notification settings - Fork 0
/
project7.cpp
94 lines (86 loc) · 3.31 KB
/
project7.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
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
/*
* Keita Nonaka
* CS255:01
* 7th: pp 463-4 #10.8
* 3/8/2018
* c++ 17
*
* I created integer set class.
* There are two cpp files and one header file.
* These files are for calculating set such as {1, 5, 8, 10}.
*/
#include "IntegerSet.h"
#include <iostream>
using namespace std;
int main(){
int num = 0;
IntegerSet A;
IntegerSet B;
cout << endl << "-------------------------------- SET CREATION ---------------------------------" << endl; // creation
cout << "Enter set A one element at a time" << endl << "The range of the set is 0 through 100 (inclusive)" << endl;
cout << "Enter -1 when you are done entering set A" << endl; // insert elements to set A
for(;;){ // infinite loop
cout << "Enter an element: ";
cin >> num;
if(num == -1)
break;
else if(num >= 0 && num <= 100)
A.insertElement(num);
}
cout << "element:" << endl << "Set A = { ";
A.printSet();
cout << "\nEnter -1 when you are done entering set B" << endl; // insert elements to set B
for(;;){ // infinite loop
cout << "Enter an element: ";
cin >> num;
if(num == -1)
break;
else if(num >= 0 && num <= 100)
B.insertElement(num);
}
cout << "element:" << endl << "Set A = { ";
B.printSet();
cout << "---------------------------------- DELETION -----------------------------------" << endl; // deletion
cout << "Enter any elements you want to delete from set A one at a time" << endl;
cout << "Enter -1 when you are done deleting from set A" << endl; // delete elements of set A
for(;;){ // infinite loop
cout << "A = { ";
A.printSet();
cout << "Enter an element to delete: ";
cin >> num;
if(num == -1)
break;
else if(num >= 0 && num <= 100)
A.deleteElement(num);
}
cout << "Enter any elements you want to delete from set B one at a time" << endl;
cout << "Enter -1 when you are done deleting from set B" << endl; // delete elements of set B
for(;;){ // infinite loop
cout << "B = { ";
B.printSet();
cout << "Enter an element to delete: ";
cin >> num;
if(num == -1)
break;
else if(num >= 0 && num <= 100)
B.deleteElement(num);
}
cout << "-------------------------------- DEMONSTRATION --------------------------------" << endl; // demonstration
cout << "Set A = { ";
A.printSet();
cout << "Set B = { ";
B.printSet();
cout << "Intersection of A and B = { ";
A.intersect(B).printSet(); // intersect
cout << "Union of A and B = { ";
A.unionize(B).printSet(); // union
cout << "Complement of A and B = { ";
A.unionize(B).complement().printSet(); // complement
cout << "Difference of A and B = { ";
A.difference(B).printSet(); // difference
A.subset(B) ? cout << "A is a subset of B" << endl : cout << "A is not a subset of B" << endl;
B.subset(A) ? cout << "B is a subset of A" << endl : cout << "B is not a subset of A" << endl;
A.isEmpty() ? cout << "A is empty" << endl : cout << "A is not empty" << endl;
B.isEmpty() ? cout << "B is empty" << endl : cout << "B is not empty" << endl;
A.isEqualTo(B) ? cout << "A and B are equal" << endl : cout << "A and B are not equal" << endl;;
}