经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » C++ » 查看文章
C++使用链表存储实现通讯录功能管理
来源:jb51  时间:2022/6/20 19:56:21  对本文有异议

本文实例为大家分享了C++使用链表存储实现通讯录功能管理的具体代码,供大家参考,具体内容如下

简介

这是第二周老师给的一个小项目要求实现基本通讯录功能,有数据的增删改查,包含插入时间的能力。

代码详情

头文件

  1. #include <iostream>
  2. #include <string>
  3. #include<malloc.h> //system功能调用?
  4. #include <windows.h> //使用本地系统API获取插入时间?
  5. #include <sstream>

基本存储结构体

  1. typedef struct info{
  2. ?? ?string number;
  3. ?? ?string date;
  4. ?? ?string name;
  5. ?? ?string adress;
  6. ?? ?string birthday;?
  7. }A;
  8. typedef struct LNode{
  9. ?? ?A data;?
  10. ? ? struct LNode *next;
  11. }LNode,*LinkList;

链表数据初始化
用前插法插入数据

  1. int InitList(LinkList &L){ //初始化链表?
  2. ?? ?L = new LNode;
  3. ?? ?L->next = NULL;
  4. ?? ?return OK;
  5. }
  6. int ListInsert(LinkList &L,string name,string adress,string birthday,string date,string number){ //考虑使用数组来赋值?
  7. ?? ?LinkList p; p= new LNode;
  8. ?? ?p->data.name = name;
  9. ?? ?p->data.adress = adress;
  10. ?? ?p->data.date = date;
  11. ?? ?p->data.birthday = birthday;
  12. ?? ?p->data.number = number;
  13. ?? ?p->next = L->next;
  14. ?? ?L->next = p;
  15. ?? ?return OK;
  16. }?

本地WindowsAPI调用插入时间

  1. SYSTEMTIME sys;?
  2. GetLocalTime( &sys );
  3. string y = doubleToString(sys.wYear);
  4. string m = doubleToString(sys.wMonth);
  5. string d = doubleToString(sys.wDay);
  6. string ymd = y+"-"+m+"-"+d;

因为获取的是一个double值,您得对其时间强制类型转换

  1. string doubleToString(double num)
  2. { //强制类型转换 double强制转换为string类型?
  3. ? ? stringstream ss;
  4. ? ? string str;
  5. ? ? ss << num;
  6. ? ? ss >> str;
  7. ? ? return str;
  8. }

数据查询功能

  1. LinkList SearchElemChar(LinkList L,int i,string e){ //思路,传递参数1,2,3,4,eg 1代表name,再分不同的方法在链表内循环查找操作?
  2. ?if (i == 1){ //查名字?
  3. ??? ?while(L!= NULL){
  4. ??? ??? ?if(L->data.name == e){
  5. ??? ??? ??? ?return L;?
  6. ?? ??? ? }else{
  7. ?? ??? ? L = L->next;
  8. ?? ??? ? }
  9. ??? ??? ?}
  10. ??? ??? ?if(L = NULL){
  11. ??? ??? ??? ?cout << "未查到数据!"<<endl;
  12. ?? ??? ? }
  13. ?}else if(i == 2){//查生日?
  14. ??? ?while(L!= NULL){
  15. ??? ??? ?if(L->data.birthday == e){
  16. ??? ??? ??? ?return L;?
  17. ?? ??? ? }else{
  18. ?? ??? ? L = L->next;
  19. ?? ??? ? }
  20. ??? ??? ?}
  21. ??? ??? ?if(L = NULL){
  22. ??? ??? ?cout <<"未查到数据!"<<endl;
  23. ?? ??? ? }
  24. ?}
  25. ?else if(i == 3){//查地址?
  26. ??? ?while(L!= NULL){
  27. ??? ??? ?if(L->data.adress == e){
  28. ??? ??? ??? ?return L;?
  29. ?? ??? ? }else{
  30. ?? ??? ? L = L->next;
  31. ?? ??? ? }
  32. ??? ??? ?}
  33. ??? ??? ?if(L = NULL){
  34. ??? ??? ?cout <<"未查到数据!"<<endl;
  35. ?? ??? ? }
  36. ?}else if(i == 4){//查时间?
  37. ??? ?while(L!= NULL){
  38. ??? ??? ?if(L->data.date == e){
  39. ??? ??? ??? ?return L;?
  40. ?? ??? ? }else{
  41. ?? ??? ? L = L->next;
  42. ?? ??? ? }
  43. ??? ??? ?}
  44. ??? ??? ?if(L = NULL){
  45. ??? ??? ?cout <<"未查到数据!"<<endl;
  46. ?? ??? ? }
  47. ?}
  48. ?else if(i == 5){//查电话?
  49. ??? ?while(L!= NULL){
  50. ??? ??? ?if(L->data.number == e){
  51. ??? ??? ??? ?return L;?
  52. ?? ??? ? }else{
  53. ?? ??? ? L = L->next;
  54. ?? ??? ? }
  55. ??? ??? ?}
  56. ??? ??? ?if(L = NULL){
  57. ??? ??? ?cout <<"未查到数据!"<<endl;
  58. ?? ??? ? }
  59. ?}
  60. ?
  61. }?

