NEED help pls. about linked list

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2007
Posts: 21
Reputation: louise07 has a little shameless behaviour in the past 
Solved Threads: 1
louise07 louise07 is offline Offline
Newbie Poster

NEED help pls. about linked list

 
0
  #1
Oct 6th, 2007
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

  1. #include<iostream.h>
  2. #include<stdlib.h>
  3. #include<conio.h>
  4. #include<stdio.h>
  5. struct node{
  6. int x;
  7. char h[50]; //last name
  8. char fn[10];
  9. struct node *next;
  10. };
  11. typedef node nd;
  12. nd *head, *p, *display, *search, *update, *pointer;
  13. void insert(int num/**, char name*/)
  14. {
  15. // p=p->next;
  16. nd * temp;
  17. temp=(nd*)malloc(sizeof(nd));
  18. temp->x=num;
  19. char lname[50];// last name
  20. char fname[50];// first name
  21. cout << "Last Name: ";
  22. cin >>lname;
  23. for( int a=0;a<sizeof(lname) ;a++)
  24. {
  25. temp->h[a]=lname[a];
  26. }
  27. cout << "First Name: ";
  28. cin >> fname;
  29. for( int b=0;b<sizeof(fname) ;b++)
  30. {
  31. temp->fn[b]=fname[b];
  32. }
  33. //p->next=temp;
  34. // p=p->next;
  35.  
  36. if(head==NULL)
  37. {
  38. head=temp;
  39. p=head;
  40. display=p;
  41. search=p;
  42. update=p;
  43. display=update;
  44. pointer=temp;
  45. }
  46. else
  47. {
  48. p->next = temp;
  49. p=p->next;
  50. display=p;
  51. search=p;
  52. update=p;
  53. display=update;
  54. pointer=temp;
  55. }
  56. }
  57. void search_emp( int ID_search)
  58. {
  59. search->next=NULL;
  60. search=head;
  61. //p=head;
  62. //while(p!=NULL)
  63. while(search!=NULL)
  64. {
  65. if( ID_search==search->x)
  66. {
  67. cout << "\nID number: " << search->x;
  68. cout << "\nLast Name: " << search->h;
  69. cout << "\nFirst Name: " << search->fn;
  70. // search=search->next;
  71. }
  72. else if( ID_search == NULL )
  73. {
  74. cout << " No ID Found!!! ";
  75. break;
  76. }
  77. search=search->next;
  78. }
  79. }
  80. void update_emp( int profile )
  81. {
  82. clrscr();
  83. int ans;
  84. do{
  85. int new_ID;
  86. char new_lname[50];
  87. update->next=NULL;
  88. update=head;
  89. //p=head;
  90. //while(p!=NULL)
  91. while(update!=NULL)
  92. {
  93. if( profile==update->x)
  94. {
  95. cout << "-----------------------------------------------------------\n";
  96. cout << " UPDATE EXISTING FILE \n";
  97. cout << "-----------------------------------------------------------\n";
  98. cout << "\nID number: " << update->x;
  99. cout << "\nLast Name: " << update->h;
  100. cout << "\nFirst Name: " << update->fn;
  101. }
  102. update=update->next;
  103. cout << "\nChoose what to update:\n";
  104. cout << "[1] ID Number\n";
  105. cout << "[2] Last Name\n";
  106. cout << "[3] First name\n";
  107. cout << "[4] Update Again?";
  108. cout << "[5] Exit\n";
  109. cout << "Enter Task : ";
  110. cin >> ans;
  111. if( ans==1)
  112. {
  113. cout << "Enter new ID number: ";
  114. cin >> new_ID;
  115. update=pointer;
  116. update->x=new_ID;
  117. }
  118. else if( ans==2)
  119. {
  120. cout << " Enter new Last Name : ";
  121. cin >>new_lname;
  122. for( int a=0;a<sizeof(new_lname) ;a++)
  123. {
  124. update->h[a]=new_lname[a];
  125. update=pointer;
  126. update->h[a]=new_lname[a];
  127. }
  128. }
  129. }
  130. }
  131. while(ans==4);
  132. }
  133.  
  134. void deleteNode(int num)
  135. { p=p->next;
  136. nd *temp;
  137. p=head;
  138. if(head->x == num)
  139. {
  140. temp=head;
  141. head=head->next;
  142. p=head;
  143. free(temp);
  144. }
  145. else
  146. {
  147. while(p!=NULL)
  148. {
  149. if(p->next->x == num)
  150. {
  151. cout << "Value to Delete: " << p->next->x;
  152. temp = p->next;
  153. p->next= p->next->next;
  154. free(temp);
  155. break;
  156. }
  157. else{
  158. p=p->next;
  159. }
  160. }
  161. }
  162. p=head;
  163. while(p!=NULL)
  164. {
  165. cout << p->next;
  166. p=p->next;
  167. }
  168. }
  169. void main()
  170. {
  171. clrscr();
  172. int val, select, ID, update_pro;
  173. char nm;
  174. char choice;
  175. do{
  176. cout << "Selecte an Operation:\n";
  177. cout << "[1] Insert value\n";
  178. cout << "[2] View List\n";
  179. cout << "[3] Delete node\n";
  180. cout << "[4] Searche Employee\n";
  181. cout << "[5] Update existing\n";
  182. cout << "Enter choice:";
  183. cin >> select;
  184. if(select == 1)
  185. {
  186. cout << "\nEnter ID number:";
  187. cin >> val;
  188. // cout << "Enter Name:";
  189. // cin >> nm;
  190. insert(val/**,nm*/);
  191. }
  192. else if( select == 2)
  193. {
  194. //p->next=NULL;
  195. display->next=NULL;
  196. display=head;
  197. //p=head;
  198. //while(p!=NULL)
  199. while(display!=NULL)
  200. {
  201. cout << "\nID number: " << display->x;
  202. cout << "\nLast Name: " << display->h;
  203. cout << "\nFirst Name: " << display->fn;
  204. display=display->next;
  205. }
  206. }
  207. else if( select == 3)
  208. {
  209. cout << " Enter ID number to be deleted: ";
  210. cin >> val;
  211. deleteNode(val);
  212. }
  213. else if( select == 4)
  214. {
  215. cout << "\nSearch by ID Number:";
  216. cin >> ID;
  217. search_emp(ID);
  218. }
  219. else if( select == 5)
  220. {
  221. cout << "Enter Employee ID Number to update Profile: ";
  222. cin >> update_pro;
  223. update_emp(update_pro);
  224. }
  225. cout << " \nDo You Want to continue?:";
  226. cin >> choice;
  227. }while(choice == 'y');
  228. }
Last edited by Ancient Dragon; Oct 6th, 2007 at 9:32 am. Reason: removed color tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,484
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: NEED help pls. about linked list

 
0
  #2
Oct 6th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 21
Reputation: louise07 has a little shameless behaviour in the past 
Solved Threads: 1
louise07 louise07 is offline Offline
Newbie Poster

Re: NEED help pls. about linked list

 
0
  #3
Oct 6th, 2007
we're using the old dos compiler. this is our project. and were having difficulty in that part. about that print thinggy coz we wrenot taught bout that
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,484
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: NEED help pls. about linked list

 
0
  #4
Oct 6th, 2007
your old DOS compiler probably supports stdprn, just as it does stdin, stdout and stderr. If so, then just print to stdprn
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 21
Reputation: louise07 has a little shameless behaviour in the past 
Solved Threads: 1
louise07 louise07 is offline Offline
Newbie Poster

Re: NEED help pls. about linked list

 
0
  #5
Oct 6th, 2007
thanks alot.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC