1.c ͼƬ?图统源???ϵͳԴ??
c ͼƬ????ϵͳԴ??
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const unsigned MAXSTUDS = ; // 学生人数
const unsigned MAXITEMS = 4; // 课程数目
struct student {
unsigned id; // 学号
char name[];
double scores[MAXITEMS + 2]; // 增加平均成绩和总成绩
}stus[MAXSTUDS];
int num_stus = 0; // 当前学生人数
char filename[] = { '\0'}; // 学生数据文件的名称
// 读磁盘数据
void ReadFile() {
int i,an;
FILE *fin;
if(filename[0] == '\0') {
printf("请输入文件名:");
fflush(stdin);
gets(filename);
}
fin = fopen(filename,"rb");
if(fin == NULL) {
printf("不能打开文件:%s\n",filename);
return;
}
if(num_stus > 0) {
do {
printf("新读入的数据将:\n1、追加到现有数据的片管片库的尾部\n2、覆盖现有数据\n");
printf("请选择:");
}while(scanf("%d",理系车库收费系统源码&an) != 1 || an < 1 || an > 2);
switch(an) {
case 1 : for(i = num_stus; i < MAXSTUDS && !feof(fin); ++i) {
if(fread(&stus[i],sizeof(struct student),1,fin) != 1)
break;
}
num_stus = i;
fclose(fin);
break;
case 2 : for(i = 0; i < MAXSTUDS && !feof(fin); ++i) {
if(fread(&stus[i],sizeof(struct student),1,fin) != 1)
break;
}
num_stus = i;
fclose(fin);
break;
}
}
else {
for(i = 0; i < MAXSTUDS && !feof(fin); ++i)
fread(&stus[i],sizeof(struct student),1,fin);
num_stus = i;
fclose(fin);
}
}
// 数据存盘
void WriteFile() {
int i;
FILE *fout;
if(filename[0] == '\0') {
printf("请输入文件名:");
fflush(stdin);
gets(filename);
}
fout = fopen(filename,"wb");
if(fout == NULL) {
printf("无法打开文件:%s\n",filename);
return;
}
printf("正在写文件:%s......\n",filename);
for(i = 0; i < num_stus; ++i)
fwrite(&stus[i],sizeof(struct student),1,fout);
printf("成功创建文件:%s\n",filename);
}
// 读入学生的信息,总成绩和平均成绩由计算获取
void ReadData(struct student *a,码图int model) { // model 1:不用读入学号,2:不用读入姓名
int i;
if(model != 1) {
printf("学号:");
scanf("%u",管理网贷源码论坛&a->id);
}
if(model != 2) {
fflush(stdin);
printf("姓名:");
gets(a->name);
}
printf("输入%d门成绩(空格隔开):",MAXITEMS);
a->scores[MAXITEMS + 1] = 0;
for(i = 0; i < MAXITEMS; ++i) {
scanf("%lf",&a->scores[i]);
a->scores[MAXITEMS + 1] += a->scores[i];
}
a->scores[MAXITEMS] = a->scores[MAXITEMS + 1] / MAXITEMS;
}
void Browse() {
int i,j,nopass[MAXITEMS];
double score,total[MAXITEMS];
double min[MAXITEMS]; // 各科最差成绩
double max[MAXITEMS]; // 各科最好成绩
if(num_stus == 0) return;
for(i = 0; i < MAXITEMS; ++i) {
min[i] = ;
max[i] = total[i] = 0;
nopass[i] = 0;
}
for(i = 0; i < + 8 * MAXITEMS; ++i) printf("*");
printf("\n");
for(i = 0; i < num_stus; ++i) {
printf("%d %6s ",stus[i].id,stus[i].name);
for(j = 0; j < MAXITEMS; ++j) {
score = stus[i].scores[j];
printf("%7.2lf ",score);
total[j] += score;
if(score < min[j]) min[j] = score;
if(score > max[j]) max[j] = score;
if(score < ) ++nopass[j];
}
printf("%7.2lf %7.2lf\n",stus[i].scores[MAXITEMS],stus[i].scores[MAXITEMS + 1]);
}
for(i = 0; i < + 8 * MAXITEMS; ++i) printf("*");
printf("\n");
printf(" 最好成绩 ");
for(i = 0; i < MAXITEMS; ++i) printf("%7.2lf ",max[i]);
printf("\n");
printf(" 最差成绩 ");
for(i = 0; i < MAXITEMS; ++i) printf("%7.2lf ",min[i]);
printf("\n");
printf(" 平均成绩 ");
for(i = 0; i < MAXITEMS; ++i) printf("%7.2lf ",total[i] / num_stus );
printf("\n");
printf(" 不及格人数 ");
for(i = 0; i < MAXITEMS; ++i) printf("%7d ",nopass[i]);
printf("\n");
for(i = 0; i < + 8 * MAXITEMS; ++i) printf("-");
printf("\n");
}
int HasThis(unsigned id) {
int i;
for(i = 0; i < num_stus; ++i) {
if(stus[i].id == id)
return i;
}
return -1;
}
void Insert() {
int an;
struct student *a;
do {
a = &stus[num_stus];
printf("请输入学号:");
scanf("%u",&a->id);
if(HasThis(a->id) == -1) {
ReadData(a,1);
++num_stus;
do {
fflush(stdin);
printf("0:返回,其他继续。系统屏幕 RGB调节源码\n");
printf("请选择:");
}while(scanf("%d",源码&an) != 1);
}
else printf("重复的学号:%u\n",a->id);
}while(an && num_stus < MAXSTUDS - 1);
}
void Query() {
unsigned id;
int j,res;
printf("请输入学号:");
scanf("%u",&id);
res = HasThis(id);
if(res >= 0) {
printf("%d %6s ",stus[res].id,stus[res].name);
for(j = 0; j < MAXITEMS + 2; ++j)
printf("%7.2lf ",stus[res].scores[j]);
printf("\n");
}
else printf("没有找到学号是:%u 的学生。\n",图统源id);
}
void Sort() {
int i,j,k;
struct student t;
for(i = 0; i < num_stus - 1; ++i) {
k = i;
for(j = i + 1; j < num_stus; ++j) {
if(stus[k].scores[MAXITEMS + 1] < stus[j].scores[MAXITEMS + 1])
k = j;
}
if(k != i) {
t = stus[i];
stus[i] = stus[k];
stus[k] = t;
}
}
}
int Erase() {
int i,res;
unsigned id;
printf("请输入学号:");
scanf("%u",&id);
res = HasThis(id);
if(res == -1) {
printf("没有找到学号是:%u 的学生。\n",片管片库id);
return 0;
}
for(i = res; i < num_stus - 1; ++i)
stus[i] = stus[i + 1];
--num_stus;
printf("删除成功。\n");
return 1;
}
int menu_select() {
int com;
char cn[];
printf("\t1、理系录入\n");
printf("\t2、码图浏览\n");
printf("\t3、管理查询\n");
printf("\t4、系统捕鱼源码包括哪些排序\n");
printf("\t5、源码删除\n");
printf("\t6、图统源医美面膜源码读文件\n");
printf("\t7、写文件\n");
printf("\t0、退出管理系统\n\n");
printf("\t选择0 - 7:");
for(;;) {
fflush(stdin);
gets(cn);
com = atoi(cn);
if(com < 0 || com > 7) printf("输入错误,重新选择0 - 7:");
else break;
}
return com;
}
void handle_menu() {
for(;;) {
switch(menu_select()) {
case 1 : printf(">> 录入......\n"); Insert(); break;
case 2 : printf(">> 浏览......\n"); Browse(); break;
case 3 : printf(">> 查询......\n"); Query(); break;
case 4 : printf(">> 排序......\n"); Sort(); break;
case 5 : printf(">> 删除......\n"); Erase(); break;
case 6 : printf(">> 读数据文件......\n"); ReadFile(); break;
case 7 : printf(">> 数据存盘......\n");WriteFile(); break;
case 0 : printf(">> 退出管理系统\n"); return; break;
}
}
}
int main() {
handle_menu();
return 0;
}