![]() |
|
#1
|
|||
|
|||
Need help with linked listshello I'm trying to create a linked list and traverse it but seem to be doing something wrong
the program specifications are: Write a complete C++ program that creates and queries a linked list of people who have served as United States presidents and/or vice presidents. Name your program file pgm4.cpp. Your program should do the following: 1. Define a struct called PublicOfficial to hold the following data about each president or vice president. Name State of birth Office held (1 = President; 2 = Vice President; 3 = both President and Vice President President Order (a number from 1 - 44 indicating whether he was the 1st, 2nd, 3rd, etc.) Year first term as President began Year last term as President ended Vice President Order (a number from 1 - 44 indicating whether he was the 1st, 2nd, 3rd, etc.) Year first term as Vice President began Year last term as Vice President ended Pointer to the next PublicOfficial in the list 2. In the main function, declare a pointer to serve as the head of a linked list of PublicOfficial structs. Also declare an ofstream variable and open a report file (pgm4.rpt) for writing out the results of queries about the data in the linked list. 3. Call a function named buildList, passing the head pointer by reference. This function will handle reading in all of the data from the file pgm4.dat and storing it in a linked list. First create the ifstream variable, open the input file and check for the success of that operation. Then read in the data for each public official until you reach the end of the file. For each person in the data file: - Dynamically create a PublicOfficial node to store that person's data. - Read in the person's Name, State of birth and Office held code. If the Office held code is 1, read in the next three lines and store the data in the President fields. Set the Vice President fields to zero. If the code is 2, read in the next three lines and store the data in the Vice President fields, setting the President fields to zero. If the code is 3 there will be six lines of data to read in, three with the President data followed by three with the Vice President data. - Call a function named addOfficial to add the new official to the end of the linked list. Pass the pointer to the head of the list and the pointer to the new official to this function. - Close the input file. All queries should be done using the linked list created from the data in this file. 4. Create a loop in the main function to get the user's selection from the menu of options shown below. President/Vice President Queries 1. Presidents 2. Vice presidents 3. All who served in both offices 4. Presidents serving in 1700s 5. Presidents serving in 1800s 6. Presidents serving in 1900s 7. Presidents serving in 2000s 8. Presidents from a given state 9. Presidents serving less than full term 10. Exit program heres the code I have so far: CPP / C++ / C Code:
Last edited by admin : 03-Mar-2009 at 00:54.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|||
|
#2
|
||||
|
||||
Re: Need help w/ linked listsQuote:
PublicOfficial is not the same as publicOfficial. You have foundational problems that are more significant than the issues surrounding linked lists. Until you fix some of your foundational issues, you're not ready for linked lists. MxB |
|
#3
|
|||
|
|||
Re: Need help with linked listsAlso, How could you write so much code without testing along the way?
Start with your structure declaration and a skeleton main(). Compile and fix... repeat as needed Then begin to add your buildList() function starting with the file open only. Don't forget to close you open files and delete you new's. Add a little at a time, test, fix, repeat. BUILD Your Code. Then you can address a single problem instead of many. |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Linked Lists Database... | TS3BxL | C++ Forum | 10 | 19-Mar-2008 23:37 |
| triangle (polygon), drawing, sizing, and rotation programme using linked lists... | promsan | C Programming Language | 12 | 14-May-2007 15:03 |
| Linked Lists problem | kracivi | C Programming Language | 1 | 01-May-2007 09:40 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 14:12 |
| Linked lists | vortz83 | C++ Forum | 3 | 20-Mar-2004 07:56 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The