首页 > 其他分享 >C语言实现成绩管理系统

C语言实现成绩管理系统

时间:2023-05-01 20:35:17浏览次数:42  
标签:fp Afterstu angle 管理系统 int C语言 student printf 成绩

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <windows.h>

#include <conio.h>

//定义结构体记录学生基本信息

struct messages

{

       int Class[5];           //班级

       char StudentNum[10]; //学号

       char Sname[10];    //姓名

       char Gender[4];     //性别

       int Age;                //年龄

       int Course[20];             //课程编号

       char  Cname[20]; //课程名称

       int Point;       //学分

       int Fgrade;            //考试成绩

       int Dgrade;           //平时成绩

       double Agrade;     //综合成绩

      

       int Course1[20];           //课程编号

       char  Cname1[20];            //课程名称

       int Point1;            //学分

       int Fgrade1;          //考试成绩

       int Dgrade1;         //平时成绩

       double Agrade1;   //综合成绩

      

       int Course2[20];           //课程编号

       char  Cname2[20];            //课程名称

       int Point2;            //学分

       int Fgrade2;          //考试成绩

       int Dgrade2;         //平时成绩

       double Agrade2;   //综合成绩

};

 

//函数声明

void keys();//密码

void color(int x);//改变颜色

int welcome();//菜单欢迎界面

void SetPosition(int x, int y);//修改光标显示位置

void keyDown(char n);//按键响应

int wel2();//第二层欢迎界面

int wel3();//第三层欢迎界面

int wel4();//第四层欢迎界面

void Getin();//1.录入成绩

void change();//2.修改

void insert();//3.插入

int looking();//4.查询

void deleting();//5.删除

void average();//6.计算平均成绩

void list_under();//7.列出不合格学生成绩

 

int main(int argc, char *argv[])

{

       system("mode con cols=90 lines=25");//改变窗口大小

       system("title 学生成绩管理系统"); //更改控制台名称

       keys();

       while(1)

       {

              system("cls");

              char n = welcome();//此处返回值代表需要进行的操作对应的标号;

              system("cls");

              keyDown(n);

       }

       return 0;

}

 

//0系列函数:准备部分,基础不牢,地动山摇!!!

//0.0改变颜色

void color(int x)

{

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);

}

 

//0.1改变输出坐标

void SetPosition(int x, int y)

{

       COORD p;

       HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);

       p.X = x;

       p.Y = y;

       SetConsoleCursorPosition(handle, p);

 }

 

//0.2欢迎界面

int welcome()

