Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <chrono>
- using namespace std;
- // --- --- --- --- ---
- const short N = 16;
- class set
- {
- private: bool array[N];
- public:
- void is_empty()
- {
- bool flag = true;
- for(int i = 0; i < N; i++)
- if (this->array[i]==true) flag=false;
- cout << endl;
- if(flag) cout << "It's empty";
- else cout << "It isn't empty";
- cout<<endl;
- }
- // --- --- ---
- set() { for(int i = 0; i < N; i++) this->array[i] = false; };
- // --- --- ---
- void generating()
- {
- short size_tmp = rand() % N; // generates random size for one array
- short tmp;
- for(int i = 0; i < size_tmp; i++)
- { tmp = rand() % N;
- if (this->array[tmp]==false) this->array[tmp]=true;
- }
- };
- // --- --- ---
- set operator || (const set& second) const{
- set third;
- for(int i = 0; i < N; i++)
- if((this->array[i] == true) || (second.array[i] == true)) third.array[i]=true;
- return third;
- }
- // --- --- ---
- set operator && (const set& second) const{
- set third;
- for(int i = 0; i < N; i++)
- if((array[i] == true) && (second.array[i] == true)) third.array[i]=true;
- return third;
- }
- // --- --- ---
- set operator - (const set& second) const{
- set third;
- for(int i = 0; i < N; i++)
- if((array[i] == true) && (second.array[i] == false)) third.array[i]=true;
- return third;
- }
- // --- --- ---
- void print()
- {
- cout << "[ ";
- for(int i = 0; i < N; i++)
- {
- if (this->array[i]==true)
- cout << hex << i << ' ';
- }
- cout << ']' << endl;
- }
- };
- // --- --- --- --- ---
- int main()
- {
- srand(2);
- set a, b, c, d, e, tmp;
- a.generating(); cout << "A: "; a.print();
- b.generating(); cout << "B: "; b.print();
- c.generating(); cout << "C: "; c.print();
- d.generating(); cout << "D: "; d.print();
- double result;
- cout << endl << "*Calculating result*" << endl;
- for(int i = 0; i < pow(10, 7); i++)
- {
- auto t1 = chrono::high_resolution_clock::now();
- e = ((a||c)-(b||d));
- auto t2 = chrono::high_resolution_clock::now();
- auto diff = chrono::duration_cast<chrono::duration<double>>(t2 - t1);
- result += diff.count();
- }
- cout << endl << "E: "; e.print();
- cout << "time: " << result << " seconds" << endl;
- return 0;
- }
- // --- --- --- --- --- --- --- --- ---
Add Comment
Please, Sign In to add comment