|
-
Oct 22nd, 2002, 12:46 PM
#1
Thread Starter
Member
Help w/project + linked list Plz Read
Ok I have this project to do and its like impossible to do!?
Im supposed to create a double linked list implemented as a class and have ( insert, delete, search, traverse ) The structure used for it should have fields for ( name, ssn, age & occupation ) The search, delete func perform their functions give a persons name. The program fills up the linked list using a data file. Then the program presents the user with options ( display a record, add a record, delete a record and exit ) The display, add, and delete operations should request a name and display an error if the name doesnt exist in the list. Then on exit the program writes the linked list back to the data file.
A same file I guess looks like this
Smith, Bob
123-34-3333
43
Engineer
Im soo lost on this project.
The code for the class though is this:
PHP Code:
Class LL
{
private:
record *head;
record *tail;
public:
LL();
int insert (record *);
record *search(char[]);
int delete_item(char[]);
void traverse[];
}
LL:: ( LL )
{
head = NULL;
tail = NULL;
}
Id be willing to pay someone ! I need u geniouses
-
Oct 22nd, 2002, 03:58 PM
#2
That's about the 5th linked list post in one week...
UTFSF!
Use The *****ing Search Function!
Two or three days ago I posted a list of the threads concerning linked lists, and one of these links contains both a C and a C++ implementation of a linked list, also both written by me.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 22nd, 2002, 04:01 PM
#3
Frenzied Member
I know I posted a full mailing list app in C using LL's , as well.
It must be final project season in beginning C/C++ classes...
-
Oct 22nd, 2002, 04:02 PM
#4
Yep, also I've seen a VERY similar exercise. Also was about cars and SSNs...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 22nd, 2002, 06:06 PM
#5
Monday Morning Lunatic
Originally posted by jim mcnamara
I know I posted a full mailing list app in C using LL's , as well.
It must be final project season in beginning C/C++ classes...
Too ****ing right.
I am sick and tired of people posting their homework questions. I have no problem with them having difficulties, we're happy to help.
But for God's sake don't give a half-arsed class layout and expect us to do your homework!
&& drunk...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 22nd, 2002, 08:59 PM
#6
Thread Starter
Member
Originally posted by parksie
Too ****ing right.
I am sick and tired of people posting their homework questions. I have no problem with them having difficulties, we're happy to help.
But for God's sake don't give a half-arsed class layout and expect us to do your homework!
&& drunk...
why not? dont u guys luv what u do?
-
Oct 23rd, 2002, 02:31 AM
#7
Monday Morning Lunatic
Heh, sorry about the rant back there 
I do love what I do, but the idea is for us to help people, not do it for them, else nobody will ever learn.
We've just had a bit of a glut of people asking obvious homework questions, that's all.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 23rd, 2002, 02:59 AM
#8
Yes, you are mainly that "unlucky kid who came in at the time when everybody just said that they would kill the next one to come in". That's all.
But nevertheless the search function should give you a big jump start. If you have specific problems come back.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 23rd, 2002, 09:20 AM
#9
Thread Starter
Member
ok well, ill try the search func, but can u guys help me still ? ill be back later
-
Oct 23rd, 2002, 09:24 AM
#10
Monday Morning Lunatic
Of course
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 23rd, 2002, 01:35 PM
#11
Thread Starter
Member
ok guys, I dunno im just really confused on the code for linked list. I think I just need an insert node I think, and Im not sure where to begin.
Heres some of the code so far, but its scattered a bit. Im not sure what the parameters are for traverse, delete etc. I need some kinda start. Im gonna keep reading up on it and workin on it right now.
PHP Code:
#include "stdafx.h"
#include <fstream>
#include <iostream>
struct record
{
char name[50];
char ssn[12];
char age[4];
char occupation[50];
record *next;
record *prev;
};
Class LL
{
private:
record *head;
record *tail;
public:
LL();
int insert (record *);
record *search(char[]);
int delete_item(char[]);
void traverse[];
}
LL:: ( LL )
{
head = NULL;
tail = NULL;
}
int LL:insert( )
void LL:traverse( )
void LL:DeleteNode( )
{
--(ll->size);
at->prev->next = at->next;
at->next->prev = at->prev;
free(at);
}
int main(int argc, char* argv[])
{
menu();
return 0;
}
int menu ()
{
int item;
// display menu and return output
cout << "===============================" << endl;
cout << " Please Select An Option " << endl << endl;
cout << " 1. Display a record" << endl;
cout << " 2. Add a record" << endl;
cout << " 3. delete a record" << endl;
cout << " 4. Exit" << endl;
cin >> item;
cin.ignore ();
// return item
return item;
}
I just wanna get it done before the weekend cuz its due next tuesday, and I have plans for the weekend. But Im gona do my best with everyones help
-
Oct 23rd, 2002, 03:06 PM
#12
I corrected some syntax errors, but not yet supplied code for the missing functions.
PHP Code:
#include "stdafx.h"
#include <fstream>
#include <iostream>
[b]using namespace std;[/b]
struct record
{
char name[50];
char ssn[12];
char age[4];
char occupation[50];
record *next;
record *prev;
};
Class LL
{
private:
record *head;
record *tail;
public:
LL();
int insert (record *);
record *search(char[]);
int delete_item(char[]);
[b]void traverse();[/b]
[b]};[/b]
[b]LL::LL()[/b]
{
head = NULL;
tail = NULL;
}
// You need to pass data to insert.
int LL:insert()
{
}
// Actually this function can't do anything
void LL:traverse()
{
}
// Need to pass an at pointer
[b]void LL::DeleteNode()[/b]
{
--(ll->size);
at->prev->next = at->next;
at->next->prev = at->prev;
free(at);
}
int main(int argc, char* argv[])
{
menu();
return 0;
}
int menu ()
{
int item;
// display menu and return output
cout << "===============================" << endl;
cout << " Please Select An Option " << endl << endl;
cout << " 1. Display a record" << endl;
cout << " 2. Add a record" << endl;
cout << " 3. delete a record" << endl;
cout << " 4. Exit" << endl;
cin >> item;
cin.ignore ();
// return item
return item;
}
Is the list sorted? Or should it be in random order? The implementation of insert depends on that.
Look at the insert implementations in my code, they are not that hard to understand (and I can explain them if you want).
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 23rd, 2002, 03:29 PM
#13
Thread Starter
Member
ya its gotta be a sorted list, and why cant traverse do anything? Im supposed to have it.
ya plz explain.
-
Oct 23rd, 2002, 03:43 PM
#14
A traverse function doesn't really make sense, you usually do the traversing directly (in C) or via iterators (in C++). traverse can't do what it's name implies without using function pointers, which you should avoid.
Traverse could also take a node pointer and return the next node, but why do
Node *p;
p = traverse(p);
when you can do
p = p->next;
?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 23rd, 2002, 04:23 PM
#15
Thread Starter
Member
well, my teacher is retarded, i guess we're supposed to use function pointers. I dunno.
-
Oct 23rd, 2002, 07:08 PM
#16
Thread Starter
Member
I know this isnt really the " right " thing to ask. But would u or anyone except money for the code? I hate to ask it, and I know I should be learning this stuff, but its just that I dont really have an interest in programming and dont understand it that much. I guess I just wanna get done with this last programming class so I can move on to networking, which is my major pretty much.
So sorry if I upset u cornedbee or anyone else, but I guess Im just desperate? I would pay though
-
Oct 24th, 2002, 05:53 AM
#17
It is more trouble arranging such a payment that it's worth...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 24th, 2002, 10:25 AM
#18
Thread Starter
Member
Originally posted by CornedBee
It is more trouble arranging such a payment that it's worth...
why? paypal is so easy
Last edited by havoq93; Oct 24th, 2002 at 10:31 AM.
-
Oct 24th, 2002, 10:53 AM
#19
Thread Starter
Member
Ok ive gotten this far. Can u help out on some of these other functions like the insert one, or fix mistakes i might have?
PHP Code:
#include "stdafx.h"
#include <fstream>
#include <iostream>
using namespace std;
struct record
{
char name[50];
char ssn[12];
char age[4];
char occupation[50];
struct record *next;
struct record *prior;
};
struct record *start; /* pointer to first entry in list */
struct record *last; /* pointer to last entry */
struct record *find(char *);
Class LL {
private:
record *head;
record *tail;
public:
LL();
int insert (record *);
record *search(char[]);
int delete_item(char[]);
void traverse[];
};
LL:: ( LL )
{
head = NULL;
tail = NULL;
};
int LL:insert( )
void LL:traverse( )
void LL: delete_item(struct record **start, struct record **last)
{
struct record *info;
char s[80];
inputs("Enter name: ", s, 30);
info = find(s);
if(info) {
if(*start==info) {
*start=info->next;
if(*start) (*start)->prior = NULL;
else *last = NULL;
}
else {
info->prior->next = info->next;
if(info!=*last)
info->next->prior = info->prior;
else
*last = info->prior;
}
free(info); /* return memory to system */
}
}
/* Look for a name in the list. */
void search(void)
{
char name[50];
struct record *info;
printf("Enter name to find: ");
gets(name);
info = find(name);
if(!info) printf("Not Found\n");
else display(info);
}
/* Load the record file. */
void load()
{
struct record *info;
FILE *fp;
fp = fopen("assign6", "rb");
if(!fp) {
printf("Cannot open file.\n");
exit(1);
}
/* free any previously allocated memory */
while(start) {
info = start->next;
free(info);
start = info;
}
/* reset top and bottom pointers */
start = last = NULL;
printf("\nLoading File\n");
while(!feof(fp)) {
info = (struct record *) malloc(sizeof(struct record));
if(!info) {
printf("Out of Memory");
return;
}
if(1 != fread(info, sizeof(struct record), 1, fp)) break;
dls_store(info, &start, &last);
}
fclose(fp);
}
/* Save the file to disk. */
void save(void)
{
struct record *info;
FILE *fp;
fp = fopen("assign6", "wb");
if(!fp) {
printf("Cannot open file.\n");
exit(1);
}
printf("\nSaving File\n");
info = start;
while(info) {
fwrite(info, sizeof(struct record), 1, fp);
info = info->next; /* get next address */
}
fclose(fp);
}
int main(int argc, char* argv[])
{
start = last = NULL; /* initialize start and end pointers */
for(; {
switch(menu()) {
case 1: display();
break;
case 2: add_rec();
break;
case 3: DeleteNode();
break;
case 4: exit(0);
}
}
return 0;
}
int menu ()
{
int item;
// display menu and return output
cout << "===============================" << endl;
cout << " Please Select An Option " << endl << endl;
cout << " 1. Display a record" << endl;
cout << " 2. Add a record" << endl;
cout << " 3. delete a record" << endl;
cout << " 4. Exit" << endl;
cin >> item;
cin.ignore ();
// return item
return item;
}
my class is also messup I think cuz i keep getting
C:\Program Files\Microsoft Visual Studio\assign6\assign6.cpp(26) : error C2146: syntax error : missing ';' before identifier 'LL'
C:\Program Files\Microsoft Visual Studio\assign6\assign6.cpp(26) : error C2501: 'Class' : missing storage-class or type specifiers
Last edited by havoq93; Oct 24th, 2002 at 11:48 AM.
-
Oct 25th, 2002, 09:52 AM
#20
Addicted Member
-
Oct 25th, 2002, 10:43 AM
#21
Class
as far as I know C++ uses class and is case-sensitive...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 25th, 2002, 10:50 AM
#22
Thread Starter
Member
ya i figured that out the other day, I shoulda mentioned it, so u didnt waste a post on me like that. lol
what about the rest of the code? right trail?
PHP Code:
#include "stdafx.h"
#include <fstream>
#include <iostream>
using namespace std;
struct record
{
char name[50];
char ssn[12];
char age[4];
char occupation[50];
struct record *next;
struct record *prior;
};
struct record *start; /* pointer to first entry in list */
struct record *last; /* pointer to last entry */
struct record *find(char *);
void list(void);
void search(void);
void display(struct record *);
void dls_store(struct record *i, struct record **start, struct record **last);
int menu();
class LL
{
private:
record *head;
record *tail;
public:
LL();
int insert(record data);
record *search(char[]);
int delete_item(char[]);
void traverse(void);
};
LL::LL ( )
{
head = NULL;
tail = NULL;
}
/* Load the record file. */
void load()
{
struct record *info;
FILE *fp;
fp = fopen("assign6", "rb");
if(!fp) {
printf("Cannot open file.\n");
exit(1);
}
/* free any previously allocated memory */
while(start) {
info = start->next;
free(info);
start = info;
}
/* reset top and bottom pointers */
start = last = NULL;
printf("\nLoading File\n");
while(!feof(fp)) {
info = (struct record *) malloc(sizeof(struct record));
if(!info) {
printf("Out of Memory");
return;
}
if(1 != fread(info, sizeof(struct record), 1, fp)) break;
dls_store(info, &start, &last);
}
fclose(fp);
}
/* Create a doubly linked list in sorted order. */
int LL::insert ( record data )
{
record *newnode = new record; // make a new node
*newnode = data; // copy the data
newnode->next = NULL;
newnode->prior= NULL; // initialise the links
if ( head == NULL ) {
// list is empty, and now there is one
head = tail = newnode;
} else {
// add node to the head of the list
newnode->next = head;
head->prior = newnode;
head = newnode;
}
return 0;
}
/* Display the entire list. */
void list(void)
{
struct record *info;
info = start;
while(info) {
display(info);
info = info->next; /* get next address */
}
printf("\n\n");
}
/* This function actually prints the fields in each record. */
void display(struct record *info)
{
printf("%s\n", info->name);
printf("%s\n", info->ssn);
printf("%s\n", info->age);
printf("%s\n", info->occupation);
printf("\n\n");
}
int menu ()
{
int item;
// display menu and return output
cout << "===============================" << endl;
cout << " Please Select An Option " << endl << endl;
cout << " 1. Display a record" << endl;
cout << " 2. Add a record" << endl;
cout << " 3. delete a record" << endl;
cout << " 4. Exit" << endl;
cin >> item;
cin.ignore ();
// return item
return item;
}
int main(int argc, char* argv[])
{
int temp =0;
do {
temp = menu ();
switch(temp)
{
case 1: list();
break;
case 4: exit(0);
break;
default:
cout << temp << " is invalid!" << endl;
}
} while (temp != 4);
return 0;
}
Last edited by havoq93; Oct 25th, 2002 at 01:29 PM.
-
Oct 25th, 2002, 01:56 PM
#23
Thread Starter
Member
OK seriously, where do I go from here?
PHP Code:
using namespace std;
struct record
{
char name[50];
char ssn[12];
char age[4];
char occupation[50];
struct record *next;
struct record *prior;
};
struct record *start; /* pointer to first entry in list */
struct record *last; /* pointer to last entry */
struct record *find(char *);
void list(void);
void search(void);
void display(struct record *);
void dls_store(struct record *i, struct record **start, struct record **last);
int menu();
class LL
{
private:
record *head;
record *tail;
public:
LL();
int insert(record data);
int read_in(record *, char*);
record *search(char[]);
int delete_item(char[]);
void traverse(void);
};
LL::LL ( )
{
head = NULL;
tail = NULL;
}
int LL::insert ( record data )
{
record *newnode = new record; // make a new node
*newnode = data; // copy the data
newnode->next = NULL;
newnode->prior= NULL; // initialise the links
if ( head == NULL ) {
// list is empty, and now there is one
head = tail = newnode;
} else {
// add node to the head of the list
newnode->next = head;
head->prior = newnode;
head = newnode;
}
return 0;
}
/* Display the entire list. */
void list(void)
{
struct record *info;
info = start;
while(info) {
display(info);
info = info->next; /* get next address */
}
printf("\n\n");
}
/* This function actually prints the fields in each record. */
void display(struct record *info)
{
printf("%s\n", info->name);
printf("%s\n", info->ssn);
printf("%s\n", info->age);
printf("%s\n", info->occupation);
printf("\n\n");
}
int menu ()
{
int item;
// display menu and return output
cout << "===============================" << endl;
cout << " Please Select An Option " << endl << endl;
cout << " 1. Display a record" << endl;
cout << " 2. Add a record" << endl;
cout << " 3. delete a record" << endl;
cout << " 4. Exit" << endl;
cin >> item;
cin.ignore ();
// return item
return item;
}
int main(int argc, char* argv[])
{
int temp =0;
do {
temp = menu ();
switch(temp)
{
case 1: list();
break;
case 4: exit(0);
break;
default:
cout << temp << " is invalid!" << endl;
}
} while (temp != 4);
return 0;
-
Oct 25th, 2002, 05:57 PM
#24
Sorry, I just don't have the time to do this now.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 26th, 2002, 09:51 AM
#25
Thread Starter
Member
someones got time, who else?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|