一个自动管理学生信息的控制台应用程序(C语言)Label:Water

 

 

//学生统计 Ver 6.0
//2018年11月25日
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define MAXN_stu 35
#define MAXN_cl 7
#define MAXN_name 20
#define MAXN_lv 6
int N_cl, N_stu;
int sum[MAXN_cl];
double aver[MAXN_cl];
int lv[MAXN_cl][MAXN_lv];
double percent_lv[MAXN_cl][MAXN_lv];

struct cc {//定义结构体
	int sum;
	int num, cl[MAXN_cl];
	char name[MAXN_name];
	double aver;
}nd[MAXN_stu];

void hp(){//帮助信息打印
    //输出提示信息
	puts("1.Input record");
	puts("2.Calculate tatal and average score of every course");
	puts("3.Calculate tatal and average score of every student");
	puts("4.Sort in descending order by total score of every student");
	puts("5.Sort in ascending order by total score of every student");
	puts("6.Sort in ascending order by number");
	puts("7.Sort in ascending order by name");
	puts("8.Search by number");
	puts("9.Search by name");
	puts("10.Statistic analysis for every course");
	puts("11.List record");
	puts("12.Write to a file");
	puts("13.Read from a flie");
	puts("14.Random data generation");
	puts("0.Exit");
	puts("Please enter you choice:");
}

void logo_lrb(){//LOGO打印
    puts("           |##########@!                                  |##%.   ;##@:                                                  :@#@:               '&##;               `");
    puts("          ;###%;;;;|@####;                               ;##@:                                                          `$##|               .%##%.               `");
    puts("         '&##|       ;###!                              '&##!                                                           |##$`               !##&'                `");
    puts("         |##&'      .%##$`   `%#######$`      .|######$:|##%.   ;##@'   :@##:      %##%.   !##%`;@#####!  ;@#####|     ;##@:   '&##;`$##&` '@##;'&######!        `");
    puts("        ;###;      :@##$.  `$##$`  `&##%    :@##@;. .!####@'   '&##!   `$##|      ;##@'   :@###@!``|####@@!``!###@'   `$##!    |##&&#%;:. .%####%'  '&###|       `");
    puts("       '&############$`            '&##!   |##&'      !###!   .%##%.   |##$`     '&##!   .%##@'    `$##@:    .%##$.   |##$.   ;###$`      !###!      '@##|       `");
    puts("      .%###&$&###&'        .;&########$.  |##&`      .%##%.   ;##&'   ;##@:     .%##%.   !##&'     ;##@'     ;##@:   ;##@:   '&##|       :@##;       !###:       `");
    puts("      ;###;   ;###!      !###%`   ;##@:  ;###;       ;##&'   '&##;   `$##!      !##&'   :@##;     '&##!     `$##!   '&##!    |##%.      .$##|       '&##|        `");
    puts("     '&##|    .%##@:   .%##$`    :@##!  .%##$`      !###;   .%##%.   |##&'     !###;   .$##|     .%##%.     |##$.   |##%.   ;##@'       !###;      '&##|         `");
    puts("    .%##$`     ;###%.  ;###|   `$###%.  .%###!    !@###%.   !##&'   `$###;   !@###%.   !##$`     !##&'     ;##@:   ;##@'   '&##!       :@###$`   '$##@:          `");
    puts("    !##@:      .%###!  '&######!!##@'    '&######@;!##&'   '@##;     |######@:;@#&'   :@##;     '&##;     '&##!   '&##!   .%##%.      `$##!;@######&'            `");
    puts("\n ---------------------------------------------------------------------------------------------------------------------------------------------------------------");
}

void gesture0(){//系统基本界面
    system("cls");
    logo_lrb();
    puts("Welcome to Student Information Management System.");
    hp();
}

void id_identify(){//身份认证
    char ch;
    char a[10]={"password"};
    char b[10];
    system("mode con: cols=180");
    puts("Welcome to Student Information Management System.");
    puts("ID:admin");
    printf("Password:");
    while(1){
        scanf("%s",b);
        if(strcmp(a,b)==0){
            break;
        }
        else{
            puts("Wrong Password.Continue?(y/n)");
            scanf(" %c",&ch);
            if(ch=='y') continue;
            else exit(0);
        }
    }
    gesture0();
}

void init_() {//对数据进行录入
	int i, j;
	memset(sum, 0, sizeof(sum));//对sum数组进行初始化操作
	memset(aver, 0.0, sizeof(aver));//对aver数组进行初始化操作
	memset(lv, 0, sizeof(lv));//对sum数组进行初始化操作
	scanf("%d%d", &N_cl, &N_stu);
	for (i = 1; i <= N_stu; i++) {//数据输入
		scanf("%d%s", &nd[i].num, &nd[i].name);
		for (j = 1; j <= N_cl; j++) {
			scanf("%d", &nd[i].cl[j]);
		}
	}
}

void GDATA(){//随机数据生成
    int i, j;
    printf("Please input the num of class and student:");
	memset(sum, 0, sizeof(sum));//对sum数组进行初始化操作
	memset(aver, 0.0, sizeof(aver));//对aver数组进行初始化操作
	memset(lv, 0, sizeof(lv));//对sum数组进行初始化操作
	srand(time(NULL));
	scanf("%d%d", &N_cl, &N_stu);
	for (i = 1; i <= N_stu; i++) {//数据输入
	    nd[i].num=19000+rand()%(100);
	    for(j=0;j<=5;j++)nd[i].name[j]=rand()%26+'A';
		for (j = 1; j <= N_cl; j++) {
			nd[i].cl[j]=rand()%101;
		}
	}
}

void cal() {//计算汇总
	int i, j;
	for (i = 1; i <= N_stu; i++) nd[i].sum = 0;
	for (i = 1; i <= N_stu; i++) {//计算每个学生的总分和平均分
		for (j = 1; j <= N_cl; j++) {
			nd[i].sum += nd[i].cl[j];//计算每个学生的总分
		}
		nd[i].aver = (double)nd[i].sum / (double)N_cl;//计算每个学生的平均分
	}
	for (i = 1; i <= N_cl; i++) {//计算每门课程的总分和平均分
		for (j = 1; j <= N_stu; j++) {//计算每门课程的总分
			sum[i] += nd[j].sum;
		}
		aver[i] = (double)sum[i] / (double)N_cl;//计算每门课程的平均分
	}

}

void lv_() {//计算各个分数段的学生
	int i, j;
	printf("class\t\t优秀(90-100)\t良好(80-89)\t中等(70-79)\t及格(60-69)\t不及格(0-59)\n");
	for (i = 1; i <= N_cl; i++) {
		for (j = 1; j <= N_stu; j++) {//对每个分数段的人员数量进行统计
			if (nd[j].cl[i] >= 90)      lv[i][1]++;//90+
			else if (nd[j].cl[i] >= 80) lv[i][2]++;//80-89
			else if (nd[j].cl[i] >= 70) lv[i][3]++;//70-79
			else if (nd[j].cl[i] >= 60) lv[i][4]++;//60-69
			else                        lv[i][5]++;//0-59
		}
		for (j = 1; j <= 5; j++) {//对每个分数段的人员比例进行统计
			percent_lv[i][j] = (double)lv[i][j] / (double)N_stu;
		}

		printf("class%d", i);
		for (j = 1; j <= 5; j++) {//对每个分数段的人员数量进行输出
			printf("\t\t%d(%.2llf)", lv[i][j], percent_lv[i][j]);
		}
		puts("");
	}

}

void sort_sum_down() {//冒泡排序按照降序对数据总分进行排序
	int i, j;
	struct cc tmp;
	for (i = 1; i <= N_stu; i++) {
		for (j = 1; j <= N_stu - 1; j++) {
			if (nd[j].sum < nd[j + 1].sum) {
				tmp = nd[j];
				nd[j] = nd[j + 1];
				nd[j + 1] = tmp;
			}
		}
	}
}

void sort_sum_up() {//冒泡排序按照升序对数据总分进行排序
	int i, j;
	struct cc tmp;
	for (i = 1; i <= N_stu; i++) {
		for (j = 1; j <= N_stu - 1; j++) {
			if (nd[j].sum > nd[j + 1].sum) {
				tmp = nd[j];
				nd[j] = nd[j + 1];
				nd[j + 1] = tmp;
			}
		}
	}
}

void sort_num() {//冒泡排序按照升序对数据学号进行排序
	int i, j;
	struct cc tmp;
	for (i = 1; i <= N_stu; i++) {
		for (j = 1; j <= N_stu - 1; j++) {
			if (nd[j].num > nd[j + 1].num) {
				tmp = nd[j];
				nd[j] = nd[j + 1];
				nd[j + 1] = tmp;
			}
		}
	}
}

void sort_name() {//冒泡排序按照升序对数据姓名进行排序
	int i, j;
	struct cc tmp;
	for (i = 1; i <= N_stu; i++) {
		for (j = 1; j <= N_stu - 1; j++) {
			//            printf("%d\n",strcmp(nd[j].name, nd[j+1].name));
			if (strcmp(nd[j].name, nd[j + 1].name) > 0) {

				tmp = nd[j];
				nd[j] = nd[j + 1];
				nd[j + 1] = tmp;
			}
		}
	}
}

void qry_num() {//按照学号查询学生排名以及其考试成绩
	int i, j, tmp_num;
	scanf("%d", &tmp_num);
	printf("rank\tnum\tname");
	for (j = 1; j <= N_cl; j++) {
		printf("\tclass%d", j);
	}
	printf("\tsum\taver\n");
	for (i = 1; i <= N_stu; i++) {
		if (tmp_num == nd[i].num) {
			printf("%d\t%d\t%s", i, nd[i].num, nd[i].name);
			for (j = 1; j <= N_cl; j++) {
				printf("\t%d", nd[i].cl[j]);
			}
			printf("\t%d\t%.2llf", nd[i].sum, nd[i].aver);
			puts("");
		}
	}
}

void qry_name() {//按照姓名查询学生排名以及其考试成绩
	int i, j;
	char tmp_name[MAXN_name];
	scanf("%s", tmp_name);
	printf("rank\tnum\tname");
	for (j = 1; j <= N_cl; j++) {
		printf("\tclass%d", j);
	}
	printf("\tsum\taver\n");
	for (i = 1; i <= N_stu; i++) {
		if (strcmp(nd[i].name, tmp_name) == 0) {
			printf("%d\t%d\t%s", i, nd[i].num, nd[i].name);
			for (j = 1; j <= N_cl; j++) {
				printf("\t%d", nd[i].cl[j]);
			}
			printf("\t%d\t%.2llf", nd[i].sum, nd[i].aver);
			puts("");
		}
	}
}

void prt_all() {//打印所有学生成绩
	int i, j;
	printf("rank\tnum\tname");
	for (j = 1; j <= N_cl; j++) {
		printf("\tclass%d", j);
	}
	printf("\tsum\taver\n");
	for (i = 1; i <= N_stu; i++) {
		printf("%d\t%d\t%s", i, nd[i].num, nd[i].name);
		for (j = 1; j <= N_cl; j++) {
			printf("\t%d", nd[i].cl[j]);
		}
		printf("\t%d\t%.2llf", nd[i].sum, nd[i].aver);
		puts("");
	}
}

void fprt_() {//读取文件并输出
	char ch;
	FILE *fp = NULL;
	if ((fp = fopen("stu.txt", "r")) == NULL) {
		printf("Failure ro open stu.txt!\n");
		exit(0);
	}
	while ((ch = fgetc(fp)) != EOF) {
		printf("%c", ch);
	}
	fclose(fp);
}

