I need to complete a program in C++. #include <iostream> #include <iterator> #in
ID: 3859506 • Letter: I
Question
I need to complete a program in C++.
#include <iostream>
#include <iterator>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
int setA[5] = {2, 4, 5, 7, 8};
int setB[7] = {1, 2, 3, 4, 5, 6, 7};
int setC[5] = {2, 5, 8, 8, 15};
int setD[6] = {1, 4, 4, 6, 7, 12};
set<int> set2A(setA,setA+5);
// TODO define set2B initialized from setB
// TODO define set2C initialized from setC
// TODO define set2D initialized from setD
int AunionB[12];
// TODO define AunionB
// TODO define CunionD
// TODO define AintersectB
// TODO define CintersectD
// TODO define finalUnion
// TODO define finalIntersection
set<int> final2Union;
set<int> final2Intersection;
set<int> final2Difference;
int *lastAunionB;
// TODO define lastAunionB
// TODO define other required variables
ostream_iterator<int> screen(cout, " ");
cout << "setA = ";
copy(/* print setA using copy */);
cout << endl;
// TODO print setB, setC, and setD using copy
lastAunionB = set_union( // TODO set AunionB to a union of setA and setB
// TODO );
// TODO print AunionB using copy
// TODO set CunionD to a union of setC and setD
// TODO print CunionD using copy
lastAintersectB = set_intersection(// TODO set AintersectB to an intersection of setA and setB
// TODO );
// TODO print AintersectB using copy
// TODO set CintersectD to an intersection of setC and setD
// TODO print CintersectD using copy
// TODO set finalUnion to a union of setA, setB, setC, and setD
// TODO print finalUnion using copy
// TODO set finalIntersection to an intersection of setA, setB, setC, and setD
// TODO print finalIntersection using copy
set_union(set2A.begin(), set2A.end(), set2B.begin(), set2B.end(), inserter(final2Union, final2Union.end()));
// TODO make final2Union a union of set2A, set2B, set2C, and set2D
// TODO print final2Union using copy
// TODO make final2Intersection an intersection of set2A, set2B, set2C, and set2D
// TODO print final2Intersection using copy
cout << "finalUnion == final2Union : ";
cout << lexicographical_compare(//TODO compare finalUnion and final2Union
) << endl;
// TODO compare finalIntersection and final2Intersection and print the comparison result
return 0;
}
The "//TODO" are all the things that need to be done. Someone please help me fast.
Explanation / Answer
#include <iostream>
#include <iterator>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
int setA[5] = {2, 4, 5, 7, 8};
int setB[7] = {1, 2, 3, 4, 5, 6, 7};
int setC[5] = {2, 5, 8, 8, 15};
int setD[6] = {1, 4, 4, 6, 7, 12};
set<int> set2A(setA,setA+5);
int AunionB[12];
set<int> final2Union;
set<int> final2Intersection;
set<int> final2Difference;
int *lastAunionB;
ostream_iterator<int> screen(cout, " ");
cout << "setA = ";
copy(/* print setA using copy */);
cout << endl;
lastAunionB = set_union
lastAintersectB = set_intersection intersection of setA and setB
set_union(set2A.begin(), set2A.end(), set2B.begin(), set2B.end(), inserter(final2Union, final2Union.end()));
set2D
cout << "finalUnion == final2Union : ";
cout << lexicographical_compare(//TODO compare finalUnion and final2Union
) << endl;
comparison result
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.