All pastes #1964137 Raw Edit

Untitled

public cpp v1 · immutable
#1964137 ·published 2010-10-16 17:09 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() {delete [] sp;}		//Intset() {}		//Intset() {}		friend ostream& operator <<(ostream& f, Intset& set);		friend istream& operator >>(istream& f, Intset& set);		int size() { return set_size; }		bool member(unsigned int a);		int insert(int a);		int item(int ind);};unsigned int Intset::SetLim;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;	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 {		cout << "\t>>> ";		f >> a;	}while(set.insert(a)!=-1 && --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) {		cout << "The number you entered is negative!\n";		return 0;	}	if(set_size >= SetLim) {		cout << "The set's full! The last number(" << a << ") is not added.\n";		return -1;	}	for(int i=0;i<set_size;i++)		if(sp[i]==a) {			cout << "The set already contains this number.\n";			return 0;		}	sp[set_size++]=a;	return 1;}int Intset::item(int ind) {	if(ind<set_size && ind>=0)		return sp[ind];	return -1;}main() {	int a;	do {		cout << "Set set size: ";		cin >> a;	}while(a<1);	Intset::SetLim=a;	Intset b,c;	cin >> b;	cout << b;	cout << b.member(6) << "\t" << b.member(100) << "\t" << b.item(1) << "\t" << b.item(7) << "\t" << b.item(20);	return 0;}