{

       color(14);

       printf("\n\n\n\n\t\t=======================欢迎使用===========================\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t按键1:数据的录入 \t按键2:数据的修改\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t按键3:数据的插入 \t按键4:数据的查询\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t按键5:数据的删除 \t按键6:计算平均成绩\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t按键7:列出不及格学生清单\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

printf("\t\t==========================================================\n");

       color(11);

       printf("\t\t\t请输入您想要进行的操作:[_](按键ESC退出)");

       char n;

       do

       {

              SetPosition(48, 19);

              n = getch();//不带回显

              if(n==27)

              {

                     SetPosition(52, 20);

                     printf("您确定要退出程序(Y/N)?[_]");

                     SetPosition(52, 21);

                     printf("                     ");

                     SetPosition(75, 20);

                     while(1)

                     {

                            n = getch();

                            if(n=='y' || n=='Y')

                            {

                                   SetPosition(52, 21);

                                   color(14);

                                   printf("欢迎您的下次使用,再见!");

                                   sleep(1);

                                   exit(0);

                            }

                            else if(n=='n' || n=='N')

                            {

                                   break;

                            }

                            else

                            {

                                   SetPosition(52, 21);

                                   printf("您的输入有误(Y/N)");

                            }

                     }

              }

              if(n>='1' && n<='7')

              {

                     SetPosition(48, 19);

                     printf("%c", n);

                     break;

              }

              else

              {

                     SetPosition(52, 21);

                     printf("请重新选择操作对象..");

                     SetPosition(52, 20);

                     printf("                        ");

              }

       }while(1);

      

       SetPosition(52, 21);

       color(14);

       SetPosition(52, 21);

       printf("请按任意键继续......");

       getch();

       return n;

 }

 

//0.3 第二层欢迎界面

int wel2()

{

       system("mode con cols=90 lines=25");//改变窗口大小

       color(14);

       printf("\n\n\n\n\t\t=======================欢迎使用===========================\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t请选择您需要的查询方式:\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t按键1:按学号查找 \t按键2:按姓名查找\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

printf("\t\t==========================================================\n");

       SetPosition(38,15);

       printf("请选择:[_]");

       SetPosition(46,15);

       int n;

       while(1)

       {

              SetPosition(46,15);

              n = getch();

              if(n=='1' || n=='2')

              {

                     printf("%c", n);

                     break;

              }

              else

              {

                     SetPosition(50,16);

                     printf("您的选择有误,请重试...");

              }

       }

       SetPosition(50,17);

       system("pause");

       return n;

 }

 

//0.4 第三层欢迎菜单 --选择需要修改的信息内容

int wel3()

{

       system("mode con cols=90 lines=25");//改变窗口大小

       color(14);

       printf("\n\n\n\n\t\t=======================欢迎使用===========================\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t请选择您需要的修改的信息:\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t按键1:修改学生信息 \t按键2:修改课程信息\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

printf("\t\t==========================================================\n");

       SetPosition(38,15);

       printf("请选择:[_]");

       SetPosition(46,15);

       int n;

       while(1)

       {

              SetPosition(46,15);

              n = getch();

              if(n=='1' || n=='2')

              {

                     printf("%c", n);

                     break;

              }

              else

              {

                     SetPosition(50,16);

                     printf("您的选择有误,请重试...");

              }

       }

       SetPosition(50,16);

       system("pause");

       return n;

 }

 

//0.5 读取文件信息

int read(FILE *fp, struct messages student[100])

{

       int i = 0;

       while(!feof(fp))//没有走到终点就继续读入

       {

              //班级,学号,姓名,性别,年龄

              fscanf(fp, "%s", student[i].Class);

              fscanf(fp, "%s", student[i].StudentNum);

              fscanf(fp, "%s", student[i].Sname);

              fscanf(fp, "%s", student[i].Gender);

              fscanf(fp, "%d", &student[i].Age);

              //课程编号,课程名称,学分,考试成绩,平时成绩,总成绩

              fscanf(fp, "%s", student[i].Course);

              fscanf(fp, "%s", student[i].Cname);

              fscanf(fp, "%d", &student[i].Point);

              fscanf(fp, "%d", &student[i].Fgrade);

              fscanf(fp, "%d", &student[i].Dgrade);

              fscanf(fp, "%lf", &student[i].Agrade);

              //第二门

              fscanf(fp, "%s", student[i].Course1);

              fscanf(fp, "%s", student[i].Cname1);

              fscanf(fp, "%d", &student[i].Point1);

              fscanf(fp, "%d", &student[i].Fgrade1);

              fscanf(fp, "%d", &student[i].Dgrade1);

              fscanf(fp, "%lf", &student[i].Agrade1);

              //第三门

              fscanf(fp, "%s", student[i].Course2);

              fscanf(fp, "%s", student[i].Cname2);

              fscanf(fp, "%d", &student[i].Point2);

              fscanf(fp, "%d", &student[i].Fgrade2);

              fscanf(fp, "%d", &student[i].Dgrade2);

              fscanf(fp, "%lf", &student[i].Agrade2);

              i++;

       }

       fclose(fp);

       return i;

}

 

//0.6 控制台打印

void Print(int i, struct messages student[100])

{

       printf("班级:%s\n", student[i].Class);

       printf("学号:%s\n", student[i].StudentNum);

       printf("姓名:%s\n", student[i].Sname);

       printf("性别:%s\n", student[i].Gender);

       printf("年龄:%d\n", student[i].Age);

       printf("-------第一门课程的相关信息-------\n");

       printf("课程编号:%s\n", student[i].Course);

       printf("课程名称:%s\n", student[i].Cname);

       printf("学分:%d\n", student[i].Point);

       printf("考试成绩:%d\n", student[i].Fgrade);

       printf("平时成绩:%d\n", student[i].Dgrade);

       printf("总成绩:%0.2lf\n", student[i].Agrade);

       printf("-------第二门课程的相关信息-------\n");

       printf("课程编号:%s\n", student[i].Course1);

       printf("课程名称:%s\n", student[i].Cname1);

       printf("学分:%d\n", student[i].Point1);

       printf("考试成绩:%d\n", student[i].Fgrade1);

       printf("平时成绩:%d\n", student[i].Dgrade1);

       printf("总成绩:%0.2lf\n", student[i].Agrade1);

       printf("-------第三门课程的相关信息-------\n");

       printf("课程编号:%s\n", student[i].Course2);

       printf("课程名称:%s\n", student[i].Cname2);

       printf("学分:%d\n", student[i].Point2);

       printf("考试成绩:%d\n", student[i].Fgrade2);

       printf("平时成绩:%d\n", student[i].Dgrade2);

       printf("总成绩:%0.2lf\n", student[i].Agrade2);

}

 

//0.7 四级菜单-->选择需要更改的科目

int wel4()

{

       system("mode con cols=90 lines=25");//改变窗口大小

       color(14);

       printf("\n\n\n\n\t\t=======================欢迎使用===========================\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t请选择您需要的修改的科目:\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t按键1:科目1\t按键2:科目2\t按键3:科目3\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

printf("\t\t==========================================================\n");

       SetPosition(38,15);

       printf("请选择:[_]");

       SetPosition(46,15);

       int n;

       while(1)

       {

              n = getch();

              if(n=='1' || n=='2' || n=='3')

              {

                     printf("%c", n);

                     break;

              }

              else

                     printf("您的选择有误,请重试...");

       }

       SetPosition(50,16);

       system("pause");

       return n;

 }

 

//0.8 按键相应

void keyDown(char n)

{

              switch(n)

              {

                     case '1':         //数据录入

                     {

                            Getin();

                            break;

                     }

                     case '2':

                     {      //数据修改

                            change();

                            break;

                     }

                     case '3':

                     {      insert();

                            break;

                     }

                     case '4':

                     {      //数据查询

                            looking();

                            break;

                     }

                     case '5':

                     {      //数据删除

                            deleting();

                            break;

                     }

                     case '6':

                     {      //平均成绩计算

                            average();

                            break;

                     }

                     case '7':

                     {      //列出不及格学生的清单

                            list_under();

                            break;

                     }

       }

 }

 

//1、数据的录入//over

void Getin()

{

       system("cls");

       FILE *fp = fopen("score.txt", "a+");

       if(fp == NULL)

       {

              printf("打开文件失败,请重试!\n按任意键退出\n");

              getch();

              fclose(fp);

              exit(0);

       }

       int count = 0;

       printf("请输入您要录入数据的人数:");

       scanf("%d", &count);

       struct messages student[100];

       int i = 0;

       for(i=0; i<count; i++)//录入信息提示

       {

              printf("请录入第%d个学生的信息:\n", i+1);

              printf("班级:");

              scanf("%s", &student[i].Class);

              printf("学号:");

              scanf("%s", &student[i].StudentNum);

              printf("姓名:");

              scanf("%s", &student[i].Sname);

              printf("性别:");

              scanf("%s", &student[i].Gender);

              printf("年龄:");

              scanf("%d", &student[i].Age);

              printf("-------第一门课程的相关信息-------\n");

              printf("课程编号:");

              scanf("%s", &student[i].Course);

              printf("课程名称:");

              scanf("%s", &student[i].Cname);

              printf("学分:");

              scanf("%d", &student[i].Point);

              printf("考试成绩:");

              scanf("%d", &student[i].Fgrade);

              printf("平时成绩:");

              scanf("%d", &student[i].Dgrade);

              student[i].Agrade = student[i].Fgrade*0.7 + student[i].Dgrade*0.3;//综合成绩

              printf("-------第二门课程的相关信息-------\n");

              printf("课程编号:");

              scanf("%s", &student[i].Course1);

              printf("课程名称:");

              scanf("%s", &student[i].Cname1);

              printf("学分:");

              scanf("%d", &student[i].Point1);

              printf("考试成绩:");

              scanf("%d", &student[i].Fgrade1);

              printf("平时成绩:");

              scanf("%d", &student[i].Dgrade1);

              student[i].Agrade1 = student[i].Fgrade1 * 0.7 + student[i].Dgrade1 * 0.3;//综合成绩

              printf("-------第三门课程的相关信息-------\n");

              printf("课程编号:");

              scanf("%s", &student[i].Course2);

              printf("课程名称:");

              scanf("%s", &student[i].Cname2);

              printf("学分:");

              scanf("%d", &student[i].Point2);

              printf("考试成绩:");

              scanf("%d", &student[i].Fgrade2);

              printf("平时成绩:");

              scanf("%d", &student[i].Dgrade2);

              student[i].Agrade2 = student[i].Fgrade2 * 0.7 + student[i].Dgrade2 * 0.3;//综合成绩

             

              //班级,学号,姓名,性别, 年龄

              fprintf(fp, "%s %s %s %s %d", student[i].Class, student[i].StudentNum, student[i].Sname, student[i].Gender, student[i].Age);

              //课程编号,课程名称,学分

              fprintf(fp, " %s %s %d ",  student[i].Course, student[i].Cname, student[i].Point);

              //考试成绩,平时成绩,总成绩

              fprintf(fp, "%d %d %0.2lf ", student[i].Fgrade, student[i].Dgrade, student[i].Agrade);

               

              fprintf(fp, " %s %s %d ",  student[i].Course1, student[i].Cname1, student[i].Point1);

              fprintf(fp, "%d %d %0.2lf ", student[i].Fgrade1, student[i].Dgrade1, student[i].Agrade1);

             

              fprintf(fp, " %s %s %d ",  student[i].Course2, student[i].Cname2, student[i].Point2);

              fprintf(fp, "%d %d %0.2lf\n", student[i].Fgrade2, student[i].Dgrade2, student[i].Agrade2);

       }

              fclose(fp);

              printf("添加学生成功,");

              system("pause");

}

 

//2.数据的修改//over

void change()

{

       FILE *fp = fopen("score.txt", "r");

       if(fp == NULL)

       {

              printf("文件打开失败,请重试...\n");

              system("pause");

              fclose(fp);

              exit(0);

       }

       //读入

       struct messages student[100];

       int i = read(fp, student);//i是学生人数

       fclose(fp);

       if(i==0)

       {

              printf("该文本中已无学生信息\n");

              system("pause");

              return;

       }

       int angle = looking();//需要修改信息处的角标

       int n = wel3() - 48;

       system("cls");

       switch(n)

       {

              case 1://修改学生信息

              {

                     printf("请重新录入该学生的信息:\n");

                     printf("班级:");

                     scanf("%s", &student[angle].Class);

                     printf("学号:");

                     scanf("%s", &student[angle].StudentNum);

                     printf("姓名:");

                     scanf("%s", &student[angle].Sname);

                     printf("性别:");

                     scanf("%s", &student[angle].Gender);

                     printf("年龄:");

                     scanf("%d", &student[angle].Age);

                     break;

              }

              case 2://修改课程信息

              {

                     int n = wel4() - 48;

                     system("cls");

                     switch(n)

                     {

                            case 1:

                            {

                                   printf("-------第一门课程的相关信息-------\n");

                                   printf("课程编号:");

                                   scanf("%s", &student[angle].Course);

                                   printf("课程名称:");

                                   scanf("%s", &student[angle].Cname);

                                   printf("学分:");

                                   scanf("%d", &student[angle].Point);

                                   printf("考试成绩:");

                                   scanf("%d", &student[angle].Fgrade);

                                   printf("平时成绩:");

                                   scanf("%d", &student[angle].Dgrade);

                                   student[angle].Agrade = student[angle].Fgrade*0.7 + student[angle].Dgrade*0.3;//综合成绩

                                   break;

                            }

                            case 2:

                            {

                                   printf("-------第二门课程的相关信息-------\n");

                                   printf("课程编号:");

                                   scanf("%s", &student[angle].Course1);

                                   printf("课程名称:");

                                   scanf("%s", &student[angle].Cname1);

                                   printf("学分:");

                                   scanf("%d", &student[angle].Point1);

                                   printf("考试成绩:");

                                   scanf("%d", &student[angle].Fgrade1);

                                   printf("平时成绩:");

                                   scanf("%d", &student[angle].Dgrade1);

                                   student[angle].Agrade1 = student[angle].Fgrade1 * 0.7 + student[angle].Dgrade2 * 0.3;//综合成绩

                                   break;

                            }

                            case 3:

                            {

                                   printf("-------第三门课程的相关信息-------\n");

                                   printf("课程编号:");

                                   scanf("%s", &student[angle].Course2);

                                   printf("课程名称:");

                                   scanf("%s", &student[angle].Cname2);

                                   printf("学分:");

                                   scanf("%d", &student[angle].Point2);

                                   printf("考试成绩:");

                                   scanf("%d", &student[angle].Fgrade2);

                                   printf("平时成绩:");

                                   scanf("%d", &student[angle].Dgrade2);

                                   student[angle].Agrade2 = student[angle].Fgrade2 * 0.7 + student[angle].Dgrade2 * 0.3;//综合成绩

                                   break;

                            }

                     }

                     break;

              }

       }

      

       fp = fopen("score.txt", "w");

       if(fp == NULL)

       {

              printf("文件打开失败,请重试...\n");

              system("pause");

              fclose(fp);

              exit(0);

       }

       int j = 0;

       for(j=0; j<i-1; j++)

       {

              //班级,学号,姓名,性别, 年龄

              fprintf(fp, "%s %s %s %s %d", student[j].Class, student[j].StudentNum, student[j].Sname, student[j].Gender, student[j].Age);

              //课程编号,课程名称,学分

              fprintf(fp, " %s %s %d ",  student[j].Course, student[j].Cname, student[j].Point);

              //考试成绩,平时成绩,总成绩

              fprintf(fp, "%d %d %0.2lf ", student[j].Fgrade, student[j].Dgrade, student[j].Agrade);

             

              //课程编号,课程名称,学分

              fprintf(fp, " %s %s %d ",  student[j].Course1, student[j].Cname1, student[j].Point1);

              //考试成绩,平时成绩,总成绩

              fprintf(fp, "%d %d %0.2lf ", student[j].Fgrade1, student[j].Dgrade1, student[j].Agrade1);

             

              //课程编号,课程名称,学分

              fprintf(fp, " %s %s %d ",  student[j].Course2, student[j].Cname2, student[j].Point2);

              //考试成绩,平时成绩,总成绩

              fprintf(fp, "%d %d %0.2lf\n", student[j].Fgrade2, student[j].Dgrade2, student[j].Agrade2);

       }

       fclose(fp);

       printf("该学生的信息已更改成功\n");

       system("pause");

}

 

//3.数据的插入//over

void insert()

{

       struct messages student[100];

       struct messages Afterstu[101];

       FILE *fp = fopen("score.txt", "r");

       if(fp == NULL)

       {

              printf("文件打开失败,请重试...\n");

              system("pause");

              fclose(fp);

              exit(0);

       }

       int i = read(fp, student);//索引上限

       fclose(fp);

      

       if(i==0)

       {

              printf("该文本中已无学生信息\n");

              system("pause");

              return;

        }//特殊情况

       else

              printf("现在文本中有%d名学生的信息,您想要将该学生的信息放在第几位?\n", i-1);

             

       int angle = 0;//记录插入文本的角标

       scanf("%d", &angle);

       angle--;//角标=位置-1

      

       //将处理后的数据存下来

       int j = 0;

       int k = 0;

       for(j=0; k<i; j++)

       {

              if(k==angle)

                     j++;

              Afterstu[j] = student[k];

              k++;

       }

       //录入插入学生的信息

 

       printf("请录入该学生的信息:\n");

       printf("班级:");

       scanf("%s", &Afterstu[angle].Class);

       printf("学号:");

       scanf("%s", &Afterstu[angle].StudentNum);

       printf("姓名:");

       scanf("%s", &Afterstu[angle].Sname);

       printf("性别:");

       scanf("%s", &Afterstu[angle].Gender);

       printf("年龄:");

       scanf("%d", &Afterstu[angle].Age);

       printf("-------第一门课程的相关信息-------\n");

       printf("课程编号:");

       scanf("%s", &Afterstu[angle].Course);

       printf("课程名称:");

       scanf("%s", &Afterstu[angle].Cname);

       printf("学分:");

       scanf("%d", &Afterstu[angle].Point);

       printf("考试成绩:");

       scanf("%d", &Afterstu[angle].Fgrade);

       printf("平时成绩:");

       scanf("%d", &Afterstu[angle].Dgrade);

       Afterstu[angle].Agrade = Afterstu[angle].Fgrade * 0.7 + Afterstu[angle].Dgrade * 0.3;//综合成绩

       printf("-------第二门课程的相关信息-------\n");

       printf("课程编号:");

       scanf("%s", &Afterstu[angle].Course1);

       printf("课程名称:");

       scanf("%s", &Afterstu[angle].Cname1);

       printf("学分:");

       scanf("%d", &Afterstu[angle].Point1);

       printf("考试成绩:");

       scanf("%d", &Afterstu[angle].Fgrade1);

       printf("平时成绩:");

       scanf("%d", &Afterstu[angle].Dgrade1);

       Afterstu[angle].Agrade1 = Afterstu[angle].Fgrade1 * 0.7 + Afterstu[angle].Dgrade1 * 0.3;//综合成绩

       printf("-------第三门课程的相关信息-------\n");

       printf("课程编号:");

       scanf("%s", &Afterstu[angle].Course2);

       printf("课程名称:");

       scanf("%s", &Afterstu[angle].Cname2);

       printf("学分:");

       scanf("%d", &Afterstu[angle].Point2);

       printf("考试成绩:");

       scanf("%d", &Afterstu[angle].Fgrade2);

       printf("平时成绩:");

       scanf("%d", &Afterstu[angle].Dgrade2);

       Afterstu[angle].Agrade2 = Afterstu[angle].Fgrade2 * 0.7 + Afterstu[angle].Dgrade2 * 0.3;//综合成绩

      

       //重新录入至文件中

       fp = fopen("score.txt", "w");

       for(j=0; j<i; j++)

       {

              //班级,学号,姓名,性别

              fprintf(fp, "%s %s %s %s ", Afterstu[j].Class, Afterstu[j].StudentNum, Afterstu[j].Sname, Afterstu[j].Gender);

              //年龄,课程编号,课程名称,学分

              fprintf(fp, "%d %s %s %d ", Afterstu[j].Age, Afterstu[j].Course, Afterstu[j].Cname, Afterstu[j].Point);

              //考试成绩,平时成绩,总成绩

              fprintf(fp, "%d %d %0.2lf", Afterstu[j].Fgrade, Afterstu[j].Dgrade, Afterstu[j].Agrade);

              fprintf(fp, " %s %s %d ",  Afterstu[j].Course1, Afterstu[j].Cname1, Afterstu[j].Point1);

              fprintf(fp, "%d %d %0.2lf ", Afterstu[j].Fgrade1, Afterstu[j].Dgrade1, Afterstu[j].Agrade1);

              fprintf(fp, " %s %s %d ",  Afterstu[j].Course2, Afterstu[j].Cname2, Afterstu[j].Point2);

              fprintf(fp, "%d %d %0.2lf\n", Afterstu[j].Fgrade2, Afterstu[j].Dgrade2, Afterstu[j].Agrade2);

        }

       fclose(fp);

       printf("该学生的信息已插入\n");

       system("pause");

}

 

//4、数据的查询//over

int looking()

{

       FILE *fp = fopen("score.txt", "r");

       if(fp == NULL)

       {

              printf("文件打开失败,请重试...\n");

              system("pause");

              fclose(fp);

              exit(0);

       }

       //读入

       struct messages student[100];

       int i = read(fp, student);

       if(i==0)

       {

              printf("该文本中已无学生信息\n");

              system("pause");

              return;

       }

       int n = wel2() - 48;

       system("cls");

       int angle = 0;//记录寻找文本的角标

       int flag = 0;//记录是否找到

       switch(n)

       {

              case 1:

              {

                     printf("请输入您要查询信息的学生的学号:\n");

                     char StudentNum[10];

                     scanf("%s", &StudentNum);

                     int j = 0;

                     for(j=0; j<i; j++)

                     {

                            if(strcmp(StudentNum, student[j].StudentNum) == 0)

                            {

                                   flag = 1;

                                   angle = j;//角标

                            }

                     }

                     break;

              }

              case 2:

              {

                     printf("请输入您要查询的学生的姓名:\n");

                     char studentName[10];

                     scanf("%s", &studentName);

                     int j = 0;

                     for(j=0; j<i; j++)

                     {

                            if(strcmp(studentName, student[j].Sname) == 0)

                            {

                                   flag = 1;

                                   angle = j;//角标

                            }

                     }

                     break;

              }

       }

       if(flag == 0)

       {

              printf("没有找到该学生的信息\n");

              system("pause");

              return;

       }//两个特殊情况

       else

       {

              printf("您查询的学生相关信息如下:\n");

              system("mode con cols=90 lines=30");//改变窗口大小

              Print(angle, student);

        }

       fclose(fp);

       SetPosition(60, 27);

       system("pause");

       return angle;

}

 

//5.数据的删除//over

void deleting()

{

       struct messages student[100];

       struct messages Afterstu[99];

       char StudentNum[10];

       FILE *fp = fopen("score.txt", "r");

       if(fp == NULL)

       {

              printf("文件打开失败,请重试...\n");

              system("pause");

              fclose(fp);

              exit(0);

       }

       int i = read(fp, student);//索引上限

       if(i == 0)

       {

              printf("该文本中已无学生信息\n");

              system("pause");

              return;

       }

       int angle = 0;//记录删除文本的角标

       int flag = 0;//记录是否找到

       int n = wel2() - 48;

       system("cls");

       switch(n)

       {

              case 1:

              {

                     printf("请输入您要删除信息的学生的学号:\n");

                     char StudentNum[10];

                     scanf("%s", &StudentNum);

                     int j = 0;

                     for(j=0; j<i; j++)

                     {

                            if(strcmp(StudentNum, student[j].StudentNum) == 0)

                            {

                                   flag = 1;

                                   angle = j;//角标

                            }

                     }

                     break;

              }

              case 2:

              {

                     printf("请输入您要删除的学生的姓名:\n");

                     char studentName[10];

                     scanf("%s", &studentName);

                     int j = 0;

                     for(j=0; j<i; j++)

                     {

                            if(strcmp(studentName, student[j].Sname) == 0)

                            {

                                   flag = 1;

                                   angle = j;//角标

                            }

                     }

                     break;

              }

   }

       if(flag == 0)

       {

              printf("没有找到该学生的信息\n");

              system("pause");

              return;

       }//特殊情况

      

       //将处理后的数据存下来

       int j = 0;

       int k = 0;

       for(j=0; k<i; j++)

       {

              if(k==angle)

                     k++;

              Afterstu[j] = student[k];

              k++;

       }

       //重新录入至文件中

       fp = fopen("score.txt", "w");

       for(j=0; j<i-2; j++)

       {

              //综合成绩

              Afterstu[j].Agrade = Afterstu[j].Fgrade * 0.7 + Afterstu[j].Dgrade * 0.3;

              Afterstu[j].Agrade1 = Afterstu[j].Fgrade1 * 0.7 + Afterstu[j].Dgrade1 * 0.3;

              Afterstu[j].Agrade2 = Afterstu[j].Fgrade2 * 0.7 + Afterstu[j].Dgrade2 * 0.3;

              //班级,学号,姓名,性别

              fprintf(fp, "%s %s %s %s ", Afterstu[j].Class, Afterstu[j].StudentNum, Afterstu[j].Sname, Afterstu[j].Gender);

              //年龄,课程编号,课程名称,学分

              fprintf(fp, "%d %s %s %d ", Afterstu[j].Age, Afterstu[j].Course, Afterstu[j].Cname, Afterstu[j].Point);

              //考试成绩,平时成绩,总成绩

              fprintf(fp, "%d %d %0.2lf ", Afterstu[j].Fgrade, Afterstu[j].Dgrade, Afterstu[j].Agrade);

 

              fprintf(fp, "%s %s %d ", Afterstu[j].Course1, Afterstu[j].Cname1, Afterstu[j].Point1);

              fprintf(fp, "%d %d %0.2lf ", Afterstu[j].Fgrade1, Afterstu[j].Dgrade1, Afterstu[j].Agrade1);

             

              fprintf(fp, "%s %s %d ", Afterstu[j].Course2, Afterstu[j].Cname2, Afterstu[j].Point2);

              fprintf(fp, "%d %d %0.2lf\n", Afterstu[j].Fgrade2, Afterstu[j].Dgrade2, Afterstu[j].Agrade2);

        }

       fclose(fp);

       printf("该学生的信息已删除\n");

       system("pause");

}

 

//6.平均成绩的计算//over

void average()

{

       FILE *fp = fopen("score.txt", "r");

       if(fp == NULL)

       {

              printf("文件打开失败,请重试...\n");

              system("pause");

              fclose(fp);

              exit(0);

       }

       //读入

       struct messages student[100];

       double scores[100] = {0};//用于记录每一位学生的平均成绩;

       int num[100] = {-1};//用于从平均成绩从高到低地记录学生信息;

       int i = read(fp, student);//i是学生人数

       fclose(fp);

       if(i==0)

       {

              printf("该文本中已无学生信息\n");

              system("pause");

              return;

       }

       int j = 0;

       for(j=0; j<i-1; j++)

       {

              int all = student[j].Point + student[j].Point1 + student[j].Point2;

              double temp = student[j].Point * student[j].Agrade / all;

              double temp1 = student[j].Point1 * student[j].Agrade1 / all;

              double temp2 = student[j].Point2 * student[j].Agrade2 / all;

              scores[j] = temp + temp1 + temp2;

        }

        int flag[100];//flag用于标记这个位置的数字是否已经被选出

        int k = 0, r = 0;

        for(k=0; k<i-1; k++)

        {

            double max = -1;

             for(j=0; j<i-1; j++)

              {

                    if(max<scores[j] && !flag[j])

                    {

                           max = scores[j];//最大值更改;

                            r = j;//角标记录;

                      }

               }//每次循环结束之后会选出一个最大值;

               num[k] = r;

               flag[r] = 1;//标记已访问;

        }

        printf("按照平均成绩降序输出如下:\n");

        for(j=0; j<i-1; j++)

        {

             printf("------第%d名------\n", j+1);

             printf("班级:%s\n", student[num[j]].Class);

              printf("学号:%s\n", student[num[j]].StudentNum);

              printf("姓名:%s\n", student[num[j]].Sname);

              printf("性别:%s\n", student[num[j]].Gender);

              printf("年龄:%d\n", student[num[j]].Age);

             printf("平均成绩:%lf\n", scores[num[j]]);

             //system("pause");

        }

        system("pause");

}

 

//7.列出不及格学生清单//over

void list_under()

{

       FILE *fp = fopen("score.txt", "r");

       if(fp == NULL)

       {

              printf("文件打开失败,请重试...\n");

              system("pause");

              fclose(fp);

              exit(0);

       }

       struct messages student[100];

       int i = read(fp, student);//i是学生人数 //读入

       int j = 0, n = 0;

       for(j=0; j<i-1; j++)

       {

              if(student[j].Agrade<60 || student[j].Agrade1<60 || student[j].Agrade2<60)

              {

                     n++;

                     printf("---第%d位成绩不合格学生的相关信息---\n", n);

                     printf("学号:%s\n", student[j].StudentNum);

                     printf("姓名:%s\n", student[j].Sname);

                     if(student[j].Agrade<60)

                     {

                            printf("课程编号:%s\n", student[j].Course);

                            printf("课程名称:%s\n", student[j].Cname);

                            printf("总成绩:%0.2lf\n", student[j].Agrade);

                     }

                     if(student[j].Agrade1<60)

                     {

                            printf("课程编号:%s\n", student[j].Course1);

                            printf("课程名称:%s\n", student[j].Cname1);

                            printf("总成绩:%0.2lf\n", student[j].Agrade1);

                     }

                     if(student[j].Agrade2<60)

                     {

                            printf("课程编号:%s\n", student[j].Course2);

                            printf("课程名称:%s\n", student[j].Cname2);

                            printf("总成绩:%0.2lf\n", student[j].Agrade2);

                     }

                     printf("\n");

              }

       }

       if(n==0)

              printf("所有学生成绩均合格!\n");

       system("pause");

}

 

//2系列函数-->优化

char key_wel()

{

       int c;

       system("mode con cols=90 lines=25");//改变窗口大小

       color(14);

       printf("\n\n\n\n\t\t=======================欢迎使用===========================\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t请选择操作:\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t      按键x:重置密码\t按键i:输入密码\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");;

       printf("\t\t||\t\t\t\t\t\t\t||\n");

       printf("\t\t||\t\t      按键[ESC]:退出\t\t\t||\n");

       printf("\t\t||\t\t\t\t\t\t\t||\n");

printf("\t\t==========================================================\n");

       while(1)

       {

              SetPosition(38,17);

              printf("请选择:[_]");

              SetPosition(46,17);

              c = getch();

              if(c=='x' || c=='i')

              {

                     printf("%c",c);

                     break;

              }

              else if(c == 27)

              {

                     SetPosition(38,18);

                     printf("确认退出?(Y/N)[_]");

                     SetPosition(53,18);

                     while(1)

                     {

                            char choice = getch();

                            if(choice == 'Y' || choice == 'y' || choice == 'n' || choice == 'N')

                            {

                                   printf("%c", choice);

                                   if(choice == 'Y' || choice == 'y')

                                   {

                                          SetPosition(38,20);

                                          printf("欢迎您的下次使用,再见!");

                                          sleep(1);

                                          exit(0);

                                   }

                                   else

                                          break;

                            }

                            else

                            {

                                   printf("\n您的输入有误,请重试...");

                                   SetPosition(53,18);

                             }

                     }

              }

              else

              {

                     SetPosition(50,22);

                     printf("您的选择有误,请重试...");

                     SetPosition(46,17);

              }

              SetPosition(38,18);

              printf("                   ");

        }

       return c;

}

 

void keys()

{

        char keys[7];//多一位放结束标志

        char in_keys[7];

        memset(in_keys, 0, sizeof(in_keys));

        memset(keys, 0, sizeof(keys)); //初始化

        int flag = 1;//表示输入的密码是否正确

        for(;flag ;)

        {

             char c = key_wel();

             switch(c)

              {

                     case 'x':

                     {

                            SetPosition(40,19);

                            printf("您是否确认重置密码?(Y/N):[_]");

                            SetPosition(66,19);

                            while(1)

                            {

                                   char c1 = getch();

                                   if(c1=='y' || c1=='Y' || c1=='n' || c1=='N')

                                   {

                                          printf("%c", c1);

                                          SetPosition(40,22);

                                          printf("                                ");

                                          if(c1=='y' || c1=='Y')

                                          {

                                                 SetPosition(40,20);

                                                 printf("请输入新的6位密码: ");

                                                 scanf("%s", keys);

                                                 flag = 0;

                                          }

                                          break;

                                   }

                                   else

                                   {

                                          SetPosition(40,22);

                                          printf("您的选择有误,请重新输入...");

                                          SetPosition(66,19);

                                   }

                            }

                            FILE *fp = fopen("secret.txt", "w+");

                            if(fp == NULL)

                            {

                                   printf("打开文件失败,请设置密码后再尝试!\n按任意键退出\n");

                                   getch();

                                   fclose(fp);

                                   exit(0);

                            }

                            fprintf(fp, "%s\n", keys);

                            fclose(fp);

                     }

                     case 'i':

                     {

                            c = 'i';

                            char choice;

                            SetPosition(40,22);

                            printf("                                   ");

                            FILE *fp = fopen("secret.txt", "r");

                            if(fp == NULL)

                            {

                                   SetPosition(40,22);

                                   printf("未设置密码,请重试!");

                                   SetPosition(40,23);

                                   system("pause");

                                   fclose(fp);

                                   exit(0);

                            }

                            fscanf(fp, "%s\n", keys);

                            fclose(fp);

                            do

                            {

                                   SetPosition(40,21);

                                   printf("请输入您的密码([ESC]返回上一层): ");

                                   int i = 0;

                                   for(i=0; i<6; i++)

                                   {

                                          in_keys[i] = getch();

                                          char ch = in_keys[i];

                                          if(ch==27)

                                          {                                 

                                                 SetPosition(40,23);

                                                 printf("您确认返回上一层?(Y/N)[_]");

                                                 SetPosition(63,23);

                                                 while(1)

                                                 {

                                                        choice = getch();

                                                        if(choice == 'Y' || choice == 'y' || choice == 'n' || choice == 'N')

                                                        {

                                                               printf("%c", choice);

                                                               if(choice == 'Y' || choice == 'y')

                                                                      c = 'x';

                                                               i = 6;

                                                               break;

                                                        }

                                                        else

                                                               printf("您的输入有误,请重试...");

                                                 }

                                          }

                                          else

                                                 printf("*");

                                          if(i == 5)

                                                 getch();

                                   }

                                   if(c == 'i')

                                   {

                                          if(strcmp(keys, in_keys) == 0)

                                          {

                                                 SetPosition(40,24);

                                                 printf("密码正确,请稍后...");

                                                 flag = 0;

                                                 sleep(1);

                                                 break;

                                          }

                                          SetPosition(40,22);

                                          if(choice == 'n')

                                          {

                                                 SetPosition(40,23);

                                                 printf("                    ");

                                                 choice = '\0';

                                          }

                                          else

                                                 printf("密码错误,请重试...");

                                          SetPosition(65,21);

                                          printf("               ");

                                   }

                                   else

                                          break;

                            }while(1);

                            break;

                     }

              }

     }

}

标签:fp,Afterstu,angle,管理系统,int,C语言,student,printf,成绩
From: https://www.cnblogs.com/yuooo/p/17366956.html

相关文章

  • C语言实现迷宫游戏
    include<stdio.h>#include<windows.h>#include<conio.h>#include<time.h>#include<math.h> //地图边长L,包括迷宫主体20,外侧的包围的墙体2,最外侧包围路径2(之后会解释)//可根据需要修改,有上限#defineL24 #defineWALL 0//墙#defineROUTE1//路径#definePLAYER......
  • c语言实现链表的基本操作——初始化,求长度,添加节点,遍历输出
    #include<stdio.h>#include<stdlib.h>//创建结构体并命名typedefstructNode //typedef用于对struct的重命名{ inti; structNode*next;}LNode,*LinkList; //定义一个结构体指针//链表初始化boolInistList(LinkListL){ L=(LNode*)malloc(sizeof(LNo......
  • c语言基础
    环境设置c程序的源文件通常使用扩展名.cc程序需要编译成机器语言,这样cpu可以按给定指令执行程序。最常用的编译器是gcc(mac上xcode就可以)程序结构#include预处理器指令,类似于import,主要用于告诉编译器,我们要引入什么。.h结尾的是头文件,头文件中一般是定义的结构体和变量#include......
  • java基于springboot的毕业生信息招聘平台、高校学生招聘管理系统、招聘管理系统,附源码
    1、项目介绍毕业生信息招聘平台的功能如下:管理管理员;首页、个人中心、企业管理、空中宣讲会管理、招聘岗位管理、毕业生管理、个人简历管理、求职信息管理、信息咨询管理、岗位应聘管理、线上面试管理、面试回复管理、试卷管理、试题管理、管理员管理、论坛管理、系统管理、考试......
  • java基于ssm的超市管理系统、超市销售管理系统,附源码+数据库+文档,适合课设设计、毕业
    1、项目介绍java基于ssm的超市管理系统、超市销售管理系统。本系统的设计是两种用户,一种是普通用户,一种是管理员用户。权限都不一样。主要功能有:添加商品、库存查询、订单管理、商品删除管理、退货管理、销售统计、供应商管理、用户管理、角色管理。项目获取,看这里2、技术框......
  • java基于ssm的房屋租赁管理系统、房屋出租管理系统、租房管理系统,附源码+数据库,免费安
    1、项目介绍java基于ssm的房屋租赁管理系统、房屋出租管理系统、租房管理系统,​系统分为前台用户界面和后台系统管理。项目获取,看这里1.1前台用户界面用户注册、用户登录、用户中心、浏览房源、房源搜索查看房源明细、发布房源、提交合同、新闻公告、留言交流1.2后台系统......
  • java基于springboot的学生毕业离校系统管理系统、高校学生离校管理系统,附源码+数据库+
    1、项目介绍学生毕业离校系统的开发过程中,采用B/S架构,主要使用Java技术进行开发,结合最新流行的springboot框架。中间件服务器是Tomcat服务器,使用Mysql数据库。该学生毕业离校系统包括管理员、学生和教师。其主要功能包括管理员:首页、个人中心、学生管理、教师管理、离校信息管......
  • C语言打印上下金字塔的按位取反运算符的精妙用法
    在打印上下金字塔的通常语句用法应该都是像下面这种#include<stdio.h>intmain(){  intn; do{   for(inti=1;i<n;i++){     for(inta=0;a<n-i;a++){       printf("");     }    for(intj=0;j<2*i-1;j++){     ......
  • 智能家居管理系统
    源码及演示地址:演示地址:https://www.wchime.xyz:8080/#/后端代码:https://gitee.com/mom925/device-web-api前端代码:https://gitee.com/mom925/device-web-vue模拟中控代码:https://gitee.com/mom925/center-control演示登录账号:......
  • 栈的顺序存储 C语言
    #include<iostream>#include<stdio.h>#defineMAXSIZE50typedefstruct{intdata[MAXSIZE];inttop;}SqStack;//初始化栈voidInitStack(SqStack&s){s.top=-1;}//判断栈空boolStackEmpty(SqStack&s){if(s.top==-1)......