do my homework for me..

This is a discussion on do my homework for me.. within the C++ Programming forums, part of the General Programming Boards category; ha ha, j/k i know everyone hates that!!! but....this is a homework related question i posted a week or so ...

  1. #1
    cereal killer dP munky's Avatar
    Join Date
    Nov 2002
    Posts
    655

    drowning in homework

    ha ha, j/k i know everyone hates that!!!

    but....this is a homework related question i posted a week or so ago and have been having a lot of trouble w/this, this is what i have so far w/the help that i've got...PLEASE!!! do NOT do this for me, i dont want that, i know i have to know this stuff and really want genuine help, if youre just gunna tell me to do it myself then just dont post.

    im supposed to use these data structures and the function prototype given to me to create a linked list, this is what i have so far, i've looked at the tutorials n' stuff but im needing more help....i dont understand how im supposed to get things working, i know i'll have to parse through the string passed to me but other than that, the **headPP thing is really getting me? how do i get this linked list in motion
    Code:
    /*************DATA STRUCTURES******************/
    // Encapsulates each entry in the phone book
    struct PhoneEntry
    {
    	// null-terminated string representing student name
    	char *name;
    
    	// null-terminated array representing student phone number
    	// in the format: XXX-XXXX
    	char number[9];
    };
    
    // Represents the structure of the phone book
    struct PhoneBook
    {
    	PhoneEntry data;
    	PhoneBook *next;
    };
    
    
    /****************FUNCTIONS******************/
    void BuildPhoneBook(PhoneBook **headPP, const char *str)
    {
    	PhoneBook *conductor;
    	const char array[1024] = str;
    	int i;
    
    	conductor = *headPP;
    
    	if(conductor != NULL)
    	{
    		while(conductor->next != NULL)
    		{
    			conductor = conductor->next;   
    	    }
    	}
    	
    	if(array = str)
    	{
    		while(i != NULL)
    		{
    			array[i] = str;
    			
    			if(array[i] = ' ')
    			{
    				conductor->data.name = array 
    			}
    			++i;
    		}
    
    	}
    	
    
    }

    sorry this was so long
    Last edited by dP munky; 03-13-2003 at 02:49 AM.
    guns dont kill people, abortion clinics kill people.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,691
    Code:
    1 void BuildPhoneBook(PhoneBook **headPP, const char *str)
    2 {
    3   PhoneBook *conductor;
    4   const char array[1024] = str;
    5   int j;
    6
    7   conductor = *headPP;
    8
    9   if(conductor != NULL)
    10  {
    11      while(conductor->next != NULL)
    12      {
    13          conductor = conductor->next;   
    14      }
    15  }
    16  
    17  if(array = str)
    18  {
    19      while(j != NULL)
    20      {
    21          array[j] = str;
    22          
    23          if(array[j] = ' ')
    24          {
    25              conductor->data.name = array 
    26          }
    27          ++j;
    28      }
    29
    30  }
    31}
    • (1) what is str supposed to be?
    • (4) if you want a copy of the pointer then drop the "[1024]", if you want to copy the array you have to use strcpy() or memcpy() or use an STL string which overloads the "=" operator.
    • (7,9) good
    • (11-14) traverse conductor to the last node in list - yep
    • (16) conductor may be NULL here - you'll need to do something about it
    • (17,23) assignment!!!!!!!! NOT comparison
    • (19) j is an int, why are you comparing it to NULL?

    I'm very confused with lines 17 - 30, but my guess is that str contains multiple items of data in it seperated by a space? Give a sample input for str.
    As for building the list, if you are going to be adding new nodes to the list, there should be a call to new somewhere.


    gg

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    A linked list usually has one structure/class. Maybe it'll have a head class and I think thats what you're trying to do with PhoneBook.

    You see, you placed the *next in the wrong place. There is only one phone book (although you can make many of them) and it has a bunch of entries. What you're doing right now is having multiple books and each book having one entry. That just doesn't make any sense unless your assignment told you explicity to do that.

    I think it should be:
    Code:
    /*************DATA STRUCTURES******************/
    // Encapsulates each entry in the phone book
    struct PhoneEntry
    {
    	// null-terminated string representing student name
    	char *name;
    
    	// null-terminated array representing student phone number
    	// in the format: XXX-XXXX
    	char number[9];
    
    	// the next entry in our book
    	PhoneEntry *next;
    };
    
    // Represents the structure of the phone book
    // ***This isn't really needed...
    struct PhoneBook
    {
    	PhoneEntry *first;
    	// ...other data here, if any...
    };


    Second, just like CodePlug, I'm very confused with those ending lines in your function. First of, since I'm not sure what you're trying to do, let me point something out. Here you declare this variable: int j; Later you use it: while(j != NULL) ++j; In C++ variables don't default to 0. If you want j to be zero from the begining, you should: int j=0;

    Plus, j!=NULL is the same thing as j!=0 so......

    *****
    Tell us EXACTLY what you're assignment said and what that function is supposed to do and we'll be more helpful.
    *****

  4. #4
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    Have you tried to ask your instructor for some guidance??
    Mr. C: Author and Instructor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-03-2001, 04:39 PM
  2. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 05:49 PM
  3. Homework
    By kermi3 in forum Windows Programming
    Replies: 5
    Last Post: 09-15-2001, 12:48 PM
  4. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 02:26 PM

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