完整案例

  1. //乐公第二周项目 实现基本通讯录存储结构?
  2. //基础链表存储数据
  3. #include <iostream>
  4. #include <string>
  5. #include<malloc.h> //system功能调用?
  6. #include <windows.h> //使用本地系统API获取插入时间?
  7. #include <sstream>
  8. #define ERROR 0
  9. #define OK 1
  10. using namespace std;
  11. typedef ?int ElemType; /*定义表元素的类型*/
  12. //结构体文件
  13. typedef struct info{
  14. ?? ?string number;
  15. ?? ?string date;
  16. ?? ?string name;
  17. ?? ?string adress;
  18. ?? ?string birthday;?
  19. }A;
  20. typedef struct LNode{
  21. ?? ?A data;?
  22. ? ? struct LNode *next;
  23. }LNode,*LinkList;
  24.  
  25. int InitList(LinkList &L){ //初始化链表?
  26. ?? ?L = new LNode;
  27. ?? ?L->next = NULL;
  28. ?? ?return OK;
  29. }
  30. int ListInsert(LinkList &L,string name,string adress,string birthday,string date,string number){ //考虑使用数组来赋值?
  31. ?? ?LinkList p; p= new LNode;
  32. ?? ?p->data.name = name;
  33. ?? ?p->data.adress = adress;
  34. ?? ?p->data.date = date;
  35. ?? ?p->data.birthday = birthday;
  36. ?? ?p->data.number = number;
  37. ?? ?p->next = L->next;
  38. ?? ?L->next = p;
  39. ?? ?return OK;
  40. }?
  41. //查找元素 (难题需要解决)
  42. ?
  43. LinkList SearchElemChar(LinkList L,int i,string e){ //思路,传递参数1,2,3,4,eg 1代表name,再分不同的方法在链表内循环查找操作?
  44. ?if (i == 1){ //查名字?
  45. ??? ?while(L!= NULL){
  46. ??? ??? ?if(L->data.name == e){
  47. ??? ??? ??? ?return L;?
  48. ?? ??? ? }else{
  49. ?? ??? ? L = L->next;
  50. ?? ??? ? }
  51. ??? ??? ?}
  52. ??? ??? ?if(L = NULL){
  53. ??? ??? ??? ?cout << "未查到数据!"<<endl;
  54. ?? ??? ? }
  55. ?}else if(i == 2){//查生日?
  56. ??? ?while(L!= NULL){
  57. ??? ??? ?if(L->data.birthday == e){
  58. ??? ??? ??? ?return L;?
  59. ?? ??? ? }else{
  60. ?? ??? ? L = L->next;
  61. ?? ??? ? }
  62. ??? ??? ?}
  63. ??? ??? ?if(L = NULL){
  64. ??? ??? ?cout <<"未查到数据!"<<endl;
  65. ?? ??? ? }
  66. ?}
  67. ?else if(i == 3){//查地址?
  68. ??? ?while(L!= NULL){
  69. ??? ??? ?if(L->data.adress == e){
  70. ??? ??? ??? ?return L;?
  71. ?? ??? ? }else{
  72. ?? ??? ? L = L->next;
  73. ?? ??? ? }
  74. ??? ??? ?}
  75. ??? ??? ?if(L = NULL){
  76. ??? ??? ?cout <<"未查到数据!"<<endl;
  77. ?? ??? ? }
  78. ?}else if(i == 4){//查时间?
  79. ??? ?while(L!= NULL){
  80. ??? ??? ?if(L->data.date == e){
  81. ??? ??? ??? ?return L;?
  82. ?? ??? ? }else{
  83. ?? ??? ? L = L->next;
  84. ?? ??? ? }
  85. ??? ??? ?}
  86. ??? ??? ?if(L = NULL){
  87. ??? ??? ?cout <<"未查到数据!"<<endl;
  88. ?? ??? ? }
  89. ?}
  90. ?else if(i == 5){//查电话?
  91. ??? ?while(L!= NULL){
  92. ??? ??? ?if(L->data.number == e){
  93. ??? ??? ??? ?return L;?
  94. ?? ??? ? }else{
  95. ?? ??? ? L = L->next;
  96. ?? ??? ? }
  97. ??? ??? ?}
  98. ??? ??? ?if(L = NULL){
  99. ??? ??? ?cout <<"未查到数据!"<<endl;
  100. ?? ??? ? }
  101. ?}
  102. ?
  103. }?
  104.  
  105. LinkList SearchElemBefore(LinkList L,string e){ //删除结点必须返回前个结点的地址,这里查找前个结点?
  106. ? ? ?LinkList P;?
  107. ??? ?while(L!= NULL){
  108. ??? ??? ?if(L->data.name == e){
  109. ??? ??? ??? ?return P;?
  110. ?? ??? ? }else{
  111. ?? ??? ? P = L;
  112. ?? ??? ? L = L->next;
  113. ?? ??? ? }
  114. ??? ??? ?}
  115. ??? ??? ?if(L = NULL){
  116. ??? ??? ??? ?return L;?
  117. ?? ??? ? }
  118. }?
  119. int ShowMenu(){ //主菜单?
  120. ?? ?int a;
  121. ?? ?cout<<"------欢迎您使用乐公通讯录系统!------"<< endl;
  122. ?? ?cout <<"-----请根据功能输入对应的序号--------" <<endl;?
  123. ?? ?cout <<"-----------1.新建联系人--------------" <<endl;?
  124. ?? ?cout <<"--------2.查看所有联系人-------------" <<endl;?
  125. ?? ?cout <<"--------3.修改选定联系人-------------" <<endl;
  126. ?? ?cout <<"--------4.查询选定联系人-------------" <<endl;
  127. ?? ?cout <<"--------5.删除选定联系人-------------" <<endl;
  128. ?? ?cout <<"------------6.退出系统---------------" <<endl;?
  129. ?? ?cout << "请您输入序号并按回车进入:" ;?
  130. ?? ?cin >> a;
  131. ?? ?return a;
  132. }
  133.  
  134. string doubleToString(double num)
  135. { //强制类型转换 double强制转换为string类型?
  136. ? ? stringstream ss;
  137. ? ? string str;
  138. ? ? ss << num;
  139. ? ? ss >> str;
  140. ? ? return str;
  141. }
  142. void foreachelem(LinkList L){
  143. ?? ?if(L->next == NULL){
  144. ?? ??? ?cout<<"通讯录里还没有联系人,快去新建一下吧~"<<endl;?
  145. ?? ?}else{
  146. ?? ?while(L->next!=NULL){
  147. ?? ??? ?L=L->next;
  148. ?? ??? ?cout<< "联系人姓名:" << L->data.name <<endl;
  149. ?? ??? ?cout<< "联系人电话:" << L->data.number<<endl;
  150. ?? ??? ?cout<< "联系人地址:" << L->data.adress <<endl;
  151. ?? ??? ?cout<< "联系人生日:" << L->data.birthday <<endl;
  152. ?? ??? ?cout<< "录入时间:" << L->data.date <<endl;
  153. ?? ?}
  154. ?? ?cout<< "\n";
  155. }
  156. //system("pause");
  157. }
  158. int serachsamename(LinkList L,string name){ //查找是否存在姓名相同的联系人?
  159. ?? ?while(L->next!=NULL){
  160. ?? ??? ?L=L->next;
  161. ?? ??? ?if(L->data.name==name)return 0;
  162. ?? ?}
  163. ?? ?return 1;
  164. }?
  165. int main(){
  166. ?? ?int i;
  167. ?? ?LinkList L;
  168. ?? ?InitList(L);
  169. ?? ?while(i!=6){
  170. ?? ??? ?i = ShowMenu();
  171. ?? ??? ?if(i ==1){
  172. ?? ??? ??? ?cout << "您选择了:新建联系人" <<endl;?
  173. ?? ??? ??? ?string number;
  174. ?? ??? ??? ?string date;
  175. ?? ? ? ? ? ?string time;
  176. ?? ? ? ? ? ?string name;
  177. ?? ? ? ? ? ?string adress;
  178. ?? ? ? ? ? ?string birthday;?
  179. ?? ? ? ? ? ?cout << "请输入联系人姓名:";?
  180. ?? ??? ??? ?cin >> name;
  181. ? ? ? ? ? ? ?SYSTEMTIME sys;?
  182. ? ? ? ? ? ? ?GetLocalTime( &sys );
  183. ? ? ? ? ? ? ?string y = doubleToString(sys.wYear);
  184. ? ? ? ? ? ? ?string m = doubleToString(sys.wMonth);
  185. ? ? ? ? ? ? ?string d = doubleToString(sys.wDay);
  186. ? ? ? ? ? ? ?string ymd = y+"-"+m+"-"+d;
  187. ? ? ? ? ? ? int repeat = serachsamename(L,name);?
  188. ? ? ? ? ? ? if(repeat == 0){
  189. ? ? ? ? ? ? ?? ?cout << "联系人姓名重复,请删除旧联系人或更改姓名!" << endl;?
  190. ?? ??? ??? ? }else{
  191. ?? ??? ??? ? ?? ?cout << "请输入联系人电话:";?
  192. ?? ??? ??? ? ? ?cin >> number;
  193. ? ? ? ? ? ? if(number.size()!=11){
  194. ? ? ? ? ? ? ?? ?cout << "手机号输入有误,请大于11位!" << endl;?? ?
  195. ?? ??? ??? ?}else{
  196. ?? ??? ??? ??? ?cout << "请输入联系人生日:";?
  197. ?? ??? ??? ?cin >> birthday;
  198. ?? ??? ??? ?cout << "请输入联系人地址:";?
  199. ?? ??? ??? ?cin >> adress;
  200. ?? ??? ??? ??? ?cout << "联系人于" << ymd;
  201. ?? ??? ??? ??? ?int ok;
  202. ?? ??? ??? ?ok = ?ListInsert(L,name,adress,birthday,ymd,number);
  203. ?? ??? ??? ?if(ok == 1){
  204. ?? ??? ??? ??? ?cout << "日新建成功!" << endl;?
  205. ?? ??? ??? ?}else{?
  206. ?? ??? ??? ?cout << "新建失败!" << endl;
  207. ?? ??? ??? ?}?
  208. ?? ??? ??? ?}
  209. ?? ??? ?}
  210. ?? ??? ??? ?system("pause");
  211. ?? ??? ??? ?system("cls");
  212. ?? ??? ?}else if(i==2){
  213. ?? ??? ??? ?cout << "您选择了:遍历联系人" <<endl;?
  214. ?? ??? ??? ?foreachelem(L);
  215. ?? ??? ??? ?system("pause");
  216. ?? ??? ??? ?system("cls");
  217. ?? ??? ??? ?
  218. ?? ??? ?}else if(i==3){
  219. ?? ??? ??? ?cout << "您选择了:修改选定联系人" <<endl;?
  220. ?? ??? ??? ?cout <<"请输入要修改的联系人姓名:" ;
  221. ?? ??? ??? ?string name;
  222. ?? ??? ??? ?cin >> name;
  223. ?? ??? ??? ?LinkList B;
  224. ?? ??? ??? ?B = SearchElemChar(L,1,name);
  225. ?? ??? ??? ? if(B){
  226. ?? ??? ??? ? ?? ?system("cls");
  227. ?? ??? ??? ? ?? ?cout << "联系人查找成功!姓名:" << B->data.name << endl;?
  228. ?? ??? ??? ? ?? ?int select;
  229. ?? ??? ??? ? ?? ?cout <<"---------修改姓名请输入1---------" << endl;
  230. ?? ??? ??? ??? ?cout <<"---------修改电话请输入2---------" << endl;?
  231. ?? ??? ??? ??? ?cout <<"---------修改生日请输入3---------" << endl;?
  232. ?? ??? ??? ??? ?cout <<"---------修改地址请输入4---------" << endl;?
  233. ?? ??? ??? ? ?? ?cout <<"请根据序号输入对象的选项修改:" ;
  234. ?? ??? ??? ? ?? ?cin >> select;
  235. ?? ??? ??? ? ?? ?switch(select){
  236. ?? ??? ??? ? ?? ??? ?case 1:?
  237. ?? ??? ??? ? ?? ??? ?{?? ?string name;
  238. ?? ??? ??? ??? ??? ?cout <<"请输入新姓名:";?
  239. ?? ??? ??? ??? ??? ?cin >> name;
  240. ?? ??? ??? ??? ??? ?B->data.name = name;
  241. ?? ??? ??? ??? ??? ?cout <<"修改完成!" << endl;
  242. ?? ??? ??? ??? ??? ?break;?
  243. ?? ??? ??? ??? ??? ? }
  244. ?? ??? ??? ??? ??? ?case 2: {
  245. ?? ??? ??? ??? ??? ?string number;
  246. ?? ??? ??? ??? ??? ?cout <<"请输入新电话:";?
  247. ?? ??? ??? ??? ??? ?cin >> number;
  248. ?? ??? ??? ??? ??? ?if(number.size()!=11){
  249. ? ? ? ? ? ? ?? ? ? ?cout << "手机号输入有误,请大于11位!" << endl;?? ?
  250. ?? ??? ??? ? ? ? ? ?}else{
  251. ?? ??? ??? ??? ??? ?B->data.number = number;
  252. ?? ??? ??? ??? ??? ?cout <<"修改完成!" << endl;
  253. ?? ??? ??? ??? ??? ?}
  254. ?? ??? ??? ??? ??? ?break;
  255. ?? ??? ??? ??? ??? ?}
  256. ?? ??? ??? ? ?? ??? ?case 3:{
  257. ?? ??? ??? ? ?? ??? ??? ?string birthday;
  258. ?? ??? ??? ? ?? ??? ??? ?cout <<"请输入新生日:";?
  259. ?? ??? ??? ? ?? ??? ??? ?cin >> birthday;
  260. ?? ??? ??? ? ?? ??? ??? ?B->data.birthday = birthday;
  261. ?? ??? ??? ??? ??? ? ? ?cout <<"修改完成!" << endl;
  262. ?? ??? ??? ??? ??? ??? ?break;
  263. ?? ??? ??? ??? ??? ? }
  264. ?? ??? ??? ??? ??? ? case 4:{
  265. ?? ??? ??? ? ?? ??? ??? ?string adress;
  266. ?? ??? ??? ? ?? ??? ??? ?cout <<"请输入新地址:";?
  267. ?? ??? ??? ? ?? ??? ??? ?cin >> adress;
  268. ?? ??? ??? ? ?? ??? ??? ?B->data.adress = adress;
  269. ?? ??? ??? ??? ??? ? ? ?cout <<"修改完成!" << endl;
  270. ?? ??? ??? ??? ??? ??? ?break;
  271. ?? ??? ??? ??? ??? ? }
  272. ?? ??? ??? ??? ??? ? default:cout <<"序号输入错误,请重新输入!"<<endl;?
  273. ?? ??? ??? ??? ? }
  274. ?? ??? ??? ? }else{
  275. ?? ??? ??? ? ?? ?cout << "未查找到联系人!请重新输入!" << endl;?
  276. ?? ??? ??? ? }
  277. ?? ??? ??? ? ?
  278. ?? ??? ??? ?system("pause");
  279. ?? ??? ??? ?system("cls");
  280. ?? ??? ?}else if(i==4){
  281. ?? ??? ??? ?system("cls");
  282. ?? ??? ??? ?cout << "您选择了:查询选定联系人" <<endl;?
  283. ?? ??? ??? ? ? ?cout <<"---------根据姓名查询请输入1---------" << endl;
  284. ?? ??? ??? ??? ?cout <<"---------根据电话查询请输入2---------" << endl;?
  285. ?? ??? ??? ??? ?cout <<"---------根据生日查询请输入3---------" << endl;?
  286. ?? ??? ??? ??? ?cout <<"---------根据地址查询请输入4---------" << endl;
  287. ?? ??? ??? ??? ?int select;
  288. ?? ??? ??? ??? ?cout <<"请根据序号输入对象的进行查询:" ;
  289. ?? ??? ??? ? ?? ?cin >> select;
  290. ?? ??? ??? ? ?? ?switch(select){
  291. ?? ??? ??? ? ?? ??? ?case 1:{
  292. ?? ??? ??? ? ?? ??? ??? ?cout <<"请输入要查询的联系人姓名:" ;
  293. ?? ??? ??? ? ? ? ? ? ? ?string name;
  294. ?? ??? ??? ? ? ? ? ? ? ?cin >> name;
  295. ?? ??? ??? ? ? ? ? ? ? ?LinkList B;
  296. ?? ??? ??? ? ? ? ? ? ? ?B = SearchElemChar(L,1,name);
  297. ?? ??? ??? ? ? ? ? ? ? ?if(B){
  298. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"查询成功!"<< endl;?
  299. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人姓名:"<< B->data.name << endl;
  300. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人电话:"<< B->data.number << endl;
  301. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人生日:"<< B->data.birthday << endl;
  302. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人地址:"<< B->data.adress << endl;
  303. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"插入日期:"<< B->data.date << endl;
  304. ?? ??? ??? ??? ??? ? ? ? }else{
  305. ?? ??? ??? ??? ??? ? ? ? ?? ?cout<<"查询失败!请重新输入!"<< endl;?
  306. ?? ??? ??? ??? ??? ??? ? }
  307. ?? ??? ??? ??? ??? ??? ?break;
  308. ?? ??? ??? ??? ??? ? }
  309. ?? ??? ??? ??? ??? ? case 2:
  310. ?? ??? ??? ??? ??? ? ?? ?{
  311. ?? ??? ??? ??? ??? ? ?? ?cout <<"请输入要查询的联系人电话:" ;
  312. ?? ??? ??? ? ? ? ? ? ? ?string number;
  313. ?? ??? ??? ? ? ? ? ? ? ?cin >> number;
  314. ?? ??? ??? ? ? ? ? ? ? ?LinkList B;
  315. ?? ??? ??? ? ? ? ? ? ? ?B = SearchElemChar(L,5,number);
  316. ?? ??? ??? ? ? ? ? ? ? ?if(B){
  317. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"查询成功!"<< endl;?
  318. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人姓名:"<< B->data.name << endl;
  319. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人电话:"<< B->data.number << endl;
  320. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人生日:"<< B->data.birthday << endl;
  321. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人地址:"<< B->data.adress << endl;
  322. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"插入日期:"<< B->data.date << endl;
  323. ?? ??? ??? ??? ??? ? ? ? }else{
  324. ?? ??? ??? ??? ??? ? ? ? ?? ?cout<<"查询失败!请重新输入!"<< endl;?
  325. ?? ??? ??? ??? ??? ??? ? }
  326. ?? ??? ??? ??? ??? ??? ?break;
  327. ?? ??? ??? ??? ??? ??? ? }
  328. ?? ??? ??? ??? ??? ??? ?case 3:{
  329. ?? ??? ??? ??? ??? ??? ??? ?cout <<"请输入要查询的联系人生日:" ;
  330. ?? ??? ??? ? ? ? ? ? ? ?string bd;
  331. ?? ??? ??? ? ? ? ? ? ? ?cin >> bd;
  332. ?? ??? ??? ? ? ? ? ? ? ?LinkList B;
  333. ?? ??? ??? ? ? ? ? ? ? ?B = SearchElemChar(L,2,bd);
  334. ?? ??? ??? ? ? ? ? ? ? ?if(B){
  335. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"查询成功!"<< endl;?
  336. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人姓名:"<< B->data.name << endl;
  337. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人电话:"<< B->data.number << endl;
  338. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人生日:"<< B->data.birthday << endl;
  339. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人地址:"<< B->data.adress << endl;
  340. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"插入日期:"<< B->data.date << endl;
  341. ?? ??? ??? ??? ??? ? ? ? }else{
  342. ?? ??? ??? ??? ??? ? ? ? ?? ?cout<<"查询失败!请重新输入!"<< endl;?
  343. ?? ??? ??? ??? ??? ??? ? }
  344. ?? ??? ??? ??? ??? ??? ?break;
  345. ?? ??? ??? ??? ??? ??? ?}
  346. ?? ??? ??? ??? ??? ??? ?case 4:{
  347. ?? ??? ??? ??? ??? ??? ?cout <<"请输入要查询的联系人地址:" ;
  348. ?? ??? ??? ? ? ? ? ? ? ?string ad;
  349. ?? ??? ??? ? ? ? ? ? ? ?cin >> ad;
  350. ?? ??? ??? ? ? ? ? ? ? ?LinkList B;
  351. ?? ??? ??? ? ? ? ? ? ? ?B = SearchElemChar(L,3,ad);
  352. ?? ??? ??? ? ? ? ? ? ? ?if(B){
  353. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"查询成功!"<< endl;?
  354. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人姓名:"<< B->data.name << endl;
  355. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人电话:"<< B->data.number << endl;
  356. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人生日:"<< B->data.birthday << endl;
  357. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人地址:"<< B->data.adress << endl;
  358. ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"插入日期:"<< B->data.date << endl;
  359. ?? ??? ??? ??? ??? ? ? ? }else{
  360. ?? ??? ??? ??? ??? ? ? ? ?? ?cout<<"查询失败!请重新输入!"<< endl;?
  361. ?? ??? ??? ??? ??? ??? ? }
  362. ?? ??? ??? ??? ??? ??? ?break;
  363. ?? ??? ??? ??? ??? ??? ??? ?break;
  364. ?? ??? ??? ??? ??? ??? ?}
  365. ?? ??? ??? ??? ??? ? default:cout <<"序号输入错误,请重新输入!"<<endl;?
  366. ?? ??? ??? ??? ? }?
  367. ?? ??? ? ? ?system("pause");
  368. ?? ??? ??? ?system("cls");
  369. ?? ??? ?}else if(i==5){
  370. ?? ??? ??? ?cout << "您选择了:删除联系人" <<endl;?
  371. ?? ??? ??? ?string name;
  372. ?? ??? ??? ?cout << "请输入联系人姓名:" <<endl;?
  373. ?? ??? ??? ?cin >> name;
  374. ?? ??? ??? ?LinkList D,P;
  375. ?? ??? ??? ?P = SearchElemBefore(L,name);?
  376. ?? ??? ??? ?if(P){
  377. ?? ??? ??? ??? ?D = P->next;
  378. ?? ??? ??? ?P->next = D->next;
  379. ?? ??? ??? ?delete D; //释放结点数据?
  380. ?? ??? ??? ?cout << "删除成功!" <<endl;
  381. ?? ??? ??? ?}else{
  382. ?? ??? ??? ??? ?cout<<"查询失败!未找到指定联系人!"<< endl;?
  383. ?? ??? ??? ?}
  384. ?? ??? ??? ?system("pause");
  385. ?? ??? ??? ?system("cls");
  386. ?? ??? ?}else if(i==6){
  387. ?? ??? ??? ?cout << "系统已退出,欢迎下次使用!" <<endl;
  388. ?? ??? ?}
  389. ?? ??? ?else{
  390. ?? ??? ??? ?cout <<"输入异常,请重新选择输入!" <<endl;
  391. ?? ??? ??? ?system("pause");
  392. ?? ??? ??? ?system("cls");
  393. ?? ??? ?}
  394. ?? ?}?
  395. ?? ?return 0;
  396. }

 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号