面向对象技术C++平时作业(2)

2018-12-04 21:57

第2题.改进第一次作业中的IntSet,分别使用运算符+、*、-和<<表示集合并、集合交、

集合差和集合输出。(必须上机验证)

/* intset.h */ #ifndef INTSET_H #define INTSET_H class IntSet { }; #endif

/* intset.cpp */ #include \ #include #include using namespace std; #include \

IntSet::IntSet(int m) { if (m<1) exit(1); cursize=0; x=new int[maxsize=m]; } IntSet::~IntSet() { delete x; } IntSet::IntSet(const IntSet& m) { }

bool IntSet::member(int t) const {

int l=0; int u=cursize-1; while (l<=u) { }

return false;

int m=(u+l)/2; if (t

u=m-1; l=m+1; return true; else if (t>x[m]) else

cursize=m.cursize; x=new int[maxsize=m.maxsize]; for (int i=0;i

int cursize,maxsize; int *x; bool member(int t) const; IntSet(int m = 100);// 构造函数 IntSet(const IntSet&);// 拷贝构造函数 ~IntSet();//

析构函数

插入元素

集合差 集合并 集合交

void insert(int t);// public:

friend ostream& operator<<(ostream&,const IntSet&); IntSet operator-(const IntSet&);// IntSet operator+(const IntSet&);// IntSet operator*(const IntSet&);//

}

void IntSet::insert(int t) { }

ostream& operator<<(ostream& os, const IntSet& is) { }

IntSet IntSet::operator-(const IntSet& anotherset) { }

IntSet IntSet::operator+(const IntSet& anotherset) { }

IntSet IntSet::operator*(const IntSet& anotherset) {

IntSet r;

for (int i=0;i

if(anotherset.member(x[i]))

r.insert(x[i]);

IntSet r = anotherset; if(!anotherset.member(x[i]))

r.insert(x[i]);

for (int i=0;i

for (int i=0;i

if(!anotherset.member(x[i]))

r.insert(x[i]);

cout << \; if (is.cursize>0) { }

cout << \; return os;

for (int i=0;i

os <

os <<',';

if (member(t)) {return;} if (cursize>=maxsize) {exit(1);} x[cursize++]=t; for (int i=cursize-1;i>0;i--) {

if (x[i]

x[i-1]=temp; } else{ break;}}

return r;

return r;

return r;}


面向对象技术C++平时作业(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:CDMA路测中5个比较重要的参数

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: