多文件模块的学生信息库系统
student.h
1 #include<stdio.h> 2 #include<string.h> 3 #define MaxSize 50 4 struct student 5 { 6 int num; 7 char name[10]; 8 int computer, english, math; 9 double average; 10 }; 11 void new_student(struct student students[]); 12 void output_student(struct student students[]); 13 void average(struct student students[]); 14 void sort(struct student students[]); 15 void modify(struct student students[]); 16 void search_student(struct student students[], int num);
main.c
1 #include "student.h" 2 int Count = 0; 3 int main(void) 4 { 5 struct student students[MaxSize]; 6 new_student(students); 7 average(students); 8 printf("New\n"); 9 output_student(students); 10 sort(students); 11 printf("After Sort:\n"); 12 output_student(students); 13 modify(students); 14 printf("After Modify:\n"); 15 output_student(students); 16 int num; 17 printf("Enter num:"); 18 scanf_s("%d", &num); 19 search_student(students, num); 20 21 return 0; 22 }
input_output.c
1 #include "student.h" 2 3 extern Count; 4 void new_student(struct student students[]) 5 { 6 int i, n; 7 if (Count == MaxSize) 8 { 9 printf("The array is full!\n"); 10 11 return; 12 } 13 printf("Input the Number of Students:"); 14 scanf_s("%d", &n); 15 for (i = 0; i < n; i++) 16 { 17 printf("Input the student's num:"); 18 scanf_s("%d", &students[i].num); 19 printf_s("Input the student's name:"); 20 scanf_s("%s", students[i].name, 10); 21 printf("Input the student's math.score:"); 22 scanf_s("%d", &students[i].math); 23 printf("Input the student's english.score:"); 24 scanf_s("%d", &students[i].english); 25 printf("Input the student's computer.score:"); 26 scanf_s("%d", &students[i].computer); 27 28 Count++; 29 } 30 } 31 void output_student(struct student students[]) 32 { 33 int i; 34 if (Count == 0) 35 { 36 printf("Count of students is zero!\n"); 37 return; 38 } 39 printf("num\tname\tmath\tenglish\tcomputer\taverage\n"); 40 for (i = 0; i < Count; i++) 41 { 42 printf("%d\t%s\t%d\t%d\t%d\t%f\n", students[i].num, students[i].name, students[i].math, students[i].english, students[i].computer, students[i].average); 43 } 44 }
aver_sort.c
1 #include "student.h" 2 extern Count; 3 void average(struct student students[]) 4 { 5 int i; 6 for (i = 0; i < Count; i++) 7 { 8 students[i].average = 1.0 * (students[i].math + students[i].english + students[i].computer) / 3; 9 } 10 } 11 void sort(struct student students[]) 12 { 13 struct student temp; 14 int i, j, index; 15 for (i = 0; i < Count - 1; i++) 16 { 17 index = i; 18 for (j = i + 1; j < Count; j++) 19 { 20 if (students[j].average > students[index].average) 21 { 22 index = j; 23 } 24 } 25 temp = students[i]; 26 students[i] = students[index]; 27 students[index] = temp; 28 } 29 }
modify.c
1 #include "student.h" 2 extern Count; 3 void modify(struct student students[]) 4 { 5 int num, course, score, i; 6 struct student* p = students; 7 printf("Input the number of the students to be updated:"); 8 scanf_s("%d", &num); 9 printf("Choice the course:1.math 2.english 3.computer:"); 10 scanf_s("%d", &course); 11 printf("Input the new score:"); 12 scanf_s("%d", &score); 13 for (i = 0; i < Count; i++, p++) 14 { 15 if (p->num == num) 16 { 17 break; 18 } 19 } 20 if (i < Count) 21 { 22 switch (course) 23 { 24 case 1:p->math = score; break; 25 case 2:p->english = score; break; 26 case 3:p->computer = score; break; 27 } 28 } 29 } 30 void search_student(struct student students[], int num) 31 { 32 int i, flag = 0; 33 if (Count == 0) 34 { 35 printf("Count of students is zero!\n"); 36 return; 37 } 38 for (i = 0; i < Count; i++) 39 { 40 if (students[i].num == num) 41 { 42 flag = 1; 43 break; 44 } 45 } 46 if (flag) 47 { 48 printf("num:%d, name:%s, math:%d, english:%d, computer:%d, average:%.2f\n", \ 49 students[i].num, students[i].name, students[i].math, students[i].english, students[i].computer, students[i].average); 50 } 51 else 52 { 53 printf("Not Found!\n"); 54 } 55 };
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!