943,929 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 609
  • C++ RSS
Sep 2nd, 2009
-3

how can i get this delete function working pls!!!

Expand Post »
i created a delete function to check for similar user id and delete one but it can seems to work, so i need your help please..

C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. #include<algorithm> //for std::sort
  3. #include<string>
  4.  
  5. using namespace std;
  6.  
  7. struct student
  8. {
  9. int id;
  10. string name;
  11. string nationality;
  12. string gender;
  13. };
  14.  
  15. void insert(student array[],const unsigned int MAX_STUDENT);
  16.  
  17. bool sortByID(const student& a, const student& b)
  18. {
  19. return ( a.id < b.id );
  20. }
  21.  
  22.  
  23. char sortByName(const student& a, const student& b)
  24. {
  25. return ( a.name < b.name);
  26. }
  27.  
  28. char sortByNationality(const student& a, const student& b)
  29. {
  30. return (a.nationality < b.nationality);
  31. }
  32.  
  33. void mySort(student array[],const unsigned int MAX)
  34. {
  35. int opt = 0;
  36. cout<<"Welcome to sorting function please do the following selection"<<endl;
  37. cout<<"***************************************************"<<endl;
  38. cout<<"* 1.Sort by student ID"<<endl;
  39. cout<<"* 2.Sort by student Name"<<endl;
  40. cout<<"* 3.Sort by Nationality"<<endl;
  41. cout<<"***************************************************"<<endl;
  42. cout<<"Selection: ";
  43. cin >> opt;
  44. cout<<"\n\n";
  45.  
  46. switch(opt)
  47. {
  48. case 1: std::sort(array,array+MAX,sortByID); break;
  49. case 2: std::sort(array,array+MAX,sortByName); break;
  50. case 3: std::sort(array,array+MAX,sortByNationality);break;
  51. }
  52.  
  53. }
  54. void delete(student array[]);
  55. void display(const student array[], unsigned int MAX);
  56. int main()
  57. {
  58. const unsigned int MAX_SIZE = 100;
  59. student array[MAX_SIZE];
  60.  
  61. int option = 0;
  62. bool exitProgram = false;
  63.  
  64. do
  65. {
  66. cout <<"Welcome to student recording system"<<endl;
  67. cout <<"Please choose one of the following option\n\n"<<endl;
  68. cout <<"1.Insert new record"<<endl;
  69. cout <<"2.Sort record"<<endl;
  70. cout <<"3.Delete record"<<endl;
  71. cout <<"4.Display record"<<endl;
  72. cout <<"0) Exit program\n\n\n";
  73.  
  74. cin >> option;
  75.  
  76. switch(option)
  77. {
  78. case 1: insert(array,MAX_SIZE); break;
  79.  
  80. case 2: cout<<"you picked sorting\n";
  81. cout<<"Now sorting\n\n\n";
  82. mySort(array,MAX_SIZE);
  83. cout<<"Sorting done\n\n\n";
  84. break;
  85.  
  86. case 3: delete(array); break;
  87. case 4: display(array,MAX_SIZE); break;
  88.  
  89. default : exitProgram = true; break;
  90. }
  91.  
  92. }while(!exitProgram);
  93.  
  94.  
  95. return 0;
  96.  
  97. }
  98. void insert(student array[],const unsigned int MAX_STUDENT)
  99. {
  100.  
  101. cout<<"\n\n";
  102.  
  103. for(unsigned int i = 0 ; i < MAX_STUDENT; i++)
  104. {
  105.  
  106. cout<<"For student #"<<(i+1)<<endl<<endl;;
  107. cout <<"Enter student ID: ";
  108. cin >>array[i].id;
  109. cin.ignore(100,'\n');
  110. cout<<endl;
  111.  
  112. cout <<"Enter student name: ";
  113. cin >>array[i].name;
  114. cin.ignore(100,'\n');
  115. cout<<endl;
  116.  
  117. cout <<"Enter student nationality: ";
  118. cin >>array[i].nationality;
  119. cin.ignore(100,'\n');
  120. cout<<endl;
  121.  
  122. cout <<"Enter student gender: ";
  123. cin >>array[i].gender;
  124. cin.ignore(100,'\n');
  125. cout<<endl;
  126. }
  127. }
  128.  
  129. void display(const student array[], unsigned int MAX)
  130. {
  131. cout<<"\\************************************************\\"<<endl;
  132. for(unsigned int i = 0; i < MAX; i++)
  133. {
  134. cout<<"---------------------------------------------------"<<endl;;
  135. cout<<"Student #:"<<(i+1)<<endl;
  136. cout<<"ID# : "<<array[i].id<<endl;
  137. cout<<"Name : "<<array[i].name<<endl;
  138. cout<<"Nationality : "<<array[i].nationality<<endl;
  139. cout<<"Gender : "<<array[i].gender<<endl<<endl;
  140. cout<<"---------------------------------------------------"<<endl;;
  141.  
  142. }
  143. cout<<"\n\\************************************************\\"<<endl;
  144. }
  145.  
  146. void delete(student array[])
  147. {
  148. char s2=" ";
  149. =" ";
  150. strcpy(s1,s2)
  151. " "
  152. }
