GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Jul-2005, 18:52
Krandygrl00 Krandygrl00 is offline
Junior Member
 
Join Date: May 2005
Location: chicago, il
Posts: 39
Krandygrl00 is on a distinguished road

so sick of this stupid program HELP!


CPP / C++ / C Code:
#ifndef MYSET_H
#define MYSET_H

#include <iostream>
#include <set>
#include <list>
#include <cmath>
#include <iterator>
#include <algorithm>
#include <iomanip>
using namespace std;

template <typename Type>
class MySet : public set<typename Type>
{
	private:
		int count;										//counts numbers
	public:
		int userarr1[10];								//Max1 of numbers in a set
		int userarr2[10]; 								//Max2 of numbers in a set
		MySet();										//default constructor								
		int cardinality()const;							//returns the number of items in the set
		void PrintElements()const;						//prints, in order from least to greatest all elements in the set
		void AddElements(Type newElement);				//adds element to set if it is not already contained in the set
		bool isSubset(MySet<Type> B);					//returns true if setA is subset of set B when called on an object of set A
		Type Intersect(MySet<Type> B);					//returns the intersection of set A and set B when called on an object of set A
		Type Union(MySet<Type> B);						//returns the union of set A and set B when called on an object of setA
		const MySet<Type>& operator= (const MySet<Type>&);
protected:
	set<typename Type>set1;
};
#endif
ostream_iterator<int>screen(cout, " ");
//-----------------------------------------------------------------------
template <typename Type>
MySet<Type>::MySet()
{
	int count = 0;								//empty set
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
void MySet<typename Type>::PrintElements()const
{
	MySet<Type>::iterator intSet;

	for(intSet = set1.begin(); intSet != set1.end(); intSet++)
	{
		cout << *intSet << endl;
	}
	cout << endl;
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
void MySet<Type>::AddElements(Type newElement) 
{
	set1.insert(newElement);
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
int MySet<Type>::cardinality()const
{
	return set1.size();
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
bool MySet<Type>::isSubset(MySet<Type> B)
{
	MySet<Type> A;

	bool found = includes(B.begin(), B.end(), A.begin(), A.end());
	
	if (found) 
	{
        return true;
    }
	else
		false;
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
Type MySet<Type>::Intersect(MySet<Type> B)
{
	MySet<Type> A, temp;
	set<Type> iterator i, endIter;

	sort(A.begin(), A.end());					//sort elements
    sort(B.begin(), B.end());

	endIter = set_intersection(B.begin(), B.end(), A.begin(), A.end(), temp.begin());
	temp.erase(endIter, temp.end());

    for (i = temp.begin(); i != temp.end(); i++) 
	//{
       // cout << *i << " ";
	//}
	return *i;
} 
/////////////////////////////////////////////////////////////////////////
template <typename Type>
Type MySet<Type>::Union(MySet<Type> B)
{
	MySet<Type> A, temp;
	set<Type> iterator i, endIter;

	sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    endIter = set_union(A.begin(), A.end(), B.begin(), B.end(), temp.begin());
    temp.erase(endIter, temp.end());

	for (i = temp.begin(); i != temp.end(); i++) 
	{
        cout << *i << " ";
	}
	return endIter;
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
const MySet<Type>& MySet<Type>::operator= (const MySet<Type>& otherList)
{ 
	if(this != &otherList)						//avoid self-copy
		copyList(otherList);

	return *this; 
}
///////////////////////////////////////////////////////////////////////////
int main()
{
	typedef MySet<int> MySet1;
	MySet1 setA, setB, setC;
	int user[10] = {};
	int user1[10] = {};

	cout << "Please Enter The ELEMENTS of A: ";
	setA.userarr1;
	cin >> user;
	cout << endl;
	cout << "Please Enter The ELEMENTS of B: ";
	cin >> user1;
	setB.userarr1;
	cout << endl;

	cout << "Set A contains: ";					//Printing out Sets
	setA.PrintElements();
	cout << endl;
	cout << "Set B contains: ";
	setB.PrintElements();
	cout << endl;
	cout << endl;
	
	setA.AddElements(9);
	cout << "Set A has a cardinality: ";		//cardinality
	setA.cardinality();
	cout << endl;
	cout << "Set B has a cardinality: ";
	setB.cardinality();
	cout << endl;
	cout << endl;

	cout << "A is a subset of B: ";				//subsets true or false
	setA.isSubset(setB);
	cout << endl;
	cout << "B is a subset of A: ";
	setB.isSubset(setA);
	cout << endl;
	cout << endl;

	cout << "The intersection of A and B is: ";	//intersect and union
	setA.Intersect(setB);
	setC.PrintElements();
	cout << endl;
	cout << "The union of A and B is: ";
	setC = setA.Union(setB);
	setC.PrintElements();
	cout << endl;
	cout << endl;

	cout << "TEST CASES..." << endl;
	cout << endl;

	cout << "Test Case 1:" << endl;				//adding elements
	cout << "Adding elements 1, 2, 3, 4, 5 to A..." << endl;
	setA.AddElements(1);
	setA.AddElements(2);
	setA.AddElements(3);
	setA.AddElements(4);
	setA.AddElements(5);
	cout << "Set A:" << endl;
	setA.PrintElements();
	cout << endl;
	cout << "Adding elements 1, 2, 3, 4, 5, 6 to B..." << endl;
	setA.AddElements(1);
	setA.AddElements(2);
	setA.AddElements(3);
	setA.AddElements(4);
	setA.AddElements(5);
	setA.AddElements(6);
	cout << "Set B: " << endl;
	setB.PrintElements();
	cout << endl;
	cout << endl;

	cout << "Test Case 2:" << endl;				//adding elements
	cout << "Adding elements 2, 3, 6 to A..." << endl;
	setA.AddElements(2);
	setA.AddElements(3);
	setA.AddElements(6);
	cout << "Set A:" << endl;
	setA.PrintElements();
	cout << endl;
	cout << "Adding elements 1, 3, 5 to B..." << endl;
	setA.AddElements(1);
	setA.AddElements(3);
	setA.AddElements(5);
	cout << endl;
	cout << endl;
	cout << "Set B: " << endl;
	setB.PrintElements();
	cout << endl;

	cout << "Test Case 3:" << endl;			
	cout << "Set A has a cardinality: ";	     //cardinality
	setA.cardinality();
	setA.PrintElements();
	cout << endl;
	cout << "Set B has a cardinality: ";
	setA.cardinality();
	setA.PrintElements();
	cout << endl;
	cout << endl;

	cout << "A is a subset of B: ";				//subsets true or false
	setA.isSubset(setB);
	cout << endl;
	cout << "B is a subset of A: ";
	setB.isSubset(setA);
	cout << endl;
	cout << endl;

	cout << "Test Case 5:" << endl;			
	cout << "The intersection of A and B is: ";	//intersect and union
	setC = setA.Intersect(setB);
	setC.PrintElements();
	cout << endl;
	cout << "The union of A and B is: ";
	setC = setA.Union(setB);
	setC.PrintElements();
	cout << endl;
	cout << endl;

	return 0;
}

///////////////*********************************//////////////

okay theres my code....I HAVE ERRORS about my = and << operators I tried to overload them but it still gave me errors. ANOTHER thing is how are use supposet to call in arrays from the user and store them did I declare them right? And also, MySet and set are they being declared correctly in my functions cuz I dont know where the hell anything is being stored Im sooo confused about this cuz I dont know where things are being stored in myset or set HELP me please thank u thank u thank u =)
Last edited by LuciWiz : 02-Jul-2005 at 00:49. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 01-Jul-2005, 21:21
Krandygrl00 Krandygrl00 is offline
Junior Member
 
Join Date: May 2005
Location: chicago, il
Posts: 39
Krandygrl00 is on a distinguished road
CPP / C++ / C Code:
//Kandice Golar
//Anderson Assignment 5
//Due 06-27-05
#ifndef MYSET_H
#define MYSET_H

#include <iostream>
#include <set>
#include <list>
#include <cmath>
#include <iterator>
#include <algorithm>
using namespace std;

template <typename Type>
class MySet : public set<Type>
{
	private:
		int count;										//counts numbers
	public:
		void fillArray();								//Max1 of numbers in a set
		MySet();										//default constructor								
		int cardinality()const;							//returns the number of items in the set
		void PrintElements()const;						//prints, in order from least to greatest all elements in the set
		void AddElements(Type newElement);				//adds element to set if it is not already contained in the set
		bool isSubset(MySet<Type> B);					//returns true if setA is subset of set B when called on an object of set A
		Type Intersect(MySet<Type> B);					//returns the intersection of set A and set B when called on an object of set A
		Type Union(MySet<Type> B);						//returns the union of set A and set B when called on an object of setA
		const MySet<Type>& operator= (const MySet<Type>&);
protected:
	set<typename Type>set;
};
#endif
//-----------------------------------------------------------------------
template<typename Type>
void MySet<typename Type>::fillArray()
{
	int userarr[10];

	cout << "Please Enter The ELEMENTS: ";
	for (int i=0; i<=9; i++)
	{
		userarr[i] = i;
	}
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
MySet<Type>::MySet()
{
	int count = 0;								//empty set
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
void MySet<typename Type>::PrintElements()const
{
	int i;

	for(i = 0; i <= 10; i++)
		cout << set[i] << " ";
	cout << endl;
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
void MySet<Type>::AddElements(Type newElement) 
{
	set.insert(newElement);
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
int MySet<Type>::cardinality()const
{
	return set.size();
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
bool MySet<Type>::isSubset(MySet<Type> B)
{
	MySet<Type> A;

	bool found = includes(B.begin(), B.end(), A.begin(), A.end());
	
	if (found) 
	{
        return true;
    }
	else
		false;
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
Type MySet<Type>::Intersect(MySet<Type> B)
{
	MySet<Type> A, temp;
	MySet<Type>::iterator intSet, endIter;

	sort(A.begin(), A.end());					//sort elements
    sort(B.begin(), B.end());

	endIter = set_intersection(B.begin(), B.end(), A.begin(), A.end(), temp.begin());
	temp.erase(endIter, temp.end());

    for (intSet = temp.begin(); intSet != temp.end(); intSet++) 
	{
       cout << *intSet << " ";
	}
} 
/////////////////////////////////////////////////////////////////////////
template <typename Type>
Type MySet<Type>::Union(MySet<Type> B)
{
	MySet<Type> A, temp;
	MySet<Type>::iterator intSet, endIter;

	sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    endIter = set_union(A.begin(), A.end(), B.begin(), B.end(), temp.begin());
    temp.erase(endIter, temp.end());

	for (intSet = temp.begin(); intSet != temp.end(); intSet++) 
	{
        cout << *intSet << " ";
	}
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
const MySet<Type>& MySet<Type>::operator= (const MySet<Type>& otherList)
{ 
	if(this != &otherList)						//avoid self-copy
		copyList(otherList);

	return *this; 
}
///////////////////////////////////////////////////////////////////////////
int main()
{
	typedef MySet<int> set;
	set setA, setB, setC;

	setA.fillArray();
	cout << endl;
	setB.fillArray();
	cout << endl;

	cout << "Set A contains: ";					//Printing out Sets
	setA.PrintElements();
	cout << endl;
	cout << "Set B contains: ";
	setB.PrintElements();
	cout << endl;
	cout << endl;
	
	setA.AddElements(9);
	cout << "Set A has a cardinality: ";		//cardinality
	setA.cardinality();
	cout << endl;
	cout << "Set B has a cardinality: ";
	setB.cardinality();
	cout << endl;
	cout << endl;

	cout << "A is a subset of B: ";				//subsets true or false
	setA.isSubset(setB);
	cout << endl;
	cout << "B is a subset of A: ";
	setB.isSubset(setA);
	cout << endl;
	cout << endl;

	cout << "The intersection of A and B is: ";	//intersect and union
	setA.Intersect(setB);
	setC.PrintElements();
	cout << endl;
	cout << "The union of A and B is: ";
	setA.Union(setB);
	setC.PrintElements();
	cout << endl;
	cout << endl;

	cout << "TEST CASES..." << endl;
	cout << endl;

	cout << "Test Case 1:" << endl;				//adding elements
	cout << "Adding elements 1, 2, 3, 4, 5 to A..." << endl;
	setA.AddElements(1);
	setA.AddElements(2);
	setA.AddElements(3);
	setA.AddElements(4);
	setA.AddElements(5);
	cout << "Set A:" << endl;
	setA.PrintElements();
	cout << endl;
	cout << "Adding elements 1, 2, 3, 4, 5, 6 to B..." << endl;
	setA.AddElements(1);
	setA.AddElements(2);
	setA.AddElements(3);
	setA.AddElements(4);
	setA.AddElements(5);
	setA.AddElements(6);
	cout << "Set B: " << endl;
	setB.PrintElements();
	cout << endl;
	cout << endl;

	cout << "Test Case 2:" << endl;				//adding elements
	cout << "Adding elements 2, 3, 6 to A..." << endl;
	setA.AddElements(2);
	setA.AddElements(3);
	setA.AddElements(6);
	cout << "Set A:" << endl;
	setA.PrintElements();
	cout << endl;
	cout << "Adding elements 1, 3, 5 to B..." << endl;
	setA.AddElements(1);
	setA.AddElements(3);
	setA.AddElements(5);
	cout << endl;
	cout << endl;
	cout << "Set B: " << endl;
	setB.PrintElements();
	cout << endl;

	cout << "Test Case 3:" << endl;			
	cout << "Set A has a cardinality: ";	     //cardinality
	setA.cardinality();
	setA.PrintElements();
	cout << endl;
	cout << "Set B has a cardinality: ";
	setA.cardinality();
	setA.PrintElements();
	cout << endl;
	cout << endl;

	cout << "A is a subset of B: ";				//subsets true or false
	setA.isSubset(setB);
	cout << endl;
	cout << "B is a subset of A: ";
	setB.isSubset(setA);
	cout << endl;
	cout << endl;

	cout << "Test Case 5:" << endl;			
	cout << "The intersection of A and B is: ";	//intersect and union
	setA.Intersect(setB);
	setC.PrintElements();
	cout << endl;
	cout << "The union of A and B is: ";
	setA.Union(setB);
	setC.PrintElements();
	cout << endl;
	cout << endl;

	return 0;
}


can sum1 help me with these two errors??? Please

1)error C2676: binary '[' : 'const std::set<_Kty>' does not define this operator or a conversion to a type acceptable to the predefined operator

2)warning C4267: 'return' : conversion from 'size_t' to 'int', possible loss of data
Last edited by LuciWiz : 02-Jul-2005 at 00:50. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #3  
Old 02-Jul-2005, 00:06
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
After 17 posts it seems someone by now would have mentioned the "Guidelines for posting requests for help" thread. I know it's hard to find, but not that hard...

I see LuciWiz has mentioned 8 times about using code tags. And every message he posts mentions the guidelines. maprich and QED specifically mentioned them to you.
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #4  
Old 02-Jul-2005, 06:12
maprich maprich is offline
Member
 
Join Date: May 2005
Posts: 163
maprich has a spectacular aura aboutmaprich has a spectacular aura about
Krandygrl00, like QED mentioned earlier, your class MySet inherits the class set and therefore you shouldn't make a protected set member in your class. Btw. no need for frustration. Take it easy - according to an old chinese saying: every 1000 mile journey starts with a single step.

So first clean your class definition. Currently you have:
Quote:
Originally Posted by Krandygrl00
CPP / C++ / C Code:
template <typename Type>
class MySet : public set<Type>
{
  private:
    int count;                    //counts numbers
  public:
    void fillArray();                 //Max1 of numbers in a set
    MySet();                    //default constructor                
    int cardinality()const;              //returns the number of items in the set
    void PrintElements()const;            //prints, in order from least to greatest all elements in the set
    void AddElements(Type newElement);        //adds element to set if it is not already contained in the set
    bool isSubset(MySet<Type> B);          //returns true if setA is subset of set B when called on an object of set A
    Type Intersect(MySet<Type> B);          //returns the intersection of set A and set B when called on an object of set A
    Type Union(MySet<Type> B);            //returns the union of set A and set B when called on an object of setA
    const MySet<Type>& operator= (const MySet<Type>&);
protected:
  set<typename Type>set;
};
After cleanup it becomes like :
CPP / C++ / C Code:
template <typename Type>
class MySet : public set<Type>
{
  public:
    MySet();                    //constructor  
    ~MySet();                  //destructor

    void fillArray();                //put 10 elements to the set             
    int cardinality()const;              //returns the number of items in the set
    void PrintElements()const;            //prints, in order from least to greatest all elements in the set
    void AddElements(Type newElement);        //adds element to set if it is not already contained in the set
    bool isSubset(MySet<Type> B);          //returns true if setA is subset of set B when called on an object of set A
    MySet<Type> Intersect(const MySet<Type> B);          //returns the intersection of set A and set B when called on an object of set A
    MySet<Type> Union(const MySet<Type> B);            //returns the union of set A and set B when called on an object of setA
    const MySet<Type>& operator= (const MySet<Type>&);
};
Deleted "int count" as useless because template class 'set' has already a member function size() that you can call instead. Also good programming practice to write the class destructor even if you didn't need it. Then notice that I changed the return type values of Intersect and Union functions. Reason should be self-evident.

Here further suggestions for you:
CPP / C++ / C Code:
template<typename Type>
void MySet<typename Type>::fillArray()
{
  Type value;

  cout << "Please Enter The ELEMENTS: ";
  for (int i=0; i<=9; i++)
  {
    cin >> value;
    this->insert( value );
  }
}
/////////////////////////////
template <typename Type>
void MySet<Type>::AddElements(Type newElement) 
{
  this->insert(newElement);
}
Figure out and rewrite the rest of the functions in the class. Then you should have a working program.
Last edited by maprich : 02-Jul-2005 at 06:16. Reason: typo
  #5  
Old 06-Jul-2005, 12:58
Krandygrl00 Krandygrl00 is offline
Junior Member
 
Join Date: May 2005
Location: chicago, il
Posts: 39
Krandygrl00 is on a distinguished road
CPP / C++ / C Code:

//Kandice Golar
//Anderson Assignment 5
//Due 06-27-05
#ifndef MYSET_H
#define MYSET_H

#include <iostream>
#include <set>
#include <list>
#include <cmath>
#include <iterator>
#include <algorithm>
using namespace std;

template <typename Type>
class MySet : public set<Type>
{
public:
	MySet();												 //constructor  
    ~MySet();												 //destructor
	void fillArray();										 //put 10 elements to the set             
    int cardinality()const;									 //returns the number of items in the set
    void PrintElements()const;								 //prints, in order from least to greatest all elements in the set
    void AddElements(Type newElement);						 //adds element to set if it is not already contained in the set
    bool isSubset(MySet<Type> B);							 //returns true if setA is subset of set B when called on an object of set A
    MySet<Type> Intersect(const MySet<Type> B);				 //returns the intersection of set A and set B when called on an object of set A
    MySet<Type> Union(const MySet<Type> B);					 //returns the union of set A and set B when called on an object of setA
    const MySet<Type>& operator= (const MySet<Type>&);
};
#endif
//-----------------------------------------------------------------------
template <typename Type>
MySet<Type>::MySet()
{
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
MySet<Type>::~MySet()
{
}
/////////////////////////////////////////////////////////////////////////
template<typename Type>
void MySet<typename Type>::fillArray()
{
  Type value;

  cout << "Please Enter The ELEMENTS: ";
  for (int i=0; i<=9; i++)
  {
    cin >> value;
    this->insert(value);
  }
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
void MySet<typename Type>::PrintElements() const
{
    MySet<Type>::iterator intSet;

    for( this->begin(); intSet != this->end(); ++intSet)
    {
        cout << *intSet << endl;
    }
    cout << endl;
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
void MySet<Type>::AddElements(Type newElement)
{
    this->insert(newElement);
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
int MySet<Type>::cardinality()const
{
	return (unsigned int)MySet::size();
}
/////////////////////////////////////////////////////////////////////////
template <typename Type>
bool MySet<Type>::isSubset(MySet<Type> B)
{
	MySet<Type> A;

	bool found = includes(B.begin(), B.end(), A.begin(), A.end());
	
	if(found) 
	{
        cout << "is subset";
    }
	else
		cout << "is not subset";
	return 0;
}
/////////////////////////////////////////////////////////////////////////
/*template <typename Type>
const MySet<Type>::Intersect(const MySet<Type> B)
{
	MySet<Type> A, temp;
	MySet<Type>::iterator intSet, endIter;

	endIter = set_intersection(B.begin(), B.end(), A.begin(), A.end(), temp.begin());
	temp.erase(endIter, temp.end());

    for (intSet = temp.begin(); intSet != temp.end(); intSet++) 
	{
       cout << *intSet << " ";
	}
	return 0;
} 
/////////////////////////////////////////////////////////////////////////
template <typename Type>
MySet<Type>::Union(const MySet<Type> B)
{
	MySet<Type> A, temp;
	MySet<Type>::iterator intSet, endIter;
	
	endIter = set_union(A.begin(), A.end(), B.begin(), B.end(), temp.begin());
    temp.erase(endIter, temp.end());

	for (intSet = temp.begin(); intSet != temp.end(); intSet++) 
	{
        cout << *intSet << " ";
	}
	return 0;
}*/
/////////////////////////////////////////////////////////////////////////
template <typename Type>
const MySet<Type>& MySet<Type>::operator= (const MySet<Type>& otherList)
{ 
	if(this != &otherList)						//avoid self-copy
		copyList(otherList);

	return *this; 
}
///////////////////////////////////////////////////////////////////////////
int main()
{
	typedef MySet<int> set;
	set setA, setB, setC;

	setA.fillArray();
	cout << endl;
	setB.fillArray();
	cout << endl;

	cout << "Set A contains: ";					//Printing out Sets
	setA.PrintElements();
	cout << endl;
	cout << "Set B contains: ";
	setB.PrintElements();
	cout << endl;
	cout << endl;
	
	setA.AddElements(9);
	cout << "Set A has a cardinality: ";		//cardinality
	setA.cardinality();
	cout << endl;
	cout << "Set B has a cardinality: ";
	setB.cardinality();
	cout << endl;
	cout << endl;

	cout << "A is a subset of B: ";				//subsets true or false
	setA.isSubset(setB);
	cout << endl;
	cout << "B is a subset of A: ";
	setB.isSubset(setA);
	cout << endl;
	cout << endl;

	cout << "The intersection of A and B is: ";	//intersect and union
	//setA.Intersect(setB);
	setC.PrintElements();
	cout << endl;
	cout << "The union of A and B is: ";
	//setA.Union(setB);
	setC.PrintElements();
	cout << endl;
	cout << endl;

	cout << "TEST CASES..." << endl;
	cout << endl;

	cout << "Test Case 1:" << endl;				//adding elements
	cout << "Adding elements 1, 2, 3, 4, 5 to A..." << endl;
	setA.AddElements(1);
	setA.AddElements(2);
	setA.AddElements(3);
	setA.AddElements(4);
	setA.AddElements(5);
	cout << "Set A:" << endl;
	setA.PrintElements();
	cout << endl;
	cout << "Adding elements 1, 2, 3, 4, 5, 6 to B..." << endl;
	setA.AddElements(1);
	setA.AddElements(2);
	setA.AddElements(3);
	setA.AddElements(4);
	setA.AddElements(5);
	setA.AddElements(6);
	cout << "Set B: " << endl;
	setB.PrintElements();
	cout << endl;
	cout << endl;

	cout << "Test Case 2:" << endl;				//adding elements
	cout << "Adding elements 2, 3, 6 to A..." << endl;
	setA.AddElements(2);
	setA.AddElements(3);
	setA.AddElements(6);
	cout << "Set A:" << endl;
	setA.PrintElements();
	cout << endl;
	cout << "Adding elements 1, 3, 5 to B..." << endl;
	setA.AddElements(1);
	setA.AddElements(3);
	setA.AddElements(5);
	cout << endl;
	cout << endl;
	cout << "Set B: " << endl;
	setB.PrintElements();
	cout << endl;

	cout << "Test Case 3:" << endl;			
	cout << "Set A has a cardinality: ";	     //cardinality
	setA.cardinality();
	setA.PrintElements();
	cout << endl;
	cout << "Set B has a cardinality: ";
	setA.cardinality();
	setA.PrintElements();
	cout << endl;
	cout << endl;

	cout << "A is a subset of B: ";				//subsets true or false
	setA.isSubset(setB);
	cout << endl;
	cout << "B is a subset of A: ";
	setB.isSubset(setA);
	cout << endl;
	cout << endl;

	cout << "Test Case 5:" << endl;			
	cout << "The intersection of A and B is: ";	//intersect and union
	//setA.Intersect(setB);
	setC.PrintElements();
	cout << endl;
	cout << "The union of A and B is: ";
	//setA.Union(setB);
	setC.PrintElements();
	cout << endl;
	cout << endl;

	return 0;
}


/////////////////////////////////////////////////
I fixed up the code like you told me too. But im haveing errors with the union and intersect after i fixed it it was saying that unresolved linking error and to consult with tech support wow but newayz thank you for ur help...another error is that when i add elements in im only able to add elements into the first array and then not in the second and by this i get an error...
  #6  
Old 06-Jul-2005, 18:01
maprich maprich is offline
Member
 
Join Date: May 2005
Posts: 163
maprich has a spectacular aura aboutmaprich has a spectacular aura about
Not only your Intersect(..) but also methods Cardinality() and isSubset(MySet<Type> B) have to be rewritten. You have to make use of this pointer.

Super shortly about this pointer:
Example Classes:
CPP / C++ / C Code:
class Beta
{
    public:
        Beta();
        void betaMethod();
};

class myAlpha : public Beta
{
    myAlpha();
    ~myAlpha();

    void myMethodA();
    void myMethodB();
};
Above myAlpha inherits Beta. So automatically if there is an object of class myAlpha say objAlpha then following is valid: objAlpha.betaMethod() as well as objAlpha.myMethodA()

And then this pointer is a pointer to the current class object.
In practice something like:
CPP / C++ / C Code:
void myAlpha::myMethodA()
{
    this->myMethodB();     // calls another method of this same class
    this->betaMethod();    // calls the inherited method of this class
}

I wrote above explanation just so that you can begin to understand the reasons for the changes that I proposed (and which you implemented) in my previous post. So that you could see what is going on and could edit the methods like Cardinality() etc.etc. by yourself. You are attempting amazingly complex level code for someone who isn't familiar with this pointer and inheritance.

To really understand what is going on you should study following individual topics:
- OOP(Object Oriented Programming) inheritance, polymorphism & interfaces e.g. wiki.tcl.tk/13398 offers some explanation
- C++ implementation of inheritance, visibility scopes, virtual inheritance, constuctors, method overloading, this pointer etc.
- C++ templates e.g.www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html offers tutorial for inheritance and templates
- C++ STL (Standard Template Library). Google turns up good tutorials about this subject too.
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
Type casts ? kai85 C++ Forum 12 23-Jun-2005 13:04
[TUTORIAL] Calling an external program in C (Linux) dsmith C Programming Language 4 22-Apr-2005 14:30
fltk-2.0 cvs Plumb FLTK Forum 20 13-Nov-2004 08:10
Need help with a C program (Long) McFury C Programming Language 3 29-Apr-2004 21:06

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:43.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.