精華區beta ck54th329 關於我們 聯絡資訊
#include <iostream> #include "IntegerSet.h" using std::cout; using std::cin; using std::endl; IntegerSet::IntegerSet(int n1,int n2,int n3,int n4,int n5){ int i; for(i=0;i<=100;i++) ////清空數列 a[i]=0; if(n1>=0 && n1<=100) a[n1]=1; if(n2>=0 && n2<=100) a[n2]=1; if(n3>=0 && n3<=100) a[n3]=1; if(n4>=0 && n4<=100) a[n4]=1; if(n5>=0 && n5<=100) a[n5]=1; } void IntegerSet::unionOfIntegerSets(IntegerSet set1,IntegerSet set2){ for(int i=0;i<=100;i++){ if(set1.a[i]==1 || set2.a[i]==1) a[i]=1; //兩數列之聯集 else a[i]=0; } } void IntegerSet::intersectionOfIntegerSets(IntegerSet set1,IntegerSet set2){ for(int i=0;i<=100;i++){ if(set1.a[i]==1 && set2.a[i]==1) a[i]=1; //兩數列之交集 else a[i]=0; } } void IntegerSet::insertElement(int num){ if(a[num]==1) cout << num << " already in this set" << endl; a[num]=1; } void IntegerSet::deletElement(int num){ if(a[num]==0) cout << num << " is not in this set yet" << endl; a[num]=0; } void IntegerSet::setPrint(){ bool empty=true; //判斷是否為空集合的變數 for(int i=0;i<=100;i++) if(a[i]==1){ cout << i << " " ; empty=false; //若含一數即非空集合 } if(empty) cout << "---" ; cout << endl; } bool IntegerSet::isEqualTo(IntegerSet set1,IntegerSet set2) { for(int i=0;i<=100;i++) if(set1.a[i] != set2.a[i]) return false; return true; } -- ※ 發信站: 批踢踢實業坊(ptt.csie.ntu.edu.tw) ◆ From: 61.70.219.17