Access Millions of academic & study documents

According to the code below, assume there a three arrays s1, s2, s3

Content type
User Generated
Showing Page:
1/6
According to the code below, assume there a three arrays
s1, s2, s3. and there are some element in array s1 and s2.
Write a C++ program. Design classes, arrays in classes,
operator overloading.
1. Overload the \"+\" operator to implement the union of
two sets. Returns a new setthat contains all the elements
of the both sets.
2. Overload the \"*\" operator to implement the intersection
of two sets. Returns a newset that contains all the
elements that are in both sets.
3. Overload the \"-\" operator to implement the set
difference. Returns a new set thatcontains all the elements
that are in the first set but not in the second.
Solution
#include<iostream>
using namespace std;
class Sets
{
int a[15],n;
public:
Sets(){}
Sets(int n)
{

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/6
this->n=n;
}
void get();
void display();
void sort();
void operator +(Sets);
void operator -(Sets);
void operator <(Sets); //superset
void operator >(Sets); //subset
};
void Sets :: operator <(Sets s2)
{
Sets s3;
}
void Sets::get()
{
cout<<\"\ \ Enter the Set Values : \";
for(int i=0;i<n;i++)
cin>>a[i];
sort();
}
void Sets ::sort()
{
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/6

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 6 pages?
Access Now
Unformatted Attachment Preview
According to the code below, assume there a three arrays s1, s2, s3. and there are some element in array s1 and s2. Write a C++ program. Design classes, arrays in classes, operator overloading. 1. Overload the \"+\" operator to implement the union of two sets. Returns a new setthat contains all the elements of the both sets. 2. Overload the \"*\" operator to implement the intersection of two sets. Returns a newset that contains all the elements that are in both sets. 3. Overload the \"-\" operator to implement the set difference. Returns a new set thatcontains all the elements that are in the first set but not in the second. Solution #include using namespace std; class Sets { int a[15],n; public: Sets(){} Sets(int n) { this->n=n; } void get(); void display(); void sort(); void operator +(Sets); void operator -(Sets); void operator (Sets); //subset }; void Sets :: operator ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4

Similar Documents