void fout_() {//输出到文件
	FILE *fp = NULL;
	if ((fp = fopen("stu.txt", "w")) == NULL) {
		printf("Failure ro open stu.txt!\n");
		exit(0);
	}

	int i, j;
	fprintf(fp, "rank\tnum\tname");
	for (j = 1; j <= N_cl; j++) {
		fprintf(fp, "\tclass%d", j);
	}
	fprintf(fp, "\tsum\taver\n");
	for (i = 1; i <= N_stu; i++) {
		fprintf(fp, "%d\t%d\t%s", i, nd[i].num, nd[i].name);
		for (j = 1; j <= N_cl; j++) {
			fprintf(fp, "\t%d", nd[i].cl[j]);
		}
		fprintf(fp, "\t%d\t%.2llf\n", nd[i].sum, nd[i].aver);
	}
	fclose(fp);
}

void swt(){
    int op;
    while (1) {
		scanf("%d", &op);
		if (op==0) break;
		else if(op>14||op<0) gesture0();
		else switch (op) {
		case 1:
			init_();//数据输入
			break;
		case 2:
			cal();//计算一体化
			break;
		case 3:
			cal();//计算一体化
			break;
		case 4:
			sort_sum_down();//按照总分降序排序
			prt_all();
			break;
		case 5:
			sort_sum_up();//按照总分升序排序
			prt_all();
			break;
		case 6:
			sort_num();//按照学号排序
			prt_all();
			break;
		case 7:
			sort_name();//按照字典序排序
			prt_all();
			break;
		case 8:
			qry_num();//按照学号查找
			break;
		case 9:
			qry_name();//按照姓名查找
			break;
		case 10:
			lv_();//数据分组
			break;
		case 11:
			prt_all();//打印所有数据
			break;
		case 12:
			fout_();//写入到文件stu.txt
			break;
		case 13:
			fprt_();//从文件读取并显示到屏幕上
			break;
        case 14:
            GDATA();//数据生成
            break;
		default:
		    gesture0();//系统基本界面
		    break;
		}
	}
}

int main() {
	id_identify();//身份认证,默认密码password
    swt();//操作符选择

	return 0;
}

 

固定图形界面

 

//学生统计 Ver 6.0.1
//1182100222 林若彬 实验大作业
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define MAXN_stu 35
#define MAXN_cl 7
#define MAXN_name 20
#define MAXN_lv 6
int N_cl, N_stu;
int sum[MAXN_cl];
double aver[MAXN_cl];
int lv[MAXN_cl][MAXN_lv];
double percent_lv[MAXN_cl][MAXN_lv];

struct cc {//定义结构体
	int sum;
	int num, cl[MAXN_cl];
	char name[MAXN_name];
	double aver;
}nd[MAXN_stu];

void hp(){//帮助信息打印
    //输出提示信息
	puts("1.Input record");
	puts("2.Calculate tatal and average score of every course");
	puts("3.Calculate tatal and average score of every student");
	puts("4.Sort in descending order by total score of every student");
	puts("5.Sort in ascending order by total score of every student");
	puts("6.Sort in ascending order by number");
	puts("7.Sort in ascending order by name");
	puts("8.Search by number");
	puts("9.Search by name");
	puts("10.Statistic analysis for every course");
	puts("11.List record");
	puts("12.Write to a file");
	puts("13.Read from a flie");
	puts("14.Random data generation");
	puts("0.Exit");
	puts("Please enter you choice:");
}

