help me with this....

Thread Solved

Join Date: Mar 2008
Posts: 4
Reputation: mengmarc is an unknown quantity at this point 
Solved Threads: 0
mengmarc mengmarc is offline Offline
Newbie Poster

help me with this....

 
0
  #1
Apr 1st, 2008
The problem:
Given a list of imployees, create a simple program that allows the user to insert, delete, display and search an employee. The prog. shall display 10 imployees as default. Also a list of menu should be display. The menu names are insert, delete, dsplay and search.

My questions are:
1. what syntax should i use to insert character that allows 'space'?
2. is there a syntax that can 'search' name within a list,,, what is it?

*ideally, it should delete the list or name with a 'current node'.
*the bold part of the prog. is my problem....'searchng to a list'.

i created this prog. guided by the notes given to me.

  1. #include <iostream.h>
  2. struct node
  3. {
  4. char name[50], search[50];
  5. node *nxt;
  6. };
  7.  
  8. node *strtPtr = NULL;
  9. node *current;
  10. int choice;
  11.  
  12. void insert()
  13. {
  14. node *emp,*emp1;
  15. emp=new node;
  16. cout<<"Name of Employee:\n";
  17. cin>>emp->name;
  18. emp->nxt=NULL;
  19. if(strtPtr==NULL)
  20. {
  21. strtPtr=emp;
  22. current=strtPtr;
  23. }
  24. else
  25. {
  26. emp1= strtPtr;
  27. while(emp1->nxt != NULL)
  28. {
  29. emp1=emp1->nxt;
  30. }
  31. emp1->nxt = emp;
  32. current=emp;
  33. }
  34. cout<<"\n\n";
  35. }
  36.  
  37. void display()
  38. {
  39. node *emp;
  40. emp=strtPtr;
  41. cout<<"\nList of the Employees: \n";
  42. if(emp==NULL)
  43. cout<<"List is empty\a\a\n\n";
  44. else
  45. {
  46. while(emp!=NULL)
  47. {
  48. cout<<emp->name;
  49. if(emp==current)
  50. cout<<" <---";
  51. cout<<endl;
  52. emp=emp->nxt;
  53. }
  54. cout<<"\nEnd of List\n\n\n";
  55. }
  56. }
  57.  
  58. void del()
  59. {
  60. node *emp, *emp1;
  61. current=strtPtr;
  62. if(strtPtr==NULL)
  63. cout<<"The List is empty\a\a\n";
  64. else
  65. {
  66. emp=strtPtr;
  67. if(emp->nxt==NULL)
  68. {
  69. delete emp;
  70. strtPtr=NULL;
  71. }
  72. else
  73. {
  74. while(emp->nxt!=NULL)
  75. {
  76. emp1=emp;
  77. emp=emp->nxt;
  78. }
  79. delete emp;
  80. emp1->nxt=NULL;
  81. }
  82. }
  83. }
  84.  
  85. void search()
  86. {
  87. node *emp,*emp1;
  88. emp=strtPtr;
  89. if(emp==NULL)
  90. {
  91. cout<<"List is empty\a\a\n\n";
  92. }
  93. else
  94. {
  95. emp1=new node;
  96. cout<<"Search (name): ";
  97. cin>>emp1->search;
  98. cout<<endl;
  99. if(emp==emp1)
  100. {
  101. emp=current;
  102. }
  103. else
  104. {
  105. while(emp!=emp1)
  106. {
  107. emp=emp->nxt;
  108. emp->nxt=emp1;
  109. current=emp;
  110. }
  111. }
  112. }
  113. }
  114.  
  115. void main()
  116. {
  117. strtPtr=NULL;
  118. do
  119. {
  120. cout<<"Select your option\n"
  121. <<"[0] Exit\n"
  122. <<"[1] Insert new employee\n"
  123. <<"[2] Display list of employees\n"
  124. <<"[3] Delete employee\n"
  125. <<"[4] Search employee\n\n>>";
  126. cin>>choice;
  127. cout<<"\n";
  128.  
  129. switch(choice)
  130. {
  131. case 1: insert(); break;
  132. case 2: display(); break;
  133. case 3: del(); break;
  134. case 4: search(); break;
  135. }
  136. }
  137. while(choice != 0);
  138. }

Sir/madam, i'm new in making c++ program...hope you can help me with this... thank you..God bless..
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 8,313
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 824
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: help me with this....

 
0
  #2
Apr 1st, 2008
>1. what syntax should i use to insert character that allows 'space'?
cin.getline:
  1. cin.getline ( emp->name, 50 );
>2. is there a syntax that can 'search' name within a list,,, what is it?
It's called a loop:
  1. node *it = strtPtr;
  2.  
  3. while ( it != 0 ) {
  4. if ( strcmp ( it->name, key ) == 0 )
  5. break;
  6.  
  7. it = it->nxt;
  8. }
  9.  
  10. if ( it != 0 )
  11. cout<<"Found '"<< it->name <<"'\n";
And if I may be so bold, is there a shortage of vowels on your system? nxt and strtPtr are exceptionally annoying to type and read.
In case you were wondering, yes, I do hate you.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 280
Reputation: Traicey is an unknown quantity at this point 
Solved Threads: 19
Traicey's Avatar
Traicey Traicey is offline Offline
Posting Whiz in Training

Re: help me with this....

 
0
  #3
Apr 1st, 2008
1. what syntax should i use to insert character that allows 'space'?
U can declare ur variables using string or even character (eg) string Name; and if u gona accept it from the user u can achieve that by this getline(cin, Name) or if u just want to right u can also use getline() method
geline(Name);

2. is there a syntax that can 'search' name within a list,,, what is it?
Yes there is a way U can use a comparison of variables with boolean to search
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 8,313
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 824
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: help me with this....

 
0
  #4
Apr 1st, 2008
Traicey, that's all well and good, if the OP's compiler supports the string class, which it may not as shown by the use of the pre-standard iostream.h header.
In case you were wondering, yes, I do hate you.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 4
Reputation: mengmarc is an unknown quantity at this point 
Solved Threads: 0
mengmarc mengmarc is offline Offline
Newbie Poster

Re: help me with this....

 
0
  #5
Apr 1st, 2008
tnx guys...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 488 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC