All pastes #1964759 Raw Edit

Someone

public cpp v1 · immutable
#1964759 ·published 2010-10-17 11:21 UTC
rendered paste body
#include <iostream>using namespace std;class Intset {	private:		unsigned int * sp; // set pointer		unsigned int set_size;	public:		static unsigned int SetLim;		Intset() { sp=new unsigned int [SetLim]; set_size=0;}		Intset(Intset& a);		Intset(unsigned int* a);		~Intset() {delete [] sp;}		int size() { return set_size; }		bool member(unsigned int a);		int insert(int a);		int item(int ind);		friend ostream& operator <<(ostream& f, Intset& set);		friend istream& operator >>(istream& f, Intset& set);		friend Intset& operator +(Intset &a,Intset &b);		friend Intset& operator *(Intset &a,Intset &b);};unsigned int Intset::SetLim;Intset::Intset(Intset &a) {	for(int i=0;i<a.size();i++)		sp[i]=a.sp[i];}Intset::Intset(unsigned int* a) {	for(set_size=0;a[set_size];set_size++);	sp=new unsigned int [set_size];	for(int i=0;i<set_size;i++)		sp[i]=a[i];}ostream& operator <<(ostream& f,Intset& set) {	f << "[";	for(int i=0;i<set.size();i++)		f << set.item(i) << ",";		f << ((set.size()) ? "\b]" : "]") << endl;	return f;}istream& operator >>(istream &f, Intset& set) {	int a,b,ec(1);	cout << "How many elements should be added? ";	f >> b;	if(b==0)		return f;	else if(b<0)		b=Intset::SetLim;	cout << "Populating set:\n";	do {		switch(ec) {			case 1:				b--;				break;			case 0:				cout << "\tThe set's full! The last number(" << a << ") is not added.\n";				return f;			case -1:				cout << "\tThe number you entered is negative!\n";				break;			case -2:				cout << "\tThe set already contains this number.\n";				break;		}		cout << "\t>>> ";		f >> a;	}while((ec=set.insert(a)) && b);	return f;}bool Intset::member(unsigned int a) {	for(int i=0;i<set_size;i++)		if(sp[i]==a) return true;	return false;}int Intset::insert(int a) {	if(a<0)		return -1;	if(set_size >= SetLim)		return 0;	for(int i=0;i<set_size;i++)		if(sp[i]==a)			return -2;	sp[set_size++]=a;	return 1;}int Intset::item(int ind) {	if(ind<set_size && ind>=0)		return sp[ind];	return -1;}Intset& operator +(Intset &a,Intset &b) {	Intset* asd=new Intset();	for(int i=0;i<a.size();i++)		asd->insert(a.sp[i]);	for(int i=0;i<b.size();i++)		asd->insert(b.sp[i]);	return *asd;}Intset& operator *(Intset &a,Intset &b) {	Intset* asd=new Intset();	for(int i=0;i<a.size();i++)		if(b.member(a.sp[i]))			asd->insert(a.sp[i]);	return *asd;}main() {	int a;	do {		cout << "Set set size: ";		cin >> a;	}while(a<1);	Intset::SetLim=a;	Intset b,c;	cin >> b;	cout << b;	cin >> c;	cout << c;	cout << (b+c) << "\t" << (b*c);	return 0;}