void logo_lrb(){//LOGO打印
    puts("           |##########@!                                  |##%.   ;##@:                                                  :@#@:               '&##;               `");
    puts("          ;###%;;;;|@####;                               ;##@:                                                          `$##|               .%##%.               `");
    puts("         '&##|       ;###!                              '&##!                                                           |##$`               !##&'                `");
    puts("         |##&'      .%##$`   `%#######$`      .|######$:|##%.   ;##@'   :@##:      %##%.   !##%`;@#####!  ;@#####|     ;##@:   '&##;`$##&` '@##;'&######!        `");
    puts("        ;###;      :@##$.  `$##$`  `&##%    :@##@;. .!####@'   '&##!   `$##|      ;##@'   :@###@!``|####@@!``!###@'   `$##!    |##&&#%;:. .%####%'  '&###|       `");
    puts("       '&############$`            '&##!   |##&'      !###!   .%##%.   |##$`     '&##!   .%##@'    `$##@:    .%##$.   |##$.   ;###$`      !###!      '@##|       `");
    puts("      .%###&$&###&'        .;&########$.  |##&`      .%##%.   ;##&'   ;##@:     .%##%.   !##&'     ;##@'     ;##@:   ;##@:   '&##|       :@##;       !###:       `");
    puts("      ;###;   ;###!      !###%`   ;##@:  ;###;       ;##&'   '&##;   `$##!      !##&'   :@##;     '&##!     `$##!   '&##!    |##%.      .$##|       '&##|        `");
    puts("     '&##|    .%##@:   .%##$`    :@##!  .%##$`      !###;   .%##%.   |##&'     !###;   .$##|     .%##%.     |##$.   |##%.   ;##@'       !###;      '&##|         `");
    puts("    .%##$`     ;###%.  ;###|   `$###%.  .%###!    !@###%.   !##&'   `$###;   !@###%.   !##$`     !##&'     ;##@:   ;##@'   '&##!       :@###$`   '$##@:          `");
    puts("    !##@:      .%###!  '&######!!##@'    '&######@;!##&'   '@##;     |######@:;@#&'   :@##;     '&##;     '&##!   '&##!   .%##%.      `$##!;@######&'            `");
    puts("\n ---------------------------------------------------------------------------------------------------------------------------------------------------------------");
}

void gesture0(){//系统基本界面
    system("cls");
    logo_lrb();
    puts("Welcome to Student Information Management System.");
    hp();
}

void id_identify(){//身份认证
    char ch;
    char a[10]={"password"};
    char b[10];
    system("mode con: cols=180");
    puts("Welcome to Student Information Management System.");
    puts("ID:admin");
    printf("Password:");
    while(1){
        scanf("%s",b);
        if(strcmp(a,b)==0){
            break;
        }
        else{
            puts("Wrong Password.Continue?(y/n)");
            scanf(" %c",&ch);
            if(ch=='y') continue;
            else exit(0);
        }
    }
    gesture0();
}

void init_() {//对数据进行录入
	int i, j;
	memset(sum, 0, sizeof(sum));//对sum数组进行初始化操作
	memset(aver, 0.0, sizeof(aver));//对aver数组进行初始化操作
	memset(lv, 0, sizeof(lv));//对sum数组进行初始化操作
	scanf("%d%d", &N_cl, &N_stu);
	for (i = 1; i <= N_stu; i++) {//数据输入
		scanf("%d%s", &nd[i].num, &nd[i].name);
		for (j = 1; j <= N_cl; j++) {
			scanf("%d", &nd[i].cl[j]);
		}
	}
}

void GDATA(){//随机数据生成
    int i, j;
    printf("Please input the num of class and student:");
	memset(sum, 0, sizeof(sum));//对sum数组进行初始化操作
	memset(aver, 0.0, sizeof(aver));//对aver数组进行初始化操作
	memset(lv, 0, sizeof(lv));//对sum数组进行初始化操作
	srand(time(NULL));
	scanf("%d%d", &N_cl, &N_stu);
	for (i = 1; i <= N_stu; i++) {//数据输入
	    nd[i].num=19000+rand()%(100);
	    for(j=0;j<=5;j++)nd[i].name[j]=rand()%26+'A';
		for (j = 1; j <= N_cl; j++) {
			nd[i].cl[j]=rand()%101;
		}
	}
}

void cal() {//计算汇总
	int i, j;
	for (i = 1; i <= N_stu; i++) nd[i].sum = 0;
	for (i = 1; i <= N_stu; i++) {//计算每个学生的总分和平均分
		for (j = 1; j <= N_cl; j++) {
			nd[i].sum += nd[i].cl[j];//计算每个学生的总分
		}
		nd[i].aver = (double)nd[i].sum / (double)N_cl;//计算每个学生的平均分
	}
	for (i = 1; i <= N_cl; i++) {//计算每门课程的总分和平均分
		for (j = 1; j <= N_stu; j++) {//计算每门课程的总分
			sum[i] += nd[j].sum;
		}
		aver[i] = (double)sum[i] / (double)N_cl;//计算每门课程的平均分
	}

}

