#include <stdio.h>#include <stdlib.h>#include <windows.h>#include <string.h>#define N 20struct xk{ int num; char name[20]; char xz; int zks; int ks; int syks; int xf; int kk;}kc[N];void lr(){ FILE *fp; int i,n; fp=fopen("d://kcxx.txt","ab+"); if(fp==NULL){ printf("Can not open file\n"); exit(1); } printf("输入几门课程信息\n"); scanf("%d",&n); for(i=0;i<n;i++) { printf("请输入课程编号\n"); scanf("%d",&kc[i].num); printf("请输入课程名称\n"); gets(kc[i].name); printf("请输入课程性质\n"); scanf("%c",&kc[i].xz); printf("请输入课程总课时\n"); scanf("%d",&kc[i].zks); printf("请输入课程授课课时\n"); scanf("%d",&kc[i].ks); printf("请输入课程实验课时\n"); scanf("%d",&kc[i].syks); printf("请输入课程学分\n"); scanf("%d",&kc[i].xf); printf("请输入课程开课学期\n"); scanf("%d",&kc[i].kk); fwrite(&kc[i],sizeof(struct xk),8,fp); } fclose(fp);}void ll(){ FILE *fp; int i; fp=fopen("d://kcxx.txt","ab+"); if(fp==NULL){ printf("Can not open file\n"); exit(1); } for(i=0;i<N;i++){ fread(&kc[i],sizeof(struct xk),8,fp); printf("%d\t%s\t%c\t%d\t%d\t%d\t%d\t%d\t",&kc[i].num,&kc[i].name,&kc[i].xz,&kc[i].zks,&kc[i].ks,&kc[i].syks,&kc[i].xf,&kc[i].kk); } fclose(fp);}void xfcx(){ FILE *fp; struct xk kc1[N]; int i,n; fp=fopen("d://kcxx.txt","rb"); if(fp==NULL){ printf("Can not open file\n"); exit(1); } printf("输入学分\n"); scanf("%d",&i); for(n=0;n<N;n++){ fread(&kc1[n],sizeof(struct xk),1,fp); if(i==kc1[n].xf) { printf("%d\t%s\t%c\t%d\t%d\t%d\t%d\t%d\t",&kc[i].num,&kc[i].name,&kc[i].xz,&kc[i].zks,&kc[i].ks,&kc[i].syks,&kc[i].xf,&kc[i].kk); }}void xfcx(){ FILE *fp; struct xk kc1[N]; int i,n; fp=fopen("d://kcxx.txt","rb"); if(fp==NULL){ printf("Can not open file\n"); exit(1); } printf("输入学分\n"); scanf("%d",&i); for(n=0;n<N;n++){ fread(&kc1[n],sizeof(struct xk),1,fp); if(i==kc1[n].xf) { printf("%d\t%s\t%c\t%d\t%d\t%d\t%d\t%d\t",&kc[i].num,&kc[i].name,&kc[i].xz,&kc[i].zks,&kc[i].ks,&kc[i].syks,&kc[i].xf,&kc[i].kk); }}void cx(){ FILE *fp; int i; fp=fopen("d://kcxx.txt","ab+"); if(fp==NULL){ printf("Can not open file\n"); exit(1); } printf("1、学分查询,2、课程性质查询"); scanf("%d",&i); switch(i) { case 1:xfcx(); break; case 2:xzcx(); break; default:printf("输入有误,重新输入。\n"); sleep(1000); }}
添加回答
举报
0/150
提交
取消