![]() |
|
#1
|
|||
|
|||
Linklist program with structsIn this assignment, you will write a program that holds a small collection of vehicles. Each vehicle will be represented by an instance of a struct that holds only the vehicle’s description, color, another field of your choice and a pointer to the next element in the list.
Write a C++ program that 1) Has a struct that contains fields (members) for the description of the vehicle, the color of the vehicle, the field that you choose and a pointer to that same struct type. 2) Main should have a pointer that holds the address of the first node in the list. 3) Nodes should be created as dynamic data (using the new keyword) 4) The list should contain exactly 3 vehicles. 5) The program should print out the vehicle description, color, and the field you chose from the list in the order they occur in the list. This is what my teacher wants to complete and Ive worked out some of the struct part of it, but I'm confused about how to do the rest. Any help would be appreciated thanks. CPP / C++ / C Code:
Last edited by LuciWiz : 16-Oct-2009 at 17:59.
Reason: Please insert your C++ code between [cpp] & [/cpp] tags
|
|||
|
#2
|
|||
|
|||
Re: Linklist program with structsTsk tsk, you didn't read the guidelines.
1) Has a struct that contains fields (members) for the description of the vehicle, the color of the vehicle, the field that you choose and a pointer to that same struct type. CPP / C++ / C Code:
The list structure aside (you can find Bob's rant about that in the C forum. Except that in C++ I'd implement it with classes), I wouldn't implement it that way. Why not use the much safer std::string instead of char*? I also wouldn't call the struct node. You're right, it is a node, but since it's not ONLY a node but also a vehicle, I'd call it vehicle. So I could change it to CPP / C++ / C Code:
2) Main should have a pointer that holds the address of the first node in the list. 3) Nodes should be created as dynamic data (using the new keyword) CPP / C++ / C Code:
CPP / C++ / C Code:
Traversing the list and cleaning up (deleting all the nodes) is up to you, but the principle is very similar to the construction of the list. In the deletion, just first remember to store the m_next pointer somewhere before deleting the current node. If that didn't help, then you should ask a question. |
|
#3
|
|||
|
|||
Re: Linklist program with structsThanks so much only problems im getting with that is a syntax error in the 'for' statement and on line 26 it says I am missing the function header
|
|
#4
|
|||
|
|||
Re: Linklist program with structswoot i figured it out thanks!
|
Recent GIDBlog
Problems with the Navy (Enlisted) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Equation solver | RazoR | C Programming Language | 3 | 18-May-2008 09:24 |
| Two-Tier data dissemination code installation problem | nidhibansal1984 | Computer Software Forum - Linux | 6 | 16-Sep-2007 10:13 |
| Help with a complex program | lordfuoco | C++ Forum | 5 | 24-Jun-2006 06:03 |
| Help With A Program Using Structs | fevershark | C++ Forum | 17 | 07-Dec-2005 20:50 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The