Advertisement
chunyin_Lee

Untitled

Jan 2nd, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<cmath>
  6. #include <cstddef>
  7. using std::string;
  8. using std::getline;
  9. using namespace std;
  10. string name[101] = { "" };
  11. string email[101] = { "" };
  12. string tele[101] = { "" };
  13. int menu()
  14. {
  15. int k;
  16.  
  17. cout << endl << endl << "***********MAIN MENU***********" << endl;
  18. cout << "1. Initialize the address book" << endl;
  19. cout << "2. Create person contact information" << endl;
  20. cout << "3. Lookup person contact inforamtion" << endl;
  21. cout << "4. Look all person contact inforamtion" << endl;
  22. cout << "5. Quit " << endl;
  23. cout << endl << "Please enter your chioce <1, 2, 3, 4 or 5 to exit :" << endl;
  24. cin >> k;
  25. if (k > 5 || k < 0)
  26. {
  27. cout << "Invalid input!Please enter again!";
  28. menu();
  29. }
  30. if (k == 1)
  31. {
  32. addressbook();
  33. }
  34. if (k == 2)
  35. {
  36. cpersoninfo();
  37. }
  38. if (k == 3)
  39. {
  40. lpersoninfo();
  41. }
  42. if (k == 4)
  43. {
  44. lapersoninfo();
  45. }
  46. if (k == 5)
  47. {
  48. cout << "Goodbye";
  49. return 0;
  50. }
  51. }
  52. void addressbook()
  53. {
  54. int i;
  55.  
  56. name[1] = {"Lawrence Cheung"};
  57. cout << "Name is : " << name[1] << endl;
  58. email[1] = { "enccl@eie.polyu.edu.hk" };
  59. cout << "Email is : " << email[1] << endl;
  60. tele[1] = { "27666131" };
  61. cout << "Telephone number is : " << tele[1];
  62.  
  63. name[2] = { "Helen Wong" };
  64. cout << "Name is : " << name[2] << endl;
  65. email[2] = { "helenwong@yahoo.com.hk" };
  66. cout << "Email is : " << email[2] << endl;
  67. tele[2] = { "94665888" };
  68. cout << "Telephone number is : " << tele[2];
  69.  
  70. name[3] = { "Simon Sui"};
  71. cout << "Name is : " << name[3] << endl;
  72. email[3] = { "ss123@gmail.com" };
  73. cout << "Email is : " << email[3] << endl;
  74. tele[3] = { "64441234" };
  75. cout << "Telephone number is : " << tele[3];
  76.  
  77. name[4] = {"Mary Ho" };
  78. cout << "Name is : " << name[4] << endl;
  79. email[4] = { "ho.mary10@netvigator.com" };
  80. cout << "Email is : " << email[4] << endl;
  81. tele[4] = { "21111112" };
  82. cout << "Telephone number is : " << tele[4];
  83.  
  84. for (i = 5;i < 102;i++)
  85. {
  86. name[i] = {""};
  87. email[i] = {""};
  88. tele[i] = {""};
  89. }
  90. cout << "Initialization is completed ." << endl;
  91. menu();
  92. }
  93. void cpersoninfo()
  94. {
  95. int max;
  96. int ii;
  97. int count = 1;
  98. size_t pos = 0, pos1 = 0;
  99.  
  100. cout << "Please enter the total number of records to be created";
  101. cin >> max;
  102. if(max > 0 || max<11)
  103. {
  104. for (int ii = count;ii <= max+count;ii++)
  105. {
  106. cout << "Full name : ";
  107. cin >> name[ii];
  108. size_t found= name[ii].find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQSTUVWXYZ ");
  109. while(found != std::string::npos)
  110. {
  111. cout << "Invalid input!Please enter again!"<<endl;
  112. cin >> name[ii];
  113. size_t found = name[ii].find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQSTUVWXYZ ");
  114. }
  115. cout << "Email address : ";
  116. cin >> email[ii];
  117. pos = email[ii].find('@', 0);
  118. while (pos == string::npos || pos == 0 || pos + 1 == email[ii].length())
  119. {
  120. cout << "Invalid input!Please enter again!" << endl;
  121. cin >> email[ii];
  122. }
  123. cout << "8-digit telephone number : ";
  124. cin >> tele[ii];
  125. size_t found1 = tele[ii].find_first_not_of("0123456789 ");
  126. pos1 = tele[ii].find('0', 0);
  127. while (found1 != std::string::npos || tele[ii].length != 8||pos1==0)
  128. {
  129. cout << "Invalid input!Please enter again!" << endl;
  130. cin >> tele[ii];
  131. }
  132. }
  133. count = count + ii;
  134. ii = 0;
  135. }
  136. else
  137. {
  138. while (max < 0 || max>10)
  139. {
  140. cout << "The input is invalid . It must be an integer not greater than 10 .";
  141. cout << "Please enter the total number of records to be created";
  142. cin >> max;
  143. }
  144.  
  145. }
  146. }
  147. void lpersoninfo()
  148. {
  149. int q = 0;
  150. int findname = 0;
  151. int findemail = 0;
  152. int findtele = 0;
  153. string kk = "a";
  154. string NAME = "";
  155. string EMAIL = "";
  156. string TELE = "";
  157. while (kk == "a" || kk == "A" || kk == "b" || kk == "B" || kk == "c" || kk == "C")
  158. {
  159. cout << endl << endl << "***********SUB-MENU***********" << endl;
  160. cout << "a. Search record by name " << endl;
  161. cout << "b. Search record by email address " << endl;
  162. cout << "c. Search record by telephone number" << endl;
  163. cout << "d. Return to main menu" << endl << endl;
  164. cout << "Please enter your chioce < a, b, c or d to return> : ";
  165.  
  166. getline(cin, kk);
  167. size_t found2 = kk.find_first_not_of("abcdABCD ");
  168. while (found2 != std::string::npos || kk.length != 1)
  169. {
  170. cout << "Invalid input!Please enter again!" << endl;
  171. cin >> kk;
  172. }
  173. if (kk == "a" || kk == "A")
  174. {
  175. cout << "Please enter a name to search" << endl;
  176. cin >> NAME;
  177. for (q = 0;q <= 101;q++)
  178. {
  179. if (NAME == name[q])
  180. {
  181. cout << "A record is found!" << endl;
  182. cout << "Email address is : " << email[q] << endl;
  183. cout << "Telephone number is : " << tele[q] << endl;
  184. findname = 1;
  185.  
  186. break;
  187. }
  188.  
  189. }
  190. if (findname == 0)
  191. {
  192. cout << "Sorry, no record is found !" << endl;
  193. }
  194. findname = 0;
  195. q = 0;
  196. }
  197. if (kk == "b" || kk == "B")
  198. {
  199. cout << "Please enter an email to search" << endl;
  200. cin >> EMAIL;
  201. for (q = 0;q <= 101;q++)
  202. {
  203. if (EMAIL == email[q])
  204. {
  205. cout << "A record is found!" << endl;
  206. cout << "Full name is : " << name[q] << endl;
  207. cout << "Telephone number is : " << tele[q] << endl;
  208. findemail = 1;
  209. break;
  210. }
  211.  
  212. }
  213. if (findemail == 0)
  214. {
  215. cout << "Sorry, no record is found !" << endl;
  216. }
  217. findemail = 0;
  218. q = 0;
  219.  
  220.  
  221.  
  222. }
  223. if (kk == "c" || kk == "C")
  224. {
  225. cout << "Please enter a telephone number to search" << endl;
  226. cin >> TELE;
  227. for (q = 0;q <= 101;q++)
  228. {
  229. if (TELE == tele[q])
  230. {
  231. cout << "A record is found!" << endl;
  232. cout << "Full name is : " << name[q] << endl;
  233. cout << "Email address is : " << email[q] << endl;
  234. findtele = 1;
  235. break;
  236. }
  237.  
  238. }
  239. if (findtele == 0)
  240. {
  241. cout << "Sorry, no record is found !" << endl;
  242. }
  243. findtele = 0;
  244. q = 0;
  245.  
  246.  
  247. }
  248. if (kk == "d" || kk == "D")
  249. {
  250. menu();
  251. }
  252. }
  253. }
  254. void lapersoninfo()
  255. {
  256. int q = 0;
  257. for (q = 0;q <= 101;q++)
  258. {
  259. if (name[q] != "")
  260. {
  261. cout << "Full name is : " << name[q] << endl;
  262. cout << "Email address is : " << email[q] << endl;
  263. cout << "Telephone number is : " << tele[q] << endl;
  264. }
  265. }
  266. menu();
  267. }
  268.  
  269. int main()
  270. {
  271. menu();
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement