WARNING: This is an Archive - Try the New TestMy.net
Home
 
Welcome, Guest. Please login or register.

 
  spcr
» Home » C++ Help!!
    
  Home    Help    Search    Login    Register  
 
News : uglystupid2 Don't look stupid, make sure you keep up-to-date with our rules, please read rules, click here  police May 22, 2012, 05:20:50 AM
old.testmy.net forums  |  Main Forum  |  HELP!  |  Programming and Website Help  |  Topic: C++ Help!! Advanced search
  0 Members and 1 Guest are viewing this topic. « previous next »
Pages 1 Go Down
Author
Topic: C++ Help!!  (Read 2213 times)
RAINMAKA
TMN Friend
*
Offline Offline

Gender: Male
Posts: 461



View Profile
« on: March 22, 2006, 12:54:26 PM »

i have a test coming up in my C++ class and my professor gave me this problem to help me get ready. im and having trouble writing the program and not too sure where to start. any help would be great. the problem is the attached picture.
Logged

 
Swimmer
Vice Admin
TMN Seasoned Veteran
*
Offline Offline

Gender: Male
Posts: 6373



View Profile
« Reply #1 on: March 22, 2006, 02:10:24 PM »

let me look at it later.. i know C# and php knows a bit of C++..
Logged

 
disturbed
News Anchor
TMN Veteran
*
Offline Offline

Posts: 2067


I am and always will be disturbed.


View Profile
« Reply #2 on: March 22, 2006, 03:40:34 PM »

i speak cpp - i can point you in the right direction, but i wont write the code for you Smile



*writing stuff as we speak - give me few minutes
Logged

Are you down with the sickness !?

[ http://hackaday.com ]
 
disturbed
News Anchor
TMN Veteran
*
Offline Offline

Posts: 2067


I am and always will be disturbed.


View Profile
« Reply #3 on: March 22, 2006, 03:59:50 PM »

...like i said, i wont write the code for you but ill point you in the right direction - i really have no idea where you stand when it comes to cpp so ill try and be as simple as possible

- You should understand what a struct is: struct is one of the structure types in cpp - it can be composed of several differnet types of elements - since you are working with a linked list of struct objects (named element), you should understand that they have to be connected by pointers (thus the element *next as the element of the struct)

- the element *next basically points to the next elemnt in the struct linked list

- you can start our your linked list by saying
element *Head = NULL;             
             this is said to be a dummy node

...now im gonna be nice - you can use the similar code to do the rest of your assignment, its quite simple actually

  void addNode(element **head, int yourInteger) {
    element *tmp;

    if ((tmp = malloc(sizeof(*tmp))) == NULL) {
      ERR_MSG(malloc);
      (void)exit(EXIT_FAILURE);
    }
    tmp->data = yourInteger;
    tmp->next = *head;
    *head = tmp;
  }



- there I noticed that you also need a random integer created - this has an easy solution - since im just trying to be simple, you should do this

create a variable count that keeps track of how many elements you have - every time you want to create a new element, you can pass that variable to a helper method that can take that count variable and lets say add 5 to it and multiply it by 2 (example...you currently have 2 elements in your linked list - you wanna create a 3rd one - pass 2 to the method, method adds 5 to it = 7 and multiply it by 2 - that will equal 14 - there is your randomly generated number)

you can also use the 'time' function of c, which takes the current number of computer clocks to generate a random number - but no need to make it more complicated



to put elements in the right order, you can use any sorting method: bubble sort, merge sort (would be best since you are already working with linked lists), quick sort - you can find algorithms on the web



......i think i coverd the basis - if you have any more questions ask away


Logged

Are you down with the sickness !?

[ http://hackaday.com ]
 
RAINMAKA
TMN Friend
*
Offline Offline

Gender: Male
Posts: 461



View Profile
« Reply #4 on: March 22, 2006, 06:02:42 PM »

disturbed thanks for your help, i have it almost done. i just have to do the part where i create a element inbetween and i just cant get it to work. if you want me to post the coding i have so far just let me know.
Logged

 
disturbed
News Anchor
TMN Veteran
*
Offline Offline

Posts: 2067


I am and always will be disturbed.


View Profile
« Reply #5 on: March 22, 2006, 06:49:10 PM »

to create an element in between - you can simply make another pointer that points to some element in your linked list and in the method i wrote there for you, instead using the head, use the pointer to that new pointer

get what i mean ?
Logged

Are you down with the sickness !?

[ http://hackaday.com ]
 
Swimmer
Vice Admin
TMN Seasoned Veteran
*
Offline Offline

Gender: Male
Posts: 6373



View Profile
« Reply #6 on: March 22, 2006, 07:29:27 PM »

A+ for disturbed!
Logged

 
disturbed
News Anchor
TMN Veteran
*
Offline Offline

Posts: 2067


I am and always will be disturbed.


View Profile
« Reply #7 on: March 22, 2006, 10:02:37 PM »

glad to be of help Smile
Logged

Are you down with the sickness !?

[ http://hackaday.com ]
 
Print  Pages 1 Go Up
old.testmy.net forums  |  Main Forum  |  HELP!  |  Programming and Website Help  |  Topic: C++ Help!! « previous next »
Jump to:  

    


 

 

 

© 2007 testmy.net - Contact - Legal - This is an older version: Try Bandwidth Speed Test v12