void
set::get()
{
int n;
cin>>n;
int i;
cin.get();
for(i=0;i<n;i++)
{
cin.getline(names[i],20);
}
names[i][0]='\0';
}
void set::print() const
{
int i=0;
while(names[i][0]!='\0')
{
if(i==0)
cout<<names[i];
else
cout<<","<<names[i];
i++;
}
cout<<endl;
}
set set::difference(set& a)
{
set diff;
int i=0;
int p=0;
while(names[i][0]!='\0')
{
int j=0;
int c=0;
while(a.names[j][0]!='\0')
{
if(strcmp(names[i],a.names[j])==0)
{
c=1;
break;
}
j++;
}
if(c!=1)
{
strcpy(diff.names[p],names[i]);
p++;
}
i++;
}
diff.names[p][0]='\0';
return diff;
}
set set::intersection(set& a)
{
set diff;
int i=0;
int p=0;
while(names[i][0]!='\0')
{
int j=0;
int c=0;
while(a.names[j][0]!='\0')
{
if(strcmp(names[i],a.names[j])==0)
{
c=1;
break;
}
j++;
}
if(c==1)
{
strcpy(diff.names[p],names[i]);
p++;
}
i++;
}
diff.names[p][0]='\0';
return diff;
}
{
int n;
cin>>n;
int i;
cin.get();
for(i=0;i<n;i++)
{
cin.getline(names[i],20);
}
names[i][0]='\0';
}
void set::print() const
{
int i=0;
while(names[i][0]!='\0')
{
if(i==0)
cout<<names[i];
else
cout<<","<<names[i];
i++;
}
cout<<endl;
}
set set::difference(set& a)
{
set diff;
int i=0;
int p=0;
while(names[i][0]!='\0')
{
int j=0;
int c=0;
while(a.names[j][0]!='\0')
{
if(strcmp(names[i],a.names[j])==0)
{
c=1;
break;
}
j++;
}
if(c!=1)
{
strcpy(diff.names[p],names[i]);
p++;
}
i++;
}
diff.names[p][0]='\0';
return diff;
}
set set::intersection(set& a)
{
set diff;
int i=0;
int p=0;
while(names[i][0]!='\0')
{
int j=0;
int c=0;
while(a.names[j][0]!='\0')
{
if(strcmp(names[i],a.names[j])==0)
{
c=1;
break;
}
j++;
}
if(c==1)
{
strcpy(diff.names[p],names[i]);
p++;
}
i++;
}
diff.names[p][0]='\0';
return diff;
}
No comments:
Post a Comment