integerset integerset::operator+(integerset &addedset){
integerset temp;
for(int index=0;index<=100;index++){
if(this->integer[index]==true||addedset.integer[index]==true)
temp.integer[index]=true;
else
temp.integer[index]=false;
}
return temp;
}
integerset integerset::operator-(integerset &subbedset){
integerset temp;
for(int index=0;index<=100;index++){
if(this->integer[index]==true&&subbedset.integer[index]==true)
temp.integer[index]=true;
else
temp.integer[index]=false;
}
return temp;
}
// file name: test.cpp
// assignment: integerset
// description: test of integerset class
#include <iostream>
#include "integerset.h"
using namespace std;
istream& operator >> (istream & cin, integerset& ia);
ostream& operator << (ostream & cout, integerset& ia);
//integer class's friend to cin and cout integerset
//cin and cout overload
int main(){
integerset intset1,intset2,clear;
//three ways to initialize in fact
//use default constructor
char flag='y';
//flag to decide whether want quit
do{
intset1.intersectionof(intset1,clear);
intset2.intersectionof(intset2,clear);
cout << "enter set1:";
cin >> intset1;
cout << "enter set2";
cin >> intset2;
cout << "set1 is:" << intset1;
cout << "set2 is:";
intset2.printset();
//two ways to output;
cout << "set1==set2:" << intset1.isequalto(intset2) << endl;
integerset temp;
//temp instance to hold the output of intersection and union
//temp.intersectionof(intset1,intset2);
cout << "intersection of both sets is" << intset1-intset2;
//temp.unionof(intset1,intset2);
cout << "union of both sets is " << intset1+intset2;
int index;
char ch;
//temp variable for input
cout << "enter numbers to remove from set 1:";
do{
cin >> index;
ch=cin.get();
if( index<=100&&index>=0 )
intset1.deleteelement(index);
}while( ch!='\n' );
//use int and ' ' format to input
//take enter as finish sign
cout << "enter numbers to insert into set 2:";
do{
cin >> index;
ch=cin.get();
if( index<=100&&index>=0 )
intset2.insertelement(index);
}while( ch!='\n' );
//use int and ' ' format to input
//take enter as finish sign
cout << "set1 is:"<<intset1;
cout << "set2 is:" << intset2;
cout << "set1==set2:" << intset1.isequalto(intset2) << endl;
temp.intersectionof(intset1,intset2);
cout << "intersection of both sets is" << temp;
temp.unionof(intset1,intset2);
cout << "union of both sets is " << temp;
cout << "another try?y/n:";
flag=cin.get();
}while(flag!='n');
return 0;
}
ostream& operator << ( ostream & cout, integerset& ia ){
cout << "{";
for( int index=0;index<=100;index++ ){
if( ia.integer[index]==true )
cout << index<< ',';
}
cout << '\b';
cout << "}" << endl;
return cout;
}
istream& operator >> ( istream & cin, integerset& ia ){
int index;
char ch;
cout << "input:";
do{
cin >> index;
ch=cin.get();
if( index<=100&&index>=0 )
ia.insertelement(index);
}while( ch!='\n' );
return cin;