录入学生信息,把学生信息存入磁盘文件中,创建一个简易的学生成绩管理系统。

创建学生成绩管理系统。
要求:
1、使用格式输入输出函数
2、学生信息包括:姓名、学号、3门课成绩(语数英)
3、学生信息存入cj.txt文件 4、能使用cat命令显示cj.txt文件内容。
一、源码
1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<string.h>
4
5 #define N 2
6 struct student
7 {
8 char name[10];
9 int num;
10 int cscore;
11 int mscore;
12 int escore;
13 int sum;
14 }stu[N];
15 void sum() //对语数外三门成绩求和
16 {
17 int i;
18 for(i=0;i<N;i++)
19 {
20 stu[i].sum=stu[i].cscore+stu[i].mscore+stu[i].escore;
21 printf(“num total score\n”);
22 printf("%d %d\n",stu[i].num,stu[i].sum);
23 }
24 return;
25 }
26 void seek() //输入学号进行查询
27 {
28 int i,item;
29 int flag=0;
30 printf(“please input num of student\n”);
31 scanf("%d",&item);
32 for(i=0;i<N;i++)
33 {
34 if(item==stu[i].num)
35 {
36 flag=1;
37 printf(“name num cscore mscore escore:\n”);
38 printf("%s %d %d %d %d\n",stu[i].name,stu[i].num,stu[i].cscore,stu[i].mscore,stu[i].escore);
39 }
40 }
41 if(flag= =0)
42 {
43 printf(“num is not exit\n”);
44 }
45 return;
46 }
47
48 int main()
49 {
50 FILE *fp;
51 int i=0;
52 int n;
53
54 printf(“please input information of student:name num csore mscore escore\n”);
55 if((fp=fopen(“cj.txt”,“wr”))==NULL)
56 {
57 printf(“open fail”);
58 return -1;
59 }
60 for(i=0;i<N;i++)
61 {
62 scanf("%s %d %d %d %d",stu[i].name,&stu[i].num,&stu[i].cscore,&stu[i].mscore,&stu[i].escore);//输入学生信息
63
64 fprintf(fp,"%s %d %d %d %d\n",stu[i].name,stu[i].num,stu[i].cscore,stu[i].mscore,stu[i].escore);//将学生信息写入cj.txt文件
65
66 }
67 printf(“1-- View sum score of student ; 2–seek stuent’s score by num\n”);//输入1为求语数外三门总成绩,输入2进行对某个学生成绩的查询
68 scanf("%d",&n);
69 switch(n)
70 {
71 case 1:
72 sum();
73 break;
74 case 2:
75 seek();
76 break;
77 default:
78 break;
79 }
80 fclose(fp);
81 return 0;
82 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值