1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

class program errors

Discussion in 'C++' started by kjt1991, Feb 2, 2011.

  1. kjt1991

    kjt1991 New Member

    Joined:
    Oct 30, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    hey guys I need some help with my program. I keep getting multiple errors and I can't figure them out. The main problem is my professor wrote the skeleton and wrote some ridiculous things. At line 10, I get multiple errors for incomplete brackets and I don't understand why. I don't know if copying and pasting the skeleton from word caused any compiling errors. The other errors are because I messed up my class implementation and I can't figure out whats wrong. Also I think I missed a bracket causing a fatal error if anybody sees the problem I would appreciate the help otherwise I can just check to make sure all the brackets are completed myself. I put :p where the compiler takes me when I hit the error.

    Code:
    #include <iostream>
    #include <cstdlib>
    using namespace std;
    
    #define MAXITEM 10;
    
    class mySet
    {
    	private:
    :p 	    int value[MAXITEM];
    	    int cardinality;
    
    	public:
    	    mySet( );     //  default constructor in which cardinality is set 0
                    void addItem(int x);  // if x is not in the set, add it and update length.
                    void removeItem(int x);  // if x is in the set, remove it from the set and update 
                                                            // length
                    void print( );   // print out all the elements in the set on screen
                    void Union(mySet y);  // merge the elements in set y into the current set
                    void intersection(mySet y); //  find all the common elements shared by set y 
                                                                 //  and current set,  then replace elements of current
                                                                 //  set with those common elements.  
    };
    
    int main(int argc, char *argv[])
    {
    	
    	mySet a,   b;
           	a.addItem(1);
           	a.addItem(2);
                cout << " The content of set a is:  " << endl;
    	a.print( );
           	b.addItem(2);
           	b.addItem(3);
                cout << "The content of set b is:  " << endl;
    	b.print( );
                a.intersection(b);
                cout << "The content of a ^ b is:  " << endl;
                a.print( );
    	a.Union(b);
                cout << "The content of (a ^ b) v b is:  " << endl;
                a.print( );
    
    	system("PAUSE");
    }
    
    mySet:: mySet ()
    	{
    
    		cardinality = 0;
    
    	}
    
    void mySet :: addItem (int x)
    	{
    
    		value[cardinality] = x;
    		
    		cardinality ++;
    
    			bool flag = false;
    
    		for (int i =0; i < cardinality; i ++)
    			{
    				if (value[i] == x)
    					{
    						flag = true; break;
    					}
    			}
    	}
    
    void mySet :: removeItem (int x)
    {
    	int i2 = 0;
    	bool flag = false;
    
    	for (int i = 0; i < cardinality; i++)
    		{
    			if (value[i] == x)
    				{
    					flag = true; break; i2 = i;
    				}
    
    			if (flag == true) //x is in the set
    				{
    					for (i = i2+1; i < cardinality; i++)
    					{
    						cardinality --; value[i-1] = value[i];
    					}
    				}
    }
    
    void mySet :: print ()
    {:p
    	if (cardinality == 0;)
    		{
    			cout << "The set is empty";
    		}
    
    	else
    		{ cout << "[ ";
    			for (int i = 0; i < cardinality; i++)
    				{
    					cout << value[i] " ";
    				}
    			cout << " ]";
    		}
    }
    
    void mySet :: Union(mySet y)
    {:p
    	for (int i = 0; i < cardinality; i++)
    		{
    			for ( int j = 0; j < y.cardinality; j++)
    				{
    					if (value[i]== y.value[j])
    						{
    							y.removeItem[y.value[j]];
    						}
    				}
    				cardinality = cardinality + y.cardinality;
    					for (int i = 0; i<y.cardinality; i++)
    						{
    							value[cardinality -y.cardinality+i] = y.value[i];
    						}
    	    }
    }
    
    void mySet :: intersection (mySet y)
    {:p
    	bool flag;
    		
    		for (int i = 0; i < cardinality; i++)
    			{
    				flag = false; int value2[10]; int counter = 0;
    				
    					for (j = 0; j< y.cardinality, j++)
    					{
    						if (value[i] == y.value[j])
    						{
    							value2[counter++] = value[i];
    						}
    					}
    			}
    }
    
     
  2. kjt1991

    kjt1991 New Member

    Joined:
    Oct 30, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I realized that MAXITEM shouldn't have a semicolon after it.
     
  3. Umairajmal

    Umairajmal New Member

    Joined:
    Dec 12, 2010
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Hazro,Pakistan
    Home Page:
    firstly remove the semicolon from "#define maxiten 10 " then run the program and tell me that how many errors he give mention each error or paste error. Then may be we can help you.
     

Share This Page