重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
C++中怎么链表实现一个通讯录管理系统,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
创新互联专业为企业提供代县网站建设、代县做网站、代县网站设计、代县网站制作等企业网站建设、网页设计与制作、代县企业网站模板建站服务,十年代县做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
具体内容如下
文件操作未写
有登录操作,复制源码需要更改登录模块的密码文件存放位置
使用VS2017编译器需要保留开头:#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS#include "iostream"#include "cstdio"#include "fstream"#include "stdlib.h"#include "String"#include "iomanip"#include "windows.h"#define LEN 100using namespace std; using std::cin;using std::cout;using std::endl;using std::ifstream;using std::ofstream;using std::ios;using std::cerr;using std::string;using std::setw; typedef struct LNode { char num[10]; char name[20]; char telNum[12]; char qq[10]; struct LNode *next;}LNode,*LinkList; int n = 0; void InitList(LinkList &L);//初始化表void InsertLNode(LinkList &L,LNode *s);//前插法插入新结点LinkList SearchName(LinkList L);//按姓名查找LinkList SearchNum(LinkList L);//按学号查找void DelLNode(LinkList &L,LinkList p);//删除p结点void PrintLNode(LinkList p);//打印结点void PrintList(LinkList L);//打印表/*----------------系统函数----------------*/void CreateLinkList(LinkList &L);//创建链表void DelName(LinkList &L);//按姓名删除通讯录成员void DelNum(LinkList &L);//按学号删除通讯录成员void saveRecord(LinkList L);//存储信息void loadRecord(LinkList &L);//加载信息/*--------------------------------------*/void Secret();void fun();void ver();void yanshi(char *p);void clear();void header(); void menu() { LinkList L=NULL; int select; do { system("cls"); printf("\t\t\t Welcome to the address book information management system!\n\n\n"); printf("\t\t\t\t***************************************************\n"); printf("\t\t\t\t * │1.InitList 2.Add Message │ *\n"); printf("\t\t\t\t * │ │ *\n"); printf("\t\t\t\t * │3.Search Message 4.Save File │ *\n"); printf("\t\t\t\t * │ │ *\n"); printf("\t\t\t\t * │5.Sort Static 6.Load Message │ *\n"); printf("\t\t\t\t * │ │ *\n"); printf("\t\t\t\t * │7.Display Message 8.Delete Message│ *\n"); printf("\t\t\t\t * │ │ *\n"); printf("\t\t\t\t * │9.Save Message 0.Exit System │ *\n"); printf("\t\t\t\t***************************************************\n"); cout << endl; yanshi((char *)"\t\tPlease choose the mode of operation(1~8):\n");/* cout << "\t\tPlease choose the mode of operation(1~8):" << endl;*/ cin >> select; switch (select) { case 8: cout << "Please select the deletion method:\n1.Delete by student number 2.Delete by name\n" << endl; int x; cin >> x; switch (x) { case 1: DelNum(L); break; case 2: DelName(L); break; } case 6: loadRecord(L); break; case 5: break; case 4: saveRecord(L); break; case 3: clear(); cout << "Please select a search method:\n1.Find by student number 2.Find by name\n" << endl; int a; cin >> a; switch (a) { case 1: clear(); { LinkList aa = SearchNum(L); header(); PrintLNode(aa); cout << "\n\n\n成功!" << endl; system("pause"); menu(); } break; case 2: clear(); { LinkList b = SearchName(L); header(); PrintLNode(b); cout << "\n\n\n成功!" << endl; system("pause"); menu(); break; } } break; case 1: InitList(L); break; case 9: break; case 7: PrintList(L); break; case 2: CreateLinkList(L); break; case 0: cout << endl << endl << endl; cout << "The programe is over!" << endl << endl << endl; Sleep(2000); exit(0); break; } } while (select != 8);} int main() { fun(); ver();//版本信息 Secret();//密码登录 menu(); return 0;} //初始化表void InitList(LinkList & L){ L = new LNode;//申请头结点 L->next= NULL;} //插入一条信息void InsertLNode(LinkList & L, LNode *s){ s->next = L->next; L->next = s;} //按姓名查找LinkList SearchName(LinkList L){ char name[20]; cout << "请输入要查找的姓名:" << endl; cin >> name; LinkList p = L->next; while (p) { //如果找到,退出循环,返回p if (strcmp(p->name, name) == 0) break; else p = p->next; } return p;} //按学号查找LinkList SearchNum(LinkList L){ char num[10]; cout << "请输入要查找的学号:" << endl; cin >> num; LinkList p = L->next; while (p) { //如果找到,退出循环,返回p if (strcmp(p->num, num) == 0) break; else p = p->next; } return p;} //删除节点void DelLNode(LinkList &L,LinkList p){ LinkList s=NULL, q; q = L->next; //将s指向p前面的一个结点 while (q&&q!=p) { s = q; q = q->next; } s->next = q->next; delete q;} //打印一条信息void PrintLNode(LinkList p){ printf("%15s", p->num); printf("%15s", p->name); printf("%15s", p->telNum); printf("%15s\n",p->qq);} //打印通讯录void PrintList(LinkList L){ clear(); header(); LinkList p = L->next; while (p) { PrintLNode(p); p = p->next; } system("pause");} //添加信息void CreateLinkList(LinkList & L){ char ans = 'y'; n = 0; while (ans=='y'||ans=='Y') { system("cls"); LNode *p = new LNode; cout << "请输入学号:" << endl; cin >> p->num; cout << "请输入姓名:" << endl; cin >> p->name; cout << "请输入电话号码:" << endl; cin >> p->telNum; cout << "请输入QQ号:" << endl; cin >> p->qq; InsertLNode(L,p); n++; cout<<"是否继续?(Y/N)"<
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。