Similar Threads
Reputation Points: -13
Solved Threads: 0
Light Poster
xfreebornx is offline Offline
38 posts
since Jul 2009
Sep 2nd, 2009
1

Re: how can i get this delete function working pls!!!

delete is a C++ keyword so use a different identifier other than
delete.

and also use the delete keyword to delete the arrays that you no
longer using. ( I mean inside that function ). Otherwise you will
get memory leaks.
Reputation Points: 86
Solved Threads: 43
Posting Pro
NicAx64 is offline Offline
532 posts
since Mar 2009
Sep 4th, 2009
0

Re: how can i get this delete function working pls!!!

void delete(student array[]) --> change function name
{
char s2=" ";
=" "; --> is it s1 declared here?
strcpy(s1,s2)-->> what its mean copying null to null??
" " -->>>what is this means?
}
Reputation Points: 10
Solved Threads: 1
Newbie Poster
emirpp is offline Offline
2 posts
since Sep 2009
Sep 4th, 2009
0

Re: how can i get this delete function working pls!!!

First look at the discussion in this thread, which as of this writing is right below yours.

Then write some code, post it, and we'll go from there.
Reputation Points: 1268
Solved Threads: 228
Posting Virtuoso
vmanes is offline Offline
1,895 posts
since Aug 2007
Sep 4th, 2009
0

Re: how can i get this delete function working pls!!!

Also look at all of your other threads on the exact same topic on Daniweb, as well as on other forums. Sometimes people are answering on oher forums at the same time you have them open on Daniweb.

http://www.daniweb.com/forums/thread214624.html
http://www.daniweb.com/forums/thread214486.html
http://www.daniweb.com/forums/thread214440.html
http://www.daniweb.com/forums/thread214101.html
http://www.daniweb.com/forums/thread213808.html


http://www.codeguru.com/forum/showth...hreadid=483563
http://www.cplusplus.com/forum/general/13911/

People spend time giving you help, then you tend not to bother responding and just start a new thread, often not taking the advice in the previous threads and just hoping someone will do the whole thing for you. Other people, not knowing about the other threads, waste time giving the same advice or close to it. And you STILL refuse to ask anything resembling a question in your posts. Just "it doesn't work".

Stop being selfish and wasting other people's time. Show you're willing some effort into this.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
Sep 4th, 2009
0

Re: how can i get this delete function working pls!!!

In this particular thread that VernonDozier posted above:

http://www.daniweb.com/forums/thread214101.html

look at post # 12 by Ancient Dragon where he gives you two possible explanations as to how you could go about creating a delete function. I'm not a betting man, but I'm willing to bet that if you look at either of those suggestions and then try to write your own code and post it here, these guys (myself included, if I can) will be willing to help.

-D
Reputation Points: 55
Solved Threads: 7
Junior Poster in Training
dgr231 is offline Offline
76 posts
since Aug 2009
Sep 4th, 2009
0

Re: how can i get this delete function working pls!!!

okay guys tnx for all ur comments i appreciate!!
Reputation Points: -13
Solved Threads: 0
Light Poster
xfreebornx is offline Offline
38 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Reading a file into an array
Next Thread in C++ Forum Timeline: requiring date validating program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC