C/C++ :: Dating Service Program Using Text File And Linked Lists
Jun 16, 2013
I'm new to programming, and I'm working on my second c++ program right now. Its a dating service where you read data from an input .txt file and store into a linked list, so then you can search, and modify the data. The text file is in this format:
M Dr.Gregory House,237-8732 7 Vicodin,Guitar,Piano,Motorcycles,Television,Food,W hiteboards.endl; (all on a single line).
First, is the sex (M or F), then the person's name, phone number, number of interests, then a list of their interests (with commas between each one, and a period at the end.) and then if they have a match you put their name there and put endl; after.
The main problem I'm having is setting up the link list, how to get it to read those as variables in the text, I know you have to use delimiters, but I can't quite figure out how to use them. You also have to keep two lists, one for males, and one for females in the output file. How do I do this? Is that a double linked list?
I have to write a program that reads from a text file, which contains a list of stock hourly prices and the company names. Something like this:
78.52 82.56 75.10 71.97 Water Company 22.40 25.68 21.37 22.96 Mega Shipping Inc
Each company data will be kept in a structure that contains: a pointer for the name, an array of the prices, and the average price for the day. The structures will be kept in a linked list. Each node structure will contain a pointer to one company data, and a pointer to the next node structure.This is all I have so far..
We have to sort the nodes alphabetically. My question is, how do I read the data from the file one line at a time, and insert them alphabetically one by one?
I was given a task to convert infix to post fix using both linked lists and stacks in the code so this is what i have written but the problem is it is giving me same error at three different places "missing function header(old style format?)
#include <iostream> #include <string> using namespace std; const int size = 100; class stack{ private: // Declare a structure for the list
I'm trying to write a function that takes two linked lists and creates a third one with only the common elements.
It assumes the first list (the caller) has no dups, but it doesn't seem to be working. The program doesn't crash, it just hangs when it is supposed to display L3 (the third list)..everything else runs and is displayed fine.
In our homework assignment it states to, "write a set of dynamic linked lists" and so on. Now, the problem I'm confusing myself is at the storage inside of each node. To my understanding, each node contains the prev and next nodes, but also a pointer to the data, in this case being a string. He has asked us to manage these strings as rows of chars such as
char[0] = c // first node being addressed here char[1] = a char[2] = t char[3] = char[4] = d // second node starting here char[5] = o char[6] = g char[7] =
I have written my code where each node is holding a string, not separated as shown above... my question is to how you can build your doubly linked list where each node is being address a set of chars.
I'm trying to do is let the user type in something like A654321 (note: these are ALL the characters, i.e. 'A', '6', '5', '4', etc..) Then I just want to display that current number back to them and I am getting some weird pointer memory allocation error..
#include<iostream> using namespace std; //To rename data-type "int" or integer to "element" (Both are equivalent).. typedef int element; //To declare an appropriate SENTINEL. char const SENTINEL = '#';
[code]....
It seems like the first part that it bugs out at is in my Clean(); function..
Unhandled exception at 0x01383FBB in VegMe.exe: 0xC0000005: Access violation reading location 0xCCCCCCD0.
It doesn't like head = head->next; ?Also, ignore the ReverseList(); function, it is not being used as of now.
I am having some trouble getting a 3d array of pointers to link up with a linked list for each of the array elements. the 3d array of pointers is declared like this:
Code:
struct particle *cell[MAXCELLS][MAXCELLS][MAXCELLS]; and there are linked lists declared like this: Code: struct particle { /* structure for particles */ double sw[3]; /* square well components */ double hs[3]; /* hard sphere components */ double u[3]; /* unit vector for rotations */ struct particle *link; };
I want to get the array pointers 'cell[x][y][z]' to point to the first observed particle in a function next to main, something like this:
Code:
void generate_list(){ int i,j,k,l; /* determine the number of cells to decompose the simulation box in each of x, y and z directions*/ int(cells_x) = floor(boxX/cell_size); int(cells_y) = floor(boxY/cell_size); int(cells_z) = floor(boxZ/cell_size); /* initialise the array of pointers to NULL */ for (j=0;j<cells_x;j++){
[Code]...
I am getting a pointer type cast error when I compile "assignment from incompatible pointer type",
I'm trying to compare a single value with a value from my Linked list and if they are same, I want to add the value from the list to new list. In other words I want to create a new List with values with the first one. Here is the code that I made, but it's not working.
This is the code with which I search in the first list for a node with a value. In the main() function I have A.find_city(), so it can start from the start_pointer from the first list:
void List::find_city() { List *temp1; int b = 0; char city[20]; cout << "Enter city: "; cin >> city; temp1 = start_ptr;
[Code] ....
This is the code with which I add a node to the new list:
I have this code that I need to memorize for my final. Memorizing code is easy for me, but I'm trying pretty hard to fundamentally understand the functions, and what they are doing (even using pen and paper, to draw and trace).For example, in the push function below, I understand everything, except why I'm setting ptr = p. I feel like p should be equal to NULL, then the next node I push should be equal to p, etc.
Stack & Stack::push(double x) { Node * p = NULL; try { p = new Node; }
[code].....
Also, are LL Queues that hard to implement once you can do them w/stacks - That will probably be something I have to code for my final, as well. Below is the full code for my Stack class.
#include <iostream> #include <string> #include <stdlib.h> using namespace std; class Stack }
A static method named readFromFile that takes a C-string as the first parameter, and an orderedLinkedList<MemberDO> object as the second parameter. The first argument is the filename that contains data for existing members. This method should read the data for each individual member from the input file (one line of data per member), create a new MemberDO object, and insert this object into the linked list specified in the second argument.
How do I take the second parameter in, do I need to create the Linked List first? Here is the code I have so far
#include<iostream> #include<string> #include <fstream> using namespace std;
So I have a Class named Subject, wich I used linked list to keep the objects. Now I have another Class called Tests which I should register a test by the Subject class, so I made a search like this:
List obj; //it's the object to access the List class, which manipulates the //nodes from Subject.
obj.currentPtr=obj.firstPtr; while (obj.currentPtr!=NULL) { if(obj.currentPtr->nameSubject==value) //searching if there's a return obj.currentPtr; //name equal to provided obj.currentPtr=obj.currentPtr->nextPtr; } return 0;
I've made a similar process for Subject. But in this when I access the firstPtr, it's shown to be 0, once I have already the list of Subject and it should not be zero. What's wrong?
The objective of the project is to become familiar with linked lists by writing a series of basic functions that allow us to manipulate a set of linked lists. I've completed all of the functions except for one.
The function I am stuck on is supposed to do the following:
concatenates list1 and list2 to form a new list, and returns a pointer to this new list;
Note: new list contains copies of all nodes in list1 and list2 */
The assignment is apparently pretty classic: given a starting state and a goal state, show the optimal path to solve a 3x3 sliding puzzle.
I have the code in place.Where I'm experiencing major issues is in maintaining two distinct linked lists. One should contain the frontier of the A-star algorithm and the other records the optimal path. In execution, however, it seems that only one list is in local memory in any one function. Therefore, when my function recurses, the lists begin to get confused and the whole algorithm veers off course.
Here is my structure definition in list.h:
typedef struct node { int value; int state[3][3]; struct node *next; } Node; typedef struct list { int count; Node *first; } List;
Here is my List_create function in list.c (do I need malloc here?):
int main(void) { List open; List closed; List_create(&open); List_create(&closed);
Here's the general flow of the program, without posting a wall of code: both lists are passed to another function in main.c, expand(), with this line:
expand(current, gState, &open, &closed);
The lists are later passed from expand() to another main.c function, generateOptions(), in this line:
generateOptions(&array, goalState, open, closed);
generateOptions() returns back to expand(), which recurses on itself with the first item in the open list and continues the expansion:
expand(open->first, goalState, open, closed);
Strangely, the open list prints out correctly before generateOptions() returns to expand(), and the closed list prints out correctly after generateOptions() returns to expand(). But when I try to print the open list in expand(), I'm instead given the closed list. Like I said at the outset, it appears that only one list exists at a time!
I am having to write a program that takes 2 sorted linked lists (x and y) and merge those to sorted into a third one (z). This has to be done via recursion. I think I am close but there is a logic error.
Anyway, I have an assignment in which I'm supposed to create a program to be used in a library. Basically a database storing all books currently outside the library along with who and when borrowed them. It also says I should use single linked lists.
Now, I've got a general idea of how to make it work but I've stumbled upon a problem. Since the program has to write all the data put into the database in a file and be able to tell the user whether a book has been kept too long by the reader, I figured I'd implement the struct tm to convert the date when the book was borrowed (or rent, whatever, English is not my first language ;p) into UNIX time.
Then, when I'd like the program to tell me which books are being kept hostage by the readers the program would look for a certain record (like a string inside a certain struct) and compare the date inside that record with current date and then the result of this comparison would be compared with a given, defined time limit. Although this is all a different kinda function, it's a bit simplier, I guess, and I think I'll work it out. However to get there at all I need to be able to store the data correctly and there is a problem, which I'll explain on the other end of the code .Here is the code I came up with:
Code: #include <stdio.h>#include <string.h> #include <stdlib.h> #include <time.h> int DisplayMenu(); int ReturnToMenu(); int AddBooks(char *filename);
[Code] ....
So, my problem is as follows: the date seems to be stored alright, but it's wrong. For checking I had a Code: printf("%d", mktime(&date)"); added and it returned "-1"... As I said, I'm relatively new to coding/programming and my knowledge is rather rudimentary.
By the way: I had one more gremlin haunting me on this one. Namely at the begining of the input to the AddBooks function:
Code: int flag = 0; do { printf("Please type in the book's title: "); gets(newbook.title); if (strcmp(newbook.title, "") == 0)
[Code] ....
The do while loop is to ensure 'unempty' input. Without this loop however, the program would display the message "Please type in the book's title:" but it wouldn't wait for input. It's simply jump to the next printf and wait for input then... I figured it might be becuase it took the 'Enter' that was somehow still in the memory after the user confirms his selection in the menu... It's just a guess, though.
#include <stdio.h> #include <stdlib.h> // Define doubly linked list structures typedef struct link singleLink; typedef struct trashLink singleTrashLink; struct link {
[Code] ....
Alright, my code is almost complete, I just can't get the clearFromList function to work correctly.
Here's what the program does, in a nutshell:
- Create two doubly-linked lists, one to hold numbers 0 through i, the other to hold a randomly generated list of numbers no greater than i to be "trashed". The same number cannot be "trashed" twice. - Go through the main doubly-linked list and "skip over" the numbers that are listed the trash doubly-linked list (i.e. "delete" them without actually freeing them). - Free both lists at the end.
I still have to free the trash list, but that's easy. I'm just stuck getting the clearFromList function to "skip over" each number in the main list that is added to the trash list.
I am working on a program where I sort elements into alphabetical order and then when one is less than the other I swap them. I first did it by swapping the data but they want me to swap the nodes instead and I am having trouble doing that.
Node *add_node( Node *list, const string &s ) { struct Node *n = new struct Node; n->word = s; // copy string s to word n->next = 0;
// add node n to the list // the list should always be in ascending alphabetical order n->next = list; list = n;
I first want to say that i am trying to solve my code without Pointers.
My goal is to.. 1. Construct an empty 2D array with a capacity of 25. (list[25][2];) 2. Empty(): test if the stack is empty 3. Push(): add a value to the stack in the (list[i][0] = value;) position and (list[i][1] = previous list[i][0] position) 4. Top(); read the value(list[i][0]) at the top(count) of the stack 5. Pop(); remove the value at the top of the stack (list[i]= 0;) 6. Display(); displays all the elements in the stack going from the top to bottom order. (shows array index, data value, and next array index)
I have hit a road block and don't know what to fix or where to go from here.
So a user inputs an artist name, and then if the input matches one of the nodes containing the artist names i need to return that. but then also if the input does not match any of the nodes, I need to insert a new one. This is to be written in C. Also my structure that this function goes off of is shown below as well.
We have an assignment in which we have to implement a printer spooler using linked lists. I have used the list from STL to implement everything. I can get the program to send the print command and maintain status of documents. The problem is I don't know how to mimic/send a dummy print command so the document gets printed. If I use Sleep() there is a delay in the whole program.while I want printing on backhand and others users to have access to the program.