啊 烦人的C++ 谁能帮我编个程序啊

来源:百度知道 编辑:UC知道 时间:2024/06/01 02:09:08
编个程序可以完成1~500内集合间的简单运算( 交,并,差)求某一个集合是否属于另 一个
集合

#include <bitset>
using namespace std;

class Set500
{
public:
bitset<500> set;
bool operator[](int i){return set[i];}
Set500 operator&(Set500& another); //交
Set500 operator|(Set500& another); //并
Set500 operator-(Set500& another); //差
bool operator>(Set500& another); //大于
}

Set500 Set500::operator&(Set500& another)
{
Set500 result;
for(int i=1;i<500;i++)
result.set(i,(*this)[i] && another[i]);
return result;
}

Set500 Set500::operator|(Set500& another)
{
Set500 result;
for(int i=1;i<500;i++)
result.set(i,(*this)[i] || another[i]);
return result;
}

Set500 Set500::operator-(Set500& another)
{
Set500 result;
for(int i=1;i<500;i++)
result.set(i,(*this)[i]?(*this)[i]&&another[i]: false);
return result;
}

bool Set500::operator>