差集函数不输出怎么改
#include<iostream>
#include<cstring>
using namespace std;
class SET{
private:
int allnum[100];
int length;
public:
SET(){
this->length=0;
memset(this->allnum,0,sizeof(allnum));
cout<<"Default constructo"<<endl;
}
SET(int n){
cout<<"Ordinary constructor"<<endl;
}
SET(SET &s){
cout<<"Copy constructor"<<endl;
}
~SET(){
cout<<"Destruct the constructor"<<endl;
}
void getnum(){
char ch='y';
cout<<"Enter the elements of the collection"<<endl;
while(ch!='\n'){
cin>>allnum[length];
ch=getchar();
length++;
}
cout<<"Input completed"<<endl;
}
void shownum(){
cout<<"Prints all the elements in the array"<<endl;
for(int i=0;i<length;i++){
cout<<allnum[i]<<" ";
}
cout<<endl<<"Complete the output"<<endl;
}
void addnum(int num){
int flag=0;
for(int i=0;i<length;i++){
if(allnum[i]==num){
flag=1;
break;
}
}
if(flag==0){
allnum[length]=num;
length++;
}
}
void delnum(int num){
int n,flag=0;
for(n=0;n<length;n++){
if(allnum[n]==num){
flag=1;
break;
}
}
if(flag==1){
for(int i=n;i<length-1;i++){
allnum[i]=allnum[i+1];
}
length--;
}
else{
cout<<"There is no element"<<endl;
}
}
SET bingji(SET &s2){
SET s;
for(int i=0;i<this->length;i++){
s.allnum[i]=this->allnum[i];
s.length=this->length;
}
for(int i=0;i<s2.length;i++){
s.addnum(s2.allnum[i]);
}
return s;
}
SET jiaoji(SET &s2){
SET s;
for(int i=0;i<this->length;i++){
for(int j=0;j<s2.length;j++){
if(this->allnum[i]==s2.allnum[j]){
s.allnum[s.length]==s2.allnum[j];
s.length++;
}
}
}
return s;
}
SET chaji(SET &s2)
{
int flag=0;
SET s,s1;
s1=this->bingji(s2);
for(int i=0;i<this->length;i++)
{
flag=0;
for(int j=0;j<s1.length;j++)
{
if(this->allnum[i]==s1.allnum[j])
{
flag=1;
break;
}
}
if(flag==0){
s.allnum[s.length]=this->allnum[i];
s.length++;
}
}
return s;
}
};
int main()
{
SET s1,s2,s3;
SET s;
int num;
cout<<"1.创建集合及集合的初始化"<<endl;
s1.getnum();
s2.getnum();
s3.getnum();
cout<<"4.显示set中的所有元素"<<endl;
s1.shownum();
s2.shownum();
s3.shownum();
cout<<endl;
cout<<"2.向集合s1中添加一个元素"<<endl;
cout<<"Enter an integer to add"<<endl;
cin>>num;
s1.addnum(num);
s1.shownum();
cout<<"3.从集合s3中删除一个元素"<<endl;
cout<<"Enter an integer to add"<<endl;
cin>>num;
s3.delnum(num);
s3.shownum();
cout<<"5.计算s1和s2的交集"<<endl;
s=s1.jiaoji(s2);
s.shownum();
cout<<"6.计算s1和s2的并集"<<endl;
s=s1.bingji(s2);
s.shownum();
cout<<"7.计算s1和s2的差集"<<endl;
s=s1.chaji(s2);
s.shownum();
}