> 文档中心 > C语言结构体数组_课程设计_无链表版本_期末大作业版(含源代码)

C语言结构体数组_课程设计_无链表版本_期末大作业版(含源代码)

作者:胜利111

通信录信息管理系统
现需要用c语言开发一款通信录信息管理系统,系统必须用结构体数组实现。管理对象为延信录,
要管理的属性包含编号(不重复)、姓名、性别(使用1表示男性,0表示女性)、电话、年龄(整数),要求的功能包括

以下几条,请完成主程序及各功能模块,每条功能必须用函数实现,功能及函数名称如下,
函数参数及返回类型可自行定义:
1. 菜单驱动的main函数
2. 从特定文件读入信息: ReadFrc 
omFile();
3. 将信息写入特定文件: WriteToFlie();
4. 显示链表所有信息: Display():
5. 添加录入信息:InputRecord();
6. 删除特定条目信息:DeleteRecord();
要求能根据编号删除特定条目信息
7. 查询指定编号通信录信息:Query();
要求能登询指定编号的通信录记录。
8,修改特定编号的记录年龄:modify();

有很多同学上下行对齐有问题或者没搞懂的,我在这里分享我自己的收藏!请点击链接进入知网页,学习用打印宽度控制,使上下行看起来更加整洁!

话不多说,直接上代码(仅供学习参考,如有疑问欢迎沟通学习!博主vx号:ueiheng )

#include#include#includestruct people {char num[20];char name[10];int sex;// Male - > 1 female - > 0 char phone[13];int year; }x[50];int i = 0;int n = 0;int count = 0;int m = 0;//Function declaration:void ReadFromFlie();void WriteToFile();void Display();void InputRecord();void menu();void asdf();void del();void modify();//读取文件 void ReadFromFile(){int i = 0;char filename[20];FILE *fp = NULL;printf("Please enter a file name to open:\n");scanf(" %s ",filename);if((fp = fopen(filename,"r+")) == NULL){printf("The file was not found!\n");return;}while(!feof(fp)){fscanf(fp,"%s %s %d %s %d",x[i].num,x[i].name,&x[i].sex,x[i].phone,&x[i].year);i++;}n = i; printf("File read!");fclose(fp);}//写入文件保存 void WriteToFile(){int i;FILE *fp;char filename[20];printf("Please enter a file name to save:\n");scanf("%s", filename);fp = fopen(filename, "w");for (i = 0; i < n; i++){fprintf(fp,"%s %s %d %s %d \n", x[i].num, x[i].name, x[i].sex, x[i].phone,x[i].year);}printf("Saved successfully!\n");fclose(fp);system("pause");//程序暂停 }//显示全部信息 void Display(){system("cls");int i;printf("The display results are as follows:\n");printf("\n\t*******address book*******\n\n");printf("Number    name    gender    telephone    age\n");for(i = 0;i  1 female - > 0)\n",x[i].num,x[i].name,x[i].sex,x[i].phone,x[i].year);}printf("\n\t************end***********\n\n");system("pause");}//添加信息 void InputRecord(){printf("The number of people already in the address book is %d\n",n);int i = n,j,flag;printf("Input the  number of people:");scanf("%d",&m);if(m > 0){do  {flag = 1;while (flag){flag = 0;printf("Please enter the number of person %d:\n", i + 1);scanf("%s", x[i].num);for (j = 0; j < i; j++){if (strcmp(x[i].num, x[j].num) == 0){printf("The number already exists, please re-enter!\n");flag = 1;}}}printf("Please enter the name of person %d:\n", i + 1);scanf("%s", x[i].name);printf("Please enter the gender of the %d person (male, please enter 1, female, please enter 0):\n", i + 1);scanf("%d", &x[i].sex);printf("Please enter the phone number of person %d:\n",i + 1);scanf("%s",x[i].phone);printf("Please enter the age of person %d:\n",i + 1);scanf("%d",&x[i].year);if (flag == 0){i ++;}} while (i < n+m);}n += m;printf("Address book information added!\n");}//菜单 void menu(){printf("\n----------------menu-----------------\n");printf("\n\t 1.Query information\n");printf("\n\t 2.Modify information\n");printf("\n\t 3.Delete information\n");printf("\n\t 4.View all information\n");printf("\n\t 5.Save file to\n");printf("\n\t 6.Add information\n");printf("\n\t 7.read file\n");printf("\n\t 0.Exit the system\n");printf("\n----------------menu-----------------\n");}//查询信息 void asdf() {int i, flag = 0;char s1[20]; printf("Please enter the number to query:\n");scanf("%s", s1);for (i = 0; i<n; i++)if (strcmp(s1,x[i].num) == 0){flag = 1;    printf("Number name gender telephone age\n");printf("%5s%5s%5d%5s%5d\n(Statement: in gender, 1 represents male and 0 represents female)",x[i].num,x[i].name,x[i].sex,x[i].phone,x[i].year);}if (flag == 0)printf("The number does not exist!\n");}//删除信息void del(){int i, j, flag = 0;char s1[20];printf("Please enter the number of the person to delete:\n");scanf("%s", s1);for (i = 0; i < n; i++){if (strcmp(x[i].num, s1) == 0){flag = 1;//要删除的往前移一位for (j = i; j < n - 1; j++){x[j] = x[j + 1];}}}//查找失败if (flag == 0){printf("The number does not exist!!!\n");}if (flag == 1){printf("Delete succeeded!!!");n--;}}//修改信息void modify() {int i, item, num = -1;char  s1[20], s2[20]; printf("Please enter the number of the person to modify:\n");scanf("%s", s1);for (i = 0; i < n; i++){if (strcmp(x[i].num, s1) == 0){num = i;printf("\n**********************\n\n");printf("1.Modify age\n");printf("2.Modify mobile phone number\n");printf("3.Exit this menu\n");printf("\n**********************\n");while (1){printf("Please select the information to modify:");scanf("%d", &item);switch (item){case 1:printf("Please enter a new age:\n");scanf("%s", s2);strcpy(x[num].name, s2);break;case 2:printf("enter a new mobile phone number:\n");scanf("%s", x[num].phone);break;case 3:printf("\n\nExit successful!!!\n\n");return;default:printf("Please choose between 1-3\n");}}printf("Modification completed!\n");}else{printf("No number for this person!");}}}//主函数 int main(void){while(1){menu();printf("Enter choice:");scanf("%d", &count);switch (count){case 1:asdf(); break;case 2:modify(); break;case 3:del(); break;case 4:Display(); break;case 5:WriteToFile(); break;case 6:InputRecord(); break;case 7:ReadFromFile();break;case 0:printf("\nAbout to exit the program!\n\n For mutual learning reference only,\n please contact the author if you have any questions!\n thank you!");exit(0);default:printf("please select between 0-7\n");}}return 0;}

美国云服务器