void lv_() {//计算各个分数段的学生
	int i, j;
	printf("class\t\t优秀(90-100)\t良好(80-89)\t中等(70-79)\t及格(60-69)\t不及格(0-59)\n");
	for (i = 1; i <= N_cl; i++) {
		for (j = 1; j <= N_stu; j++) {//对每个分数段的人员数量进行统计
			if (nd[j].cl[i] >= 90)      lv[i][1]++;//90+
			else if (nd[j].cl[i] >= 80) lv[i][2]++;//80-89
			else if (nd[j].cl[i] >= 70) lv[i][3]++;//70-79
			else if (nd[j].cl[i] >= 60) lv[i][4]++;//60-69
			else                        lv[i][5]++;//0-59
		}
		for (j = 1; j <= 5; j++) {//对每个分数段的人员比例进行统计
			percent_lv[i][j] = (double)lv[i][j] / (double)N_stu;
		}

		printf("class%d", i);
		for (j = 1; j <= 5; j++) {//对每个分数段的人员数量进行输出
			printf("\t\t%d(%.2llf)", lv[i][j], percent_lv[i][j]);
		}
		puts("");
	}

}

void sort_sum_down() {//冒泡排序按照降序对数据总分进行排序
	int i, j;
	struct cc tmp;
	for (i = 1; i <= N_stu; i++) {
		for (j = 1; j <= N_stu - 1; j++) {
			if (nd[j].sum < nd[j + 1].sum) {
				tmp = nd[j];
				nd[j] = nd[j + 1];
				nd[j + 1] = tmp;
			}
		}
	}
}

void sort_sum_up() {//冒泡排序按照升序对数据总分进行排序
	int i, j;
	struct cc tmp;
	for (i = 1; i <= N_stu; i++) {
		for (j = 1; j <= N_stu - 1; j++) {
			if (nd[j].sum > nd[j + 1].sum) {
				tmp = nd[j];
				nd[j] = nd[j + 1];
				nd[j + 1] = tmp;
			}
		}
	}
}

void sort_num() {//冒泡排序按照升序对数据学号进行排序
	int i, j;
	struct cc tmp;
	for (i = 1; i <= N_stu; i++) {
		for (j = 1; j <= N_stu - 1; j++) {
			if (nd[j].num > nd[j + 1].num) {
				tmp = nd[j];
				nd[j] = nd[j + 1];
				nd[j + 1] = tmp;
			}
		}
	}
}

void sort_name() {//冒泡排序按照升序对数据姓名进行排序
	int i, j;
	struct cc tmp;
	for (i = 1; i <= N_stu; i++) {
		for (j = 1; j <= N_stu - 1; j++) {
			//            printf("%d\n",strcmp(nd[j].name, nd[j+1].name));
			if (strcmp(nd[j].name, nd[j + 1].name) > 0) {

				tmp = nd[j];
				nd[j] = nd[j + 1];
				nd[j + 1] = tmp;
			}
		}
	}
}

void qry_num() {//按照学号查询学生排名以及其考试成绩
	int i, j, tmp_num;
	scanf("%d", &tmp_num);
	printf("rank\tnum\tname");
	for (j = 1; j <= N_cl; j++) {
		printf("\tclass%d", j);
	}
	printf("\tsum\taver\n");
	for (i = 1; i <= N_stu; i++) {
		if (tmp_num == nd[i].num) {
			printf("%d\t%d\t%s", i, nd[i].num, nd[i].name);
			for (j = 1; j <= N_cl; j++) {
				printf("\t%d", nd[i].cl[j]);
			}
			printf("\t%d\t%.2llf", nd[i].sum, nd[i].aver);
			puts("");
		}
	}
}

