C语言——学生成绩管理系统

  1 /* ***********************
2 author : C / C#
3 data : 2011-8-19
4 Copyright 2011
5 *********************** */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 #define N 5
12
13 void aver(score);
14 void menu(int *num , char *name , char *flag);
15 float *search(int *num , char *flag , char *name , char *p_name , int *p_num , float * score);
16 void repo(int *stu_num , char *stu_name , float * score , float *score_i);
17
18 int main(void)
19 {
20 int number , stu_num[N] = { 2 , 3 , 5 , 8 , 9 };
21
22 float score[N][4] = {
23 {78 ,67 , 89} ,
24 {90 ,87 , 65} ,
25 {65 ,54 , 79} ,
26 {98 ,87 , 69} ,
27 {87 ,70 , 60} ,
28 } ;
29 float *p_score ;
30
31 char stu_name[N][20] = {
32 "li dong" ,
33 "zhu li" ,
34 "wang ming" ,
35 "tang tai guo" ,
36 "bai dong hui" ,
37 };
38 char name[20] , flag ;
39
40 aver(score);
41 menu(&number , name , &flag);
42 p_score = search(&number , &flag , name , stu_name , stu_num , score);
43 repo(stu_num , stu_name , score , p_score);
44
45 }
46
47 void aver(float *score_a)
48 {
49 int i , j ;
50 float sum ;
51
52 for(i = 0 ; i < N ; i++)
53 {
54 for(sum = 0 , j = 0 ; j < 4 ; j++)
55 {
56 sum += *(score_a + i * 4 + j);
57 }
58 *(score_a + i * 4 + 3) = sum / 3 ; //将平均值赋给每一行的第四位数
59 }
60
61 return ;
62 }
63
64 void menu(int *num , char *name , char *flag)
65 {
66 printf("\nSelect the searching method : \n C—————— name | N —————— no : ");
67 *flag = getchar();
68
69 if(*flag == 'n' || *flag == 'N')
70 {
71 printf("\nInput student number :");
72 scanf("%d" , num);
73 }
74 else if(*flag == 'c' || *flag == 'C')
75 {
76 getchar(); //第一次编译把这个掉了,找了好久才找到 ,要注意
77 printf("\nInput student name :");
78 gets(name);
79 }
80 else
81 {
82 printf("\nInput Erroe !");
83 exit(1);
84 }
85
86 return ;
87 }
88
89 float *search(int *num , char *flag , char *name , char *p_name , int *p_num , float *score)
90 {
91 int i ;
92
93 if(*flag == 'n' || *flag == 'N')
94 {
95 for(i = 0 ; i < N ; i++)
96 {
97 while(*num == *(p_num + i))
98 return ( score + i * 4 ) ;
99 }
100 }
101 else if(*flag == 'c' || *flag == 'C')
102 {
103 for(i = 0 ; i < N ; i++)
104 {
105 while(strcmp(name , p_name + i * 20) == 0)
106 return ( score + i * 4 ) ;
107 }
108 }
109 else
110 {
111 printf("\nNot found !");
112 exit(1);
113 }
114 }
115
116 void repo(int *stu_num , char *stu_name , float * score , float *score_i)
117 {
118 int i , j ;
119 i = (score_i - score) / 4 ;
120 printf("\nNo.\tName\t\tmath\tphys\tengl\taveragr");
121
122 printf("\n%-8d", *(stu_num + i));
123
124 printf("%-16s", stu_name + i * 20);
125
126 for(j = 0 ; j < 4 ; j++)
127 {
128 printf("%-8.2f", *(score_i + j));
129 }
130
131 printf("\n");
132
133 return ;
134 }

posted @ 2011-08-19 15:29  MATRIX | yan  阅读(1249)  评论(0编辑  收藏  举报