| | |
NEED help pls. about linked list
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2007
Posts: 21
Reputation:
Solved Threads: 1
NEED help please. here's our code. We wanted to print its output file. what function will we use? how will we do it? .We wanted to add printing in the menu.thanks
C++ Syntax (Toggle Plain Text)
#include<iostream.h> #include<stdlib.h> #include<conio.h> #include<stdio.h> struct node{ int x; char h[50]; //last name char fn[10]; struct node *next; }; typedef node nd; nd *head, *p, *display, *search, *update, *pointer; void insert(int num/**, char name*/) { // p=p->next; nd * temp; temp=(nd*)malloc(sizeof(nd)); temp->x=num; char lname[50];// last name char fname[50];// first name cout << "Last Name: "; cin >>lname; for( int a=0;a<sizeof(lname) ;a++) { temp->h[a]=lname[a]; } cout << "First Name: "; cin >> fname; for( int b=0;b<sizeof(fname) ;b++) { temp->fn[b]=fname[b]; } //p->next=temp; // p=p->next; if(head==NULL) { head=temp; p=head; display=p; search=p; update=p; display=update; pointer=temp; } else { p->next = temp; p=p->next; display=p; search=p; update=p; display=update; pointer=temp; } } void search_emp( int ID_search) { search->next=NULL; search=head; //p=head; //while(p!=NULL) while(search!=NULL) { if( ID_search==search->x) { cout << "\nID number: " << search->x; cout << "\nLast Name: " << search->h; cout << "\nFirst Name: " << search->fn; // search=search->next; } else if( ID_search == NULL ) { cout << " No ID Found!!! "; break; } search=search->next; } } void update_emp( int profile ) { clrscr(); int ans; do{ int new_ID; char new_lname[50]; update->next=NULL; update=head; //p=head; //while(p!=NULL) while(update!=NULL) { if( profile==update->x) { cout << "-----------------------------------------------------------\n"; cout << " UPDATE EXISTING FILE \n"; cout << "-----------------------------------------------------------\n"; cout << "\nID number: " << update->x; cout << "\nLast Name: " << update->h; cout << "\nFirst Name: " << update->fn; } update=update->next; cout << "\nChoose what to update:\n"; cout << "[1] ID Number\n"; cout << "[2] Last Name\n"; cout << "[3] First name\n"; cout << "[4] Update Again?"; cout << "[5] Exit\n"; cout << "Enter Task : "; cin >> ans; if( ans==1) { cout << "Enter new ID number: "; cin >> new_ID; update=pointer; update->x=new_ID; } else if( ans==2) { cout << " Enter new Last Name : "; cin >>new_lname; for( int a=0;a<sizeof(new_lname) ;a++) { update->h[a]=new_lname[a]; update=pointer; update->h[a]=new_lname[a]; } } } } while(ans==4); } void deleteNode(int num) { p=p->next; nd *temp; p=head; if(head->x == num) { temp=head; head=head->next; p=head; free(temp); } else { while(p!=NULL) { if(p->next->x == num) { cout << "Value to Delete: " << p->next->x; temp = p->next; p->next= p->next->next; free(temp); break; } else{ p=p->next; } } } p=head; while(p!=NULL) { cout << p->next; p=p->next; } } void main() { clrscr(); int val, select, ID, update_pro; char nm; char choice; do{ cout << "Selecte an Operation:\n"; cout << "[1] Insert value\n"; cout << "[2] View List\n"; cout << "[3] Delete node\n"; cout << "[4] Searche Employee\n"; cout << "[5] Update existing\n"; cout << "Enter choice:"; cin >> select; if(select == 1) { cout << "\nEnter ID number:"; cin >> val; // cout << "Enter Name:"; // cin >> nm; insert(val/**,nm*/); } else if( select == 2) { //p->next=NULL; display->next=NULL; display=head; //p=head; //while(p!=NULL) while(display!=NULL) { cout << "\nID number: " << display->x; cout << "\nLast Name: " << display->h; cout << "\nFirst Name: " << display->fn; display=display->next; } } else if( select == 3) { cout << " Enter ID number to be deleted: "; cin >> val; deleteNode(val); } else if( select == 4) { cout << "\nSearch by ID Number:"; cin >> ID; search_emp(ID); } else if( select == 5) { cout << "Enter Employee ID Number to update Profile: "; cin >> update_pro; update_emp(update_pro); } cout << " \nDo You Want to continue?:"; cin >> choice; }while(choice == 'y'); }
Last edited by Ancient Dragon; Oct 6th, 2007 at 9:32 am. Reason: removed color tags
what compiler are we using ? And why are we mixing C functions with c++ code? If you are going to write are c++ program then do so. Yea I know c++ language supports those c functions but its a lot better style to use all c++.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
your old DOS compiler probably supports stdprn, just as it does stdin, stdout and stderr. If so, then just print to stdprn
But your compiler can not access network printers -- the printer must be on LPT1.
C++ Syntax (Toggle Plain Text)
fprintf(stdprn,"Hello World\n");
But your compiler can not access network printers -- the printer must be on LPT1.
Last edited by Ancient Dragon; Oct 6th, 2007 at 7:08 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Removing an item from head of linked list (C)
- Inserting in a sorted linked list(sorted alphabetically) (C++)
- The C++ LINKED LIST (C++)
- To create contact manager using doubly linked list(c++) (C++)
- How to read in a sentence and insert in to linked list? (C++)
- Cannot figure out how to implement linked list and rbtree for a project! (Java)
- Linked List (C++)
- help by sorting a simply linked list (C)
Other Threads in the C++ Forum
- Previous Thread: windows api help
- Next Thread: windows api help
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