void qry_name() {//按照姓名查询学生排名以及其考试成绩
	int i, j;
	char tmp_name[MAXN_name];
	scanf("%s", tmp_name);
	printf("rank\tnum\tname");
	for (j = 1; j <= N_cl; j++) {
		printf("\tclass%d", j);
	}
	printf("\tsum\taver\n");
	for (i = 1; i <= N_stu; i++) {
		if (strcmp(nd[i].name, tmp_name) == 0) {
			printf("%d\t%d\t%s", i, nd[i].num, nd[i].name);
			for (j = 1; j <= N_cl; j++) {
				printf("\t%d", nd[i].cl[j]);
			}
			printf("\t%d\t%.2llf", nd[i].sum, nd[i].aver);
			puts("");
		}
	}
}

void prt_all() {//打印所有学生成绩
	int i, j;
	printf("rank\tnum\tname");
	for (j = 1; j <= N_cl; j++) {
		printf("\tclass%d", j);
	}
	printf("\tsum\taver\n");
	for (i = 1; i <= N_stu; i++) {
		printf("%d\t%d\t%s", i, nd[i].num, nd[i].name);
		for (j = 1; j <= N_cl; j++) {
			printf("\t%d", nd[i].cl[j]);
		}
		printf("\t%d\t%.2llf", nd[i].sum, nd[i].aver);
		puts("");
	}
}

void fprt_() {//读取文件并输出
	char ch;
	FILE *fp = NULL;
	if ((fp = fopen("stu.txt", "r")) == NULL) {
		printf("Failure ro open stu.txt!\n");
		exit(0);
	}
	while ((ch = fgetc(fp)) != EOF) {
		printf("%c", ch);
	}
	fclose(fp);
}

void fout_() {//输出到文件
	FILE *fp = NULL;
	if ((fp = fopen("stu.txt", "w")) == NULL) {
		printf("Failure ro open stu.txt!\n");
		exit(0);
	}

	int i, j;
	fprintf(fp, "rank\tnum\tname");
	for (j = 1; j <= N_cl; j++) {
		fprintf(fp, "\tclass%d", j);
	}
	fprintf(fp, "\tsum\taver\n");
	for (i = 1; i <= N_stu; i++) {
		fprintf(fp, "%d\t%d\t%s", i, nd[i].num, nd[i].name);
		for (j = 1; j <= N_cl; j++) {
			fprintf(fp, "\t%d", nd[i].cl[j]);
		}
		fprintf(fp, "\t%d\t%.2llf\n", nd[i].sum, nd[i].aver);
	}
	fclose(fp);
}

void swt(){
    int op;
    while (1) {
		scanf("%d", &op);
		if (op==0) break;
		else if(op>14||op<0) gesture0();
		else switch (op) {
		case 1:
		    gesture0();
			init_();//数据输入
			break;
		case 2:
		    gesture0();
			cal();//计算一体化
			break;
		case 3:
		    gesture0();
			cal();//计算一体化
			break;
		case 4:
		    gesture0();
			sort_sum_down();//按照总分降序排序
			prt_all();
			break;
		case 5:
		    gesture0();
			sort_sum_up();//按照总分升序排序
			prt_all();
			break;
		case 6:
		    gesture0();
			sort_num();//按照学号排序
			prt_all();
			break;
		case 7:
		    gesture0();
			sort_name();//按照字典序排序
			prt_all();
			break;
		case 8:
		    gesture0();
			qry_num();//按照学号查找
			break;
		case 9:
		    gesture0();
			qry_name();//按照姓名查找
			break;
		case 10:
		    gesture0();
			lv_();//数据分组
			break;
		case 11:
		    gesture0();
			prt_all();//打印所有数据
			break;
		case 12:
		    gesture0();
			fout_();//写入到文件stu.txt
			break;
		case 13:
		    gesture0();
			fprt_();//从文件读取并显示到屏幕上
			break;
        case 14:
            gesture0();
            GDATA();//数据生成
            break;
		default:
		    gesture0();//系统基本界面
		    break;
		}
	}
}

int main() {
	id_identify();//身份认证,默认密码password
    swt();//操作符选择

	return 0;
}

  

posted @ 2018-11-24 23:21  Radiumlrb  阅读(257)  评论(0编辑  收藏  举报