Advertisement
chunyin_Lee

Untitled

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