View Single Post
Join Date: May 2008
Posts: 13
Reputation: nouryn is an unknown quantity at this point 
Solved Threads: 0
nouryn nouryn is offline Offline
Newbie Poster

Re: help in phonebook

 
0
  #3
May 5th, 2008
i don't have a clue a bout the sort i've tried many functions from the internet but they didn't work but i've began in the other function in the phone book and that is what i get thnx




  1. #include<iostream>
  2. #include<string>
  3. #include<fstream>
  4. #include<algorithm>
  5. using namespace std;
  6. fstream phonebook;
  7. struct phone
  8. {
  9. char word[50];
  10. char fword[50];
  11. fstream edit;
  12. int id;
  13. string fname;
  14. string sname;
  15. string lname;
  16. int phonenumber;
  17. int mobilenumber;
  18. string email;
  19. };
  20.  
  21. phone info;
  22. char d,f,r;
  23. string c,g;
  24.  
  25. int add()
  26. {
  27. phonebook.open("c:\\c\\phonebook.txt",ios::out|ios::app);
  28. cout<<"enter the first name\n";
  29. cin>>info.fname;
  30. cout<<"enter the second name\n";
  31. cin>>info.sname;
  32. cout<<"enter the last name\n";
  33. cin>>info.lname;
  34. cout<<"enter the phone number\n";
  35. cin>>info.phonenumber;
  36. cout<<"enter the moile number\n";
  37. cin>>info.mobilenumber;
  38. cout<<"enter the e-mail\n";
  39. cin>>info.email;
  40.  
  41. phonebook<<info.fname<<"\t "<<info.sname<<"\t "<<info.lname<<" \t "
  42. <<info.phonenumber<<" \t "<<info.mobilenumber<<" \t "<<info.email<<endl;;
  43. cout<<endl;
  44. phonebook.close();
  45.  
  46. return 0;
  47. }
  48.  
  49. int getdisplay()
  50. {
  51.  
  52. cout<<"if u wanna display all contacts press 'a'\n"<<"if u wanna display contacts begining with specific letter press 'c'\n";
  53. cin>>r;
  54. phonebook.open("c:\\c\\phonebook.txt",ios::in);
  55. phonebook.clear();
  56. switch(r)
  57. {
  58.  
  59. case 'a':
  60. {
  61. while(!phonebook.eof())
  62. {
  63. getline(phonebook,c);
  64. cout<<c<<endl;
  65. }
  66. phonebook.close();
  67. break;
  68. }
  69. case 'c':
  70. {
  71.  
  72. phonebook.open("c:\\c\\phonebook.txt",ios::in);
  73. phonebook>>c;
  74. cout<<"enter the wanted letter";
  75. cin>>g;
  76. // getdisplay;
  77. cout<<"dsucyeehr";
  78.  
  79.  
  80. phonebook.close();
  81. break;
  82. }
  83. }
  84. return 0;
  85.  
  86. }
  87. void getsearch()
  88. {
  89. cout << "Enter your contact:"<<endl;
  90.  
  91. cin >> info.word;
  92. phonebook.open("c:\\c\\phonebook.txt",ios::in);
  93. phonebook.clear();
  94. int counter =0;
  95. while (!phonebook.eof()){
  96. phonebook >> info.fword;
  97. int j=strcmp(info.fword,info.word);
  98. if (j==0){
  99. cout << "contact was found in the file :)"<<endl;
  100. cout<< info.word << endl;
  101. counter ++;
  102. phonebook>>info.fname>>info.sname>>info.lname>>info.phonenumber>>info.mobilenumber>>info.email;
  103. cout<<info.fword<<" "<<info.fname<<" "<<info.sname<<" "<<info.lname
  104. <<" "<<info.phonenumber<<" "<<info.mobilenumber<<" "<<info.email;
  105. break;
  106. }
  107. }
  108. if (counter == 0)
  109. cout << "contact was not found in the file :(" << endl;
  110.  
  111.  
  112. phonebook.close();
  113.  
  114.  
  115. }
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. int main()
  123. {
  124.  
  125.  
  126. while(1)
  127. {
  128.  
  129.  
  130. cout<<endl<<"1-Adding new contacts"<<endl
  131. <<"2-Displaying contacts information"<<endl
  132. <<"3-Searching for a contact"<<endl
  133. <<"4-Deleting a contact"<<endl
  134. <<"5-Modifying a contact information"<<endl
  135. <<"6-Sort the contacts by name"<<endl
  136. <<"7-exit"<<endl<<endl;
  137. cout<<"enter your choice"<<endl;
  138. cin>>d;
  139. switch(d)
  140.  
  141. {
  142. case '1':
  143.  
  144. {
  145. add();
  146. cout<<"if u wann add another contact press 'y' if not press 'n'";
  147. cin>>f;
  148. if(f=='y')
  149.  
  150. {
  151. add();
  152. }
  153.  
  154. break;
  155. }
  156. case '2':
  157. {
  158. getdisplay();
  159. break;
  160. }
  161. case '3':
  162. {
  163. getsearch();
  164.  
  165. break;
  166.  
  167. }
  168. case '4':
  169. {
  170. break;
  171. }
  172. case '5':
  173. {
  174. break;
  175. }
  176. case '6':
  177. {
  178.  
  179. break;
  180. }
  181. case '7':
  182. {
  183. return 0;
  184. break;
  185. }
  186. }
  187. }
  188.  
  189. system ("pause");
  190. return 0;
  191. }
Last edited by Ancient Dragon; May 7th, 2008 at 1:01 pm. Reason: add code tags
Reply With Quote