main.cpp
来自「给出集合类的定义」· C++ 代码 · 共 86 行
CPP
86 行
//main.cpp实现主函数
#include"IntegerSet.h"
void main()
{
int num;
char goOn; //是否继续的标志
IntegerSet a1,a2,unionSet,intersectionSet;
//提示用户语
cout<<"The Infamous Integer Set Program."<<endl;
cout<<endl;
cout<<"Note: When entering numbers please seperate "<<endl;
cout<<" them with spaces."<<endl;
cout<<endl;
do
{
cout<<"Enter Set 1:";
do //接受元素
{
cin>>num;
a1.insertElement(num);
}while(cin.get()!='\n');
cout<<"Enter Set 2:";
do
{
cin>>num;
a2.insertElement(num);
}while(cin.get()!='\n');
cout<<"Set 1 is "<<a1<<endl; //打印集合
cout<<"Set 2 is "<<a2<<endl;
cout<<"Set 1 == Set 2:";
if(a1.isEqualTo(a2))
{
cout<<" true"<<endl;
}
else
cout<<" false"<<endl;
cout<<"Intersection of both sets is ";//交集运算
intersectionSet.intersectionOf(a1,a2);
cout<<intersectionSet;
cout<<endl;
cout<<"Union of both sets is ";//并集运算
unionSet.unionOf(a1,a2);
cout<<unionSet;
cout<<endl;
cout<<"Enter numbers to remove from Set 1:";//删除元素
do{
cin>>num;
a1.deleteElement(num);
}while(cin.get()!='\n');
cout<<"Enter numbers to insert into Set 2:";//插入元素
do{
cin>>num;
a2.insertElement(num);
}while(cin.get()!='\n');
cout<<"Set 1 is "<<a1<<endl;
cout<<"Set 2 is "<<a2<<endl;
cout<<"Set 1 == Set 2:";
if(a1.isEqualTo(a2))
{
cout<<" true"<<endl;
}
else
cout<<" false"<<endl;
cout<<"Intersection of both sets is ";
intersectionSet.intersectionOf(a1,a2);
cout<<intersectionSet;
cout<<endl;
cout<<"Union of both sets is ";
unionSet.unionOf(a1,a2);
cout<<unionSet;
cout<<endl;
cout<<"To try another couple of sets press 'y':";//是否继续
cin>>goOn;
}while(goOn=='y');
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?