⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 给出集合类的定义
💻 CPP
字号:
//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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -