further troubles with sets

This is a discussion on further troubles with sets within the C++ Programming forums, part of the General Programming Boards category; I understand jawib, but you don't know how many numbers are inputed and if they are even numbers...thats why it ...

  1. #16
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    I understand jawib, but you don't know how many numbers are inputed and if they are even numbers...thats why it is not so simple, and thats why I used strtok() to go threw the input and pick out only the decimals....

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  2. #17
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Hmmm...

    Well if there is a limit to how many numbers can be entered you could do:
    Code:
    char tmp[20]={0};
    	//create a set
    	cin>>command;
    int n;
    int member[100];
    if( command.find("create")!=string::npos )
    	{
    	n=command.find("create");
    	for (int i=0;(i+n)<command.length();i++)
    {
    int j=0;
     while (isdigit(command[i]))
         tmp[j++]=command[i];
    member[i]=atoi(tmp);
    memset(tmp,0,20);
    }
    }
    But I suppose it wouldn't be allowed...And its not tested anyways...I don't know I wish I could help more but I'm tired and gotta get up for school tomorrow
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #18
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    ok, this is what I did to fill up the array with the elements:
    Code:
    void Sets::createSet( int member, SingleSet data, int &ID )
    {
    	if( data.getId() != ID )
    	{
    		allSets[ID] = new SingleSet;
    		data.setId( ID );
    	}
    
    	allSets[ID]->push( member );
    }
    then to test if that works I wrote the print function that is also required for my program...it compiles fine but when I run it it gives me a fatal error?? any ideas?
    Code:
    //THIS FUNCTION IS CALLED BY getCommand() from main.cpp
    //and it is located in class Sets
    void Sets::print( int set )
    {
    	allSets[set]->print();
    }
    
    //above function calls this function found in class SingleSet
    void SingleSet::print()
    {
    	for( int i=0; i<3; i++)
    	{
    		cout << endl << setArray[i] << " ";
    	}
    }

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  4. #19
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    >>But I suppose it wouldn't be allowed...And its not tested anyways...I don't know I wish I could help more but I'm tired and gotta get up for school tomorrow

    thanks for all the advice jawib...i appreciate it. I'll work on this for another few hours and hopefully I can get it don tonite. I'll post what I have before I go to bed. The assignment is not due till friday night.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  5. #20
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    >>The assignment is not due till friday night

    Now he tells me lol

    Well good luck...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  6. #21
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    I don't understand one thing...why does this: int number = (allSets[ID]->setArray[0]); work int the createSet function but not afterwards in the print function????
    Code:
    void Sets::createSet( int member, SingleSet data, int &ID )
    {
    	if( data.getId() != ID )
    	{
    		allSets[ID] = new SingleSet;
    		data.setId( ID );
    	}
    
    	allSets[ID]->push( member );
    	int number = ( allSets[ID]->setArray[0] );
    	cout << endl << number << endl;
    }
    
    void Sets::print( int set )
    {
    	int number = 0;
    
    	for(int i=0; i<3; i++)
    	{
    	    number = (allSets[set]->setArray[i]);
    		cout << endl << " " << number;
    	}
    
    }

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  7. #22
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    here is what vc++ debugger tells me...but I don't know how to interpret it:
    Attached Images Attached Images  

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  8. #23
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    I've figure it out...I have not been returning (&) the variables declared in main of type Sets and SingleSet.....ooops

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem aligning floating point numbers
    By esbo in forum C Programming
    Replies: 4
    Last Post: 01-05-2009, 08:09 PM
  2. Stl sets and custom classes.
    By cunnus88 in forum C++ Programming
    Replies: 3
    Last Post: 05-13-2006, 12:58 AM
  3. Major Problems with GetSaveFileName() and GetOpenFileName()
    By CodeHacker in forum Windows Programming
    Replies: 8
    Last Post: 07-12-2004, 12:05 PM
  4. creating new sets
    By axon in forum C++ Programming
    Replies: 7
    Last Post: 12-03-2003, 06:37 PM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21