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
|
#include <iostream>
#include <string>
#include "Set.h"
#include <vector>
using namespace std;
void ShowDetails(const Set& mySet, string setName);
int main()
{
vector<int> myVector = { 1, 3, 5, 7, 9 };
vector<int> myVector2 = { 1, 13, 5 };
//Create the Sets:
Set setA(myVector);
Set setB(myVector2);
Set setC;
//Add item(s) to sets:
setA.Add(77);
setB.Add(777);
setC.Add(7777);
//Display details of the Sets:
ShowDetails(setA, "setA");
ShowDetails(setB, "setB");
ShowDetails(setC, "setC");
//########## Test the IsThere member function ##########//
cout << "===== Testing IsThere Member Function =====" << endl;
cout << "5 is in setA: " << setA.IsThere(5) << endl;
cout << "20 is in setA: " << setA.IsThere(20) << endl;
cout << "============================================" << endl;
//Create the Sets:
Set setU_AB;
Set setU_BA;
Set setI_AB;
Set setI_BA;
Set setD_AB;
Set setD_BA;
//Run set operations & display details of the Sets:
//########## Test the Union member function ##########//
setU_AB = setA.Union(setB);
setU_BA = setB.Union(setA);
ShowDetails(setU_AB, "setU_AB (A U B)");
ShowDetails(setU_BA, "setU_BA (B U A)");
//########## Test the Intersection member function ##########//
setI_AB = setA.Intersection(setB);
setI_BA = setB.Intersection(setA);
ShowDetails(setI_AB, "setI_AB (A & B)");
ShowDetails(setI_BA, "setI_BA (B & A)");
//########## Test the Difference member function ##########//
setD_AB = setA.Difference(setB);
setD_BA = setB.Difference(setA);
ShowDetails(setD_AB, "setD_AB (A - B)");
ShowDetails(setD_BA, "setD_BA (B - A)");
return 0;
}
void ShowDetails(const Set& mySet, string setName)
{
cout << "Member(s) in "<< setName <<": "; mySet.Print(); cout << endl;
cout << "Member count: " << mySet.Count() << endl;
cout << "============================================" << endl;
}
|