求为什么?运行不完呢?
#pragma once#include"set.h"
#include<iostream>
using namespace std;
Set::Set()
{
set=new int[20];
size=0;
key=0;
}
void Set::AddSet(int n)
{
if(size<20)
{
set[size++]=n;
key=1;
}
else {cout<<"The Set is full!\n";}
}
void Set::DelSet(int n)
{
int d,m=0;
if(!key)
cout<<"The Set is empty!\n";
else
{
for(d=0;d<size;d++)
{
if(set[d]==n)
{
for( m=d;m<size;m++)
set[m]=set[m+1];
size--;
if(size==0)
key=0;
break;
}
}
if(!m)
{
cout<<"No,wrong number!Please do it again!\n";
}
}
}
void Set::OutSet()
{
int i;
for(i=0;i<size;i++)
cout<<set[i]<<" ";
cout<<endl;
}
int Set::Getsize()
{
return size;
}
int Set::Getnumber(int n)
{
return set[n];
}
Set::~Set()
{
delete[] set;
}
#include"string"
using namespace std;
class Set{
public:
Set();
void AddSet(int n);
void DelSet(int n);
void OutSet();
int Getnumber(int n);
int Getsize();
~Set();
private:
int *set;
int key;
int size;
};
#pragma once
#include"set.h"
#include<iostream>
#include<cstdlib>
using namespace std;
void Operates1(Set &s1,Set s2);
void Operates2(Set &s2,Set s1);
void Relation(Set s1,Set s2);
void Jiaoji(Set s1,Set s2);
void Bingji(Set s1,Set s2);
void Chaji(Set s1,Set s2);
void main()
{
Set s1,s2;
Operates1(s1,s2);
}
void Operates1(Set &s1,Set s2)
{
int i,m;
while(1)
{
cout<<"Make your choice: 1:AddSet 2:DelSet 3:OutSet 4:Operate s2 5:Relation 0:exit\n";
cin>>i;
switch(i)
{
case 1:cout<<"The number is:";cin>>m;s1.AddSet(m);break;
case 2:cout<<"The number is:";cin>>m;s1.DelSet(m);break;
case 3:cout<<"The Set is:";s1.OutSet();break;
case 4:Operates2(s2,s1);break;
case 5:Relation(s1,s2);break;
case 0:exit(0);
default:printf("No,the number is wrong!Please do it again!\n");
}
}
}
void Operates2(Set &s2,Set s1)
{
int i,m;
while(1)
{
cout<<"Make your choice: 1:AddSet 2:DelSet 3:OutSet 4:Operate s1 5:Relation 0:exit\n";
cin>>i;
switch(i)
{
case 1:cout<<"The number is:";cin>>m;s2.AddSet(m);break;
case 2:cout<<"The number is:";cin>>m;s2.DelSet(m);break;
case 3:cout<<"The Set is:";s2.OutSet();break;
case 4:Operates1(s1,s2);break;
case 5:Relation(s1,s2);break;
case 0:exit(0);
default:printf("No,the number is wrong!Please do it again!\n");
}
}
}
void Relation(Set s1,Set s2)
{
int i;
while(1)
{
cout<<"Make your choice: 1:Jiaoji 2:Bingji 3:Chaji 0:exit:";cin>>i;
switch(i)
{
case 1:Jiaoji(s1,s2);break;
case 2:Bingji(s1,s2);break;
case 3:Chaji(s1,s2);break;
case 0:exit(0);
default:printf("No,the number is wrong!Please do it again!\n");
}
}
}
void Jiaoji(Set s1,Set s2)
{
int m,n;
for(m=0;m<s1.Getsize();m++)
for(n=0;n<s2.Getsize();n++)
if(s1.Getnumber(m)==s2.Getnumber(n))
{
cout<<s1.Getnumber(m)<<" ";
break;
}
cout<<endl;
}
void Bingji(Set s1,Set s2)
{
int m,n,i=0,s;
int all[40],less[20];
for(m=0;m<s1.Getsize();m++)
for(n=0;n<s2.Getsize();n++)
if(s1.Getnumber(m)==s2.Getnumber(n))
less[i++]=s1.Getnumber(m);
for(m=0;m<s1.Getsize();m++)
all[m]=s1.Getnumber(m);
for(n=0;n<s2.Getsize();n++)
all[m+n]=s2.Getnumber(n);
s=s1.Getsize()+s2.Getsize();
//cout<<s;
for(m=0;m<s;m++)
for(n=0;n<i;n++)
{
if(all[m]==less[n])
break;
else
if(n==i-1)
cout<<all[m]<<" ";
}
for(m=0;m<i;m++)
cout<<less[m]<<" ";
cout<<endl;
}
void Chaji(Set s1,Set s2)
{
int m,n,i=0,s;
int all[40],less[20];
for(m=0;m<s1.Getsize();m++)
for(n=0;n<s2.Getsize();n++)
if(s1.Getnumber(m)==s2.Getnumber(n))
less[i++]=s1.Getnumber(m);
for(m=0;m<s1.Getsize();m++)
all[m]=s1.Getnumber(m);
for(n=0;n<s2.Getsize();n++)
all[m+n]=s2.Getnumber(n);
s=s1.Getsize()+s2.Getsize();
cout<<s;
for(m=0;m<s;m++)
for(n=0;n<i;n++)
{
if(all[m]==less[n])
break;
else
if(n==i-1)
cout<<all[m]<<" ";
}
for(m=0;m<i;m++)
cout<<less[m]<<" ";
cout<<endl;
}