#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
typedef struct student
{
char name[20];
char num[15];
char sex[10];
char from[20];
char political[10];
char phone[15];
char QQ[15];
char dorm[10];
struct student *next;
}stu;
stu *head = NULL;
int i = 1;
void menu();
void help();
void next();
void look_data(stu *head);
void input_data();
void insert_data();
void deleted_data();
void find_data();
void update_data();
void save_data();
int main()
{
int label = 0;
while(1)
{
menu();
scanf("%d", &label);
switch(label)
{
case 1: help(); break;
case 2: input_data(); break;
case 3: find_data(); break;
case 4: deleted_data(); break;
case 5: save_data(); break;
case 6: look_data(head); break;
case 7: update_data(head);break;
case 8: insert_data(); break;
case 9: exit(0); break;
default: next(); break;
}
}
return 0;
}
void menu()
{
system("cls");
printf("\n");
printf("********************************************************************************************\n");
printf("* 通讯录管理系统 *\n");
printf("********************************************************************************************\n");
printf("****************************************系统功能菜单****************************************\n");
printf("--------------------------------------------------------------------------------------------\n");
printf("********************************************************************************************\n");
printf("**** 1、系统使用帮助 **** 2、插入多条数据 ****\n");
printf("********************************************************************************************\n");
printf("**** 3、查询数据 **** 4、删除数据 ****\n");
printf("********************************************************************************************\n");
printf("**** 5、保存数据 **** 6、显示数据 ****\n");
printf("********************************************************************************************\n");
printf("**** 7、修改数据 **** 8、插入一条数据 ****\n");
printf("********************************************************************************************\n");
printf("**** 9、退出系统 **** ====》待开发模块《==== ****\n");
printf("********************************************************************************************\n");
printf("--------------------------------------------------------------------------------------------\n");
}
void help()
{
system("cls");
printf("\n 这是一个学生管理系统,为方便您更快了解它,请先阅读以下注意事项: \n");
printf("\n 注意事项: \n");
printf("\n 1、请根据提示进行操作! \n");
printf("\n 2、初次使用请先选择输入数据! \n");
printf("\n 3、按照菜单提示键入数字代号! \n");
printf("\n 4、增加数据后,切记保存! \n");
printf("\n 5、若您之前使用过,下次进入系统请先刷新学生信息! \n");
printf("\n 6、使用遇到任何问题请与我们联系,电话:110、119、120\n");
printf("\n 7、最后感谢您的使用! \n");
system("pause");
}
void next()
{
system("cls");
printf("\n");
printf("********************************************************************************************\n");
printf("**** ====》此模块待开发《==== ****\n");
printf("********************************************************************************************\n");
system("pause");
}
void input_data()
{
stu *p1 = NULL, *p2 = NULL;
int m = 1;
system("cls");
printf("**** ====》输入数据《==== ****\n");
printf("**** ====》ok代表结束《==== ****\n");
while(m)
{
printf("\n--------------------------------------------------------------------------------------------\n");
p1 = (stu *)malloc(sizeof(stu));
p1->next = NULL;
if(p1 == NULL)
{
printf("malloc error!!\r\n");
return ;
}
printf("\n手机号:");
scanf("%s", &p1->phone);
if(strcmp(p1->phone, "ok") == 0)
{
printf("\n输入完毕!!\n");
free(p1);
m = 0;
break;
}
stu *tmp = head;
while(tmp != NULL)
{
if(strcmp(tmp->phone, p1->phone) == 0)
{
printf("\n该学生已经存在!!\n");
break;
}
p2 = tmp;
tmp = tmp->next;
}
if(tmp == NULL)
{
printf("\n姓名:");
scanf("%s", &p1->name);
printf("\n性别:");
scanf("%s", &p1->sex);
printf("\n籍贯:");
scanf("%s", &p1->from);
printf("\n政治面貌:");
scanf("%s", &p1->political);
printf("\n学号:");
scanf("%s", &p1->num);
printf("\nQQ号:");
scanf("%s", &p1->QQ);
printf("\n宿舍:");
scanf("%s", &p1->dorm);
if(i == 1)
{
head = p1;
i = 2;
}
else
p2->next = p1;
p2 = p1;
}
printf("\n--------------------------------------------------------------------------------------------\n");
}
system("pause");
}
void look_data(stu *head)
{
system("cls");
printf("**** ====》显示数据《==== ****\n");
stu *tmp = head;
printf("\n--------------------------------------------------------------------------------------------\n");
while(tmp != NULL)
{
printf("姓名:%s\n", tmp->name);
printf("学号:%s\t", tmp->num);
printf("性别:%s\t", tmp->sex);
printf("籍贯:%s\t", tmp->from);
printf("政治面貌:%s\t", tmp->political);
printf("手机号:%s\t", tmp->phone);
printf("QQ号:%s\t", tmp->QQ);
printf("宿舍:%s\n", tmp->dorm);
tmp = tmp->next;
}
printf("\n--------------------------------------------------------------------------------------------\n");
system("pause");
}
void insert_data()
{
stu *p1 = NULL;
p1 = (stu *)malloc(sizeof(stu));
p1->next = NULL;
if(p1 == NULL)
{
printf("malloc error!!\r\n");
return ;
}
printf("\n手机号:");
scanf("%s", &p1->phone);
stu *tmp = head;
while(tmp != NULL)
{
if(strcmp(tmp->phone, p1->phone) == 0)
{
printf("\n该学生已经存在!!\n");
break;
}
tmp = tmp->next;
}
if(tmp == NULL)
{
printf("\n姓名:");
scanf("%s", &p1->name);
printf("\n性别:");
scanf("%s", &p1->sex);
printf("\n籍贯:");
scanf("%s", &p1->from);
printf("\n政治面貌:");
scanf("%s", &p1->political);
printf("\n学号:");
scanf("%s", &p1->num);
printf("\nQQ号:");
scanf("%s", &p1->QQ);
printf("\n宿舍:");
scanf("%s", &p1->dorm);
if(i == 1)
{
head = p1;
i = 2;
}
else
{
int label = 0;
char phoned[20];
stu *mmp = head, *p2;
system("cls");
printf("********************************************************************************************\n");
printf("******************************************插入选项******************************************\n");
printf("--------------------------------------------------------------------------------------------\n");
printf("********************************************************************************************\n");
printf("**** 1、首位置插入 2、尾位置插入 3、特定位置前插 其他:取消插入 ****\n");
printf("********************************************************************************************\n");
printf("\n请输入你的选择:");
scanf("%d", &label);
switch(label)
{
case 1:
p1->next = mmp;
head = p1;
break;
case 2:
while(mmp->next != NULL)
{
mmp = mmp->next;
}
mmp->next = p1;
break;
case 3:
printf("\n请输入手机号(前插):");
scanf("%s", phoned);
while(strcmp(phoned, mmp->phone) != 0)
{
p2 = mmp;
mmp = mmp->next;
}
p1->next = mmp;
p2->next = p1;
break;
default:
free(p1);
break;
}
printf("插入成功!!!!\n");
}
}
return ;
}
void deleted_data()
{
char phone[11];
printf("\n请输入你要删除的手机号:");
scanf("%s", phone);
stu *tmp = head, *nmmp;
int flag = 0;
if(tmp == NULL)
{
printf("你的通讯录还没有添加人员!!\n");
system("pause");
return ;
}
while(tmp)
{
if(0 == strcmp(phone, tmp->phone))
{
flag = 1;
nmmp->next = tmp->next;
free(tmp);
printf("删除成功!\n");
break;
}
nmmp = tmp;
tmp = tmp->next;
}
if(flag == 0)
printf("这个学生不存在!!\n");
system("pause");
}
void find_data()
{
char phone[11];
printf("\n请输入你要查找的手机号:");
scanf("%s", phone);
stu *tmp = head, *nmmp;
int flag = 0;
if(tmp == NULL)
{
printf("你的通讯录还没有添加人员!!\n");
system("pause");
return ;
}
while(tmp)
{
if(0 == strcmp(phone, tmp->phone))
{
flag = 1;
printf("你要找到的数据\n");
printf("姓名:%s\n", tmp->name);
printf("学号:%s\t", tmp->num);
printf("性别:%s\t", tmp->sex);
printf("籍贯:%s\t", tmp->from);
printf("政治面貌:%s\t", tmp->political);
printf("手机号:%s\t", tmp->phone);
printf("QQ号:%s\t", tmp->QQ);
printf("宿舍:%s\n", tmp->dorm);
printf("查找成功!\n");
break;
}
tmp = tmp->next;
}
if(flag == 0)
printf("这个学生不存在!!\n");
system("pause");
}
void update_data()
{
char phone[11];
printf("\n请输入你要修改人的手机号:");
scanf("%s", phone);
stu *tmp = head;
int flag = 0;
if(tmp == NULL)
{
printf("你的通讯录还没有添加人员!!\n");
system("pause");
return ;
}
while(tmp)
{
if(0 == strcmp(phone, tmp->phone))
{
flag = 1;
printf("你要找到的数据\n");
printf("姓名:%s\n", tmp->name);
printf("学号:%s\t", tmp->num);
printf("性别:%s\t", tmp->sex);
printf("籍贯:%s\t", tmp->from);
printf("政治面貌:%s\t", tmp->political);
printf("手机号:%s\t", tmp->phone);
printf("QQ号:%s\t", tmp->QQ);
printf("宿舍:%s\n", tmp->dorm);
printf("请选择要修改的信息\n");
printf("\t1.姓名\t2.学号\t3.性别\t4.籍贯\n\t5.政治面貌\t6.手机号\t7.QQ\t8.宿舍\n");
printf("\n您的选择是(1~8):");
scanf("%d", &i);
printf("请输入修改之后的内容\n");
switch(i)
{
case 1:printf("姓名:");
scanf("%s", &tmp->name);
break;
case 2:printf("学号:");
scanf("%s", &tmp->num);
break;
case 3:printf("性别:");
scanf("%s", &tmp->sex);
break;
case 4:printf("籍贯:");
scanf("%s", &tmp->from);
break;
case 5:printf("政治面貌:");
scanf("%s", &tmp->political);
break;
case 6:printf("手机号:");
scanf("%s", &tmp->phone);
break;
case 7:printf("QQ:");
scanf("%s", &tmp->QQ);
break;
case 8:printf("宿舍:");
scanf("%d", &tmp->dorm);
break;
}
printf("修改成功!!!");
}
tmp = tmp->next;
}
if(flag == 0)
printf("这个学生不存在!!\n");
system("pause");
}
void save_data()
{
FILE *fp;
stu *tmp = head;
char filename[100];
printf("\n请输入要保存的文件名:");
scanf("%s", filename);
if((fp = fopen(filename, "w+")) == NULL)
{
printf("\n打开文件失败!\n");
exit(0);
}
fprintf(fp,"姓名\t学号\t性别\t籍贯\t政治面貌\t手机号\tQQ号\t宿舍\n");
while(tmp)
{
fprintf(fp,"%s\t", tmp->name);
fprintf(fp,"%s\t", tmp->num);
fprintf(fp,"%s\t", tmp->sex);
fprintf(fp,"%s\t", tmp->from);
fprintf(fp,"%s\t", tmp->political);
fprintf(fp,"%s\t", tmp->phone);
fprintf(fp,"%s\t", tmp->QQ);
fprintf(fp,"%s\n", tmp->dorm);
tmp = tmp->next;
}
printf("\n保存成功!\n");
fclose(fp);
system("pause");
}
|