Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

. Write a class Intset for modeling sets of integers in the range 0 through 99.

ID: 3730809 • Letter: #

Question

. Write a class Intset for modeling sets of integers in the range 0 through 99. A set should be represented internally as an array of type bool: The ith array element will be true whenever integer i is in the set and will be false whenever integer i is not in the set. Include a no-argument constructor that initializes a set to the so-called "empty set," i.e., a set whose array representation contains all false values. The class should include the following overloaded operators: +to perform the union of two set (the union of sets A and B is the set that contains all elements of set A or set B, or both) to perform the intersection of two sets (the intersection of sets A and B is the set that contains all elements in both set A and set B.) to form the difference of two sets (the difference of sets A and B is the set containing those elements that are in A but not in B) to add an integer into a set. +- - to delete an integer from a set. to determine if two sets are equal to form the complement of a set (the complement of set A, denoted A, is the set containing all the elements in the universal set that are not in A - the universal set for this problem is the set containing all integers between 0 and 99) to determine if one set is a subset of another set (set A is a subset of set B means that for any element x in A, x is also an element of set B) to display a set in roster notation (for example, {2, 3, 5,9})

Explanation / Answer

here is your program : ----------->>>>>>>>>.

#include<iostream>

using namespace std;

class IntSet{
bool data[100];

public:
  IntSet(){
   for(int i = 0;i<100;i++){
    data[i] = false;
   }
  }
  IntSet operator=(IntSet oth){
   for(int i = 0;i<100;i++){
    data[i] = oth.data[i];
   }
   
   return *this;
  }
  IntSet operator+(IntSet &oth){
   IntSet temp;
   for(int i = 0;i<100;i++){
    if(oth.data[i]){
     temp.data[i] = oth.data[i];
    }
    if(data[i]){
     temp.data[i] = data[i];
    }
   }
   
   return temp;
  }
  IntSet operator*(IntSet &oth){
   IntSet temp;
   for(int i = 0;i<100;i++){
    if(oth.data[i] && data[i]){
     temp.data[i] = oth.data[i];
    }
   }
   
   return temp;
  }
  IntSet operator-(IntSet &oth){
   IntSet temp;
   for(int i = 0;i<100;i++){
    if(data[i] && oth.data[i] == false){
     temp.data[i] = oth.data[i];
    }
   }
   
   return temp;
  }
  void operator+=(int ind){
   if(ind >= 0 && ind < 100){
    data[ind] = true;
   }
  }
  void operator-=(int ind){
   if(ind >= 0 && ind < 100){
    data[ind] = false;
   }
  }
  bool operator==(IntSet &oth){
   for(int i = 0;i<100;i++){
    if(data[i] && oth.data[i] == false){
     return false;
    }
    if(oth.data[i] && data[i] == false){
     return false;
    }
   }
   
   return true;
  }
  bool operator<=(IntSet &oth){
   for(int i = 0;i<100;i++){
    if(data[i] && oth.data[i] == false){
     return false;
    }
   }
   
   return true;
  }
  
  void operator!(){
   for(int i = 0;i<100;i++){
    if(data[i]){
     data[i] = false;
    }else if(data[i] == false){
     data[i] = true;
    }
   }
  }
  friend ostream& operator<<(ostream &out,IntSet &oth){
   out<<"{";
   int st = 0;
   for(int i = 0;i<100;i++){
    if(oth.data[i]){
     if(st != 0){
      out<<", ";
     }
     out<<i;
     st = 1;
    }
   }
   out<<"}";
   return out;
  }
};


void menu(){
system("cls");
cout<<" Select An Option : ";
cout<<" 1. - Add number to set";
cout<<" 2. - Remove Number From a set";
cout<<" 3. - Form The Union of two set";
cout<<" 4. - Form The Intersection of two set";
cout<<" 5. - Form The Difference of two set";
cout<<" 6. - Determine if two set are equal";
cout<<" 7. - Form the Complement of set";
cout<<" 8. - Determine the one set is a subset of another set";
cout<<" 9. - Display a Set";
cout<<" 10. - Exit ";
}

int main(){
IntSet arr[10];
int ch = 0;
while(ch != 10){
  menu();
  cin>>ch;
  switch(ch){
   case 1:
    {
     string c;
     int n;
     cout<<" Add Number To Which Set(A,B,C,D,E,F,G,H,I,J) ? ";
     cin>>c;
     string s = "y";
     while(s[0] == 'y'){
      cout<<" enter number to add : ";
      cin>>n;
      arr[(int)(c[0] - 'A')] += n;
      cout<<" Add Another Number (y/n) : ";
      cin>>s;
     }
     break;
    }
   case 2:
    {
     string c;
     int n;
     cout<<" Remove Numbers from Which Set(A,B,C,D,E,F,G,H,I,J) ? ";
     cin>>c;
     cout<<" enter number to remove : ";
     cin>>n;
     string s = "y";
     while(s[0] == 'y'){
      cout<<" enter number to remove : ";
      cin>>n;
      arr[(int)(c[0] - 'A')] -= n;
      cout<<" Remove Another Number (y/n) : ";
      cin>>s;
     }
     break;
    }
   case 3:
    {
     string c,c1,c3;
     cout<<" First Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c;
     cout<<" Second Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c1;
     cout<<" Result Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c3;
     arr[(int)(c3[0] - 'A')] = arr[(int)(c[0] - 'A')] + arr[(int)(c1[0] - 'A')];
     break;
    }
   case 4:
    {
     string c,c1,c3;
     cout<<" First Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c;
     cout<<" Second Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c1;
     cout<<" Result Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c3;
     arr[(int)(c3[0] - 'A')] = arr[(int)(c[0] - 'A')] * arr[(int)(c1[0] - 'A')];
     break;
    }
   case 5:
    {
     string c,c1,c3;
     cout<<" First Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c;
     cout<<" Second Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c1;
     cout<<" Result Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c3;
     arr[(int)(c3[0] - 'A')] = arr[(int)(c[0] - 'A')] - arr[(int)(c1[0] - 'A')];
     break;
    }
   case 6:
    {
     string c,c1;
     cout<<" First Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c;
     cout<<" Second Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c1;
     if(arr[(int)(c[0] - 'A')] == arr[(int)(c1[0] - 'A')]){
      cout<<" These sets Are equal";
     }else{
      cout<<" These sets Are not equal";
     }
     break;
    }
   case 7:
    {
     string c;
     cout<<" Complement Which Set(A,B,C,D,E,F,G,H,I,J) ? ";
     cin>>c;
     !arr[(int)(c[0] - 'A')];
     break;
    }
   case 8:
    {
     string c,c1;
     cout<<" First Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c;
     cout<<" Second Set : (A,B,C,D,E,F,G,H,I,J) ?: ";
     cin>>c1;
     if(arr[(int)(c[0] - 'A')] <= arr[(int)(c1[0] - 'A')]){
      cout<<" The first set is subset of second set";
     }else{
      cout<<" The first set is not a subset of second set";
     }
     break;
    }
   case 9:
    {
     string c;
     cout<<"Add Number To Which Set(A,B,C,D,E,F,G,H,I,J) ? ";
     cin>>c;
     cout<<arr[(int)(c[0] - 'A')];
    }
  }
  cin.clear();
  cin.get();
  cin.ignore();
}
}