程式設計作業——系統管理

程式碼曉菜雞發表於2020-11-27

程式實驗的大作業,DDL前完工的一版

   //專案名稱:年級綜測管理系統          //
  //建立人:程式碼小菜雞                 //
 //學號:×××××××××××××               //
//建立時間:2020.11.8 上午11:09   //

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <malloc.h>
#include <string.h>
#include <windows.h>
//#include "info.h"
//#include <algorithm.h>


//-------------------------------------------------------------以 下 為 各 種 定 義 和 聲 明---------------------------------------------------------------//
#define Status void
#define xuehao long long int   //-922 3372 0368 5477 5808 ~ 922 3372 0368 5477 5807 (922*10^16)
#define deyuchengji double     //.2f
#define laodongchengji double  //.1f
#define tiyuchengji double     //.3f
#define zhiyuchengji double    //.8f
#define zuizhongchengji double //.8f

//用於計算智育和體育成績
#define Calculus_A1 int
//微積分A (Ⅰ)
#define Introduction_to_Computing_Discipline int
//計算學科導論
#define Experiments_for_Foundation_of_Programming int
//程式設計基礎實驗
#define Foundation_of_Programming int
//程式設計基礎
#define Military_Theory int
//軍事理論
#define College_English_Listening_and_Speaking1 int
//大學英語聽說1
#define College_English_Reading_and_Writing1 int
//大學英語讀寫1
#define Morality_and_Fundamentals_of_Law int
//思想道德修養與法律基礎
#define Physical_Education1 double
//體育1
#define Computing_Essentials int
//計算機技術基礎(雙語)
#define Linear_Algebra int
//線性代數
#define College_English_Reading_and_Writing2 int
//大學英語讀寫2
#define College_Physics_A1 int
//大學物理A(I)
#define College_English_Listening_and_Speaking2 int
//大學英語聽說2
#define Experiment_of_Advanced_Programming int
//高階語言程式設計實驗
#define Calculus_A2 int
//微積分A (Ⅱ)
#define Advanced_Programming int
//高階語言程式設計
#define Etiquette_for_College_Students int
//大學生禮儀
#define Frontiers_of_Information_Science int
//資訊科學前沿
#define Physical_Education2 int
//體育2
#define Probability_Theory_and_Mathematical_Statistics int
//概率與數理統計

//-------------------21 門 單 科 的 定 義 與 聲 明------------------------//

#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define MAXN 507      //最大學生人數,可修改
#define INCREAMENT 60 //轉入學生學生增量上限
#define bool int
#define Elemtype int

//-------------------所 有 的 函 數 操 作 的 函 數 名-------------------------//

int manage_password();
//輸入管理系統賬號密碼,以管理員身份進入軟體(雙系統)
//flag顯示其他呼叫此函式的函式
Status CHANGE_manage_password();
//實現對登入管理系統密碼的修改
Status calculate_zhiyu(int Elem);
//計算個人智育成績
Status calculate_tiyu(int Elem);
//計算個人德育成績
Status manage_order();
//switch函式模組,承接管理平臺的輸入命令
Status student_order();
//switch函式模組,承接學生平臺的輸入命令
Status manage_help();
//輸出管理系統使用說明
Status student_help();
//輸出學生查詢系統使用說明
int allocate();
//以學號為參考依據,先對讀取的“各科成績”、“德育和勞動成績”按照學號大小降序排列,
//而後將兩部分資料進行合併並輸出結果
int judge_60(Elemtype n);
//判斷各科成績是否超過60,即判別掛科與否的if函式
Status allocte_all_password();
//利用每位同學的身份證匹配每名同學的密碼,身份證號後六位
int read_deyu_and_laodong();
//從txt中讀取德育和勞動成績
int read_alldata();
//從txt中讀取各科成績
Status addScore();
//計算德育、智育、體育、勞動四項之和
Status search_analysis();
//查詢分析函式
Status sorting();
//對總成績進行排序函式————————氣泡排序
void shellSort(Elemtype *a, Elemtype len);
//對總成績進行排序函式————————希爾排序
Status submenu();
//子選單模組,用於與sorting()函式中的switch選項
Status print_perpass();
//計算掛科率以及掛科同學資訊,內含登入系統
Status addstu();
//新增同學的資訊
Status delstu();
//刪減同學的資訊
Status choose_system();
//初始時選擇系統選單模組
Status manage_menu();
//管理選單模組
Status student_menu();
//學生選單模組
Status student_read_deyu_and_laodong();
//學生平臺的讀取德育和勞動成績,用於提前處理資料,譬如得到總人數
Status student_read_alldata();
//學生平臺的讀取各科成績,用於提前處理資料
Status student_allocate();
//學生平臺的將兩部分資料進行合併並輸出結果的函式,用於提前處理資料
Status student_addScore();
//學生平臺的求和函式,用於提前處理資料
Status student_account();
//學生平臺的帳號密碼登入系統函式
Status student_all_score();
//學生平臺的查詢個人資訊的輸出函式
int stdio_messagebox(Elemtype ret, Elemtype choice);
//生成選擇系統時的按鈕視窗



int STUnum; //計數

int i;

int ret;//引用messagebox()函式的變數宣告

int CHOICE;//記錄選擇

enum WON
{
    NO,
    YES
}; //whether or not,用於每個模組結果是否輸出

enum passing
{
    Npass, //掛科
    pass   //未掛科
};         //判斷學生是否掛科
clock_t start, finish;


struct student
{
    xuehao student_xuehao;          //學號
    char name[100];                 //姓名
    char id[100];                   //身份證號
    char PW[100];                   //密碼
    deyuchengji student_deyu;       //德育成績
    laodongchengji student_laodong; //勞動成績
    tiyuchengji student_tiyu;       //體育成績
    zhiyuchengji student_zhiyu;     //智育成績
    zuizhongchengji student_score;  //總成績
    bool student_pass               //掛科情況
} student_info[MAXN + INCREAMENT], buddle_info, buf_info[MAXN + INCREAMENT];


typedef struct student stu;


typedef struct LNode
{
    stu data;
    struct LNode *next;
} LinkList;


Status InitList(LinkList *L);
//初始化連結串列
Status ListInsert(LinkList *L, LinkList *p);
//插入新的節點


struct zhiyu_tiyu
{
    Calculus_A1 CA_1;                                                                                //微積分A (Ⅰ)
    Introduction_to_Computing_Discipline ICD;                                                        //計算學科導論
    Experiments_for_Foundation_of_Programming EFP;                                                   //程式設計基礎實驗
    Foundation_of_Programming FP;                                                                    //程式設計基礎
    Military_Theory MT;                                                                              //軍事理論
    College_English_Listening_and_Speaking1 CELS_1;                                                  //大學英語聽說1
    College_English_Reading_and_Writing1 CERW_1;                                                     //大學英語讀寫1
    Morality_and_Fundamentals_of_Law MFL;                                                            //思想道德修養與法律基礎
    Physical_Education1 PE_1;                                                                        //體育1
    Computing_Essentials CE;                                                                         //計算機技術基礎(雙語)
    Linear_Algebra LA;                                                                               //線性代數
    College_English_Reading_and_Writing2 CERW_2;                                                     //大學英語讀寫2
    College_Physics_A1 CPA_1;                                                                        //大學物理A(I)
    College_English_Listening_and_Speaking2 CELS_2;                                                  //大學英語聽說2
    Experiment_of_Advanced_Programming EAP;                                                          //高階語言程式設計實驗
    Calculus_A2 CA_2;                                                                                //微積分A (Ⅱ)
    Advanced_Programming AP;                                                                         //高階語言程式設計
    Etiquette_for_College_Students ECS;                                                              //大學生禮儀
    Frontiers_of_Information_Science FIS;                                                            //資訊科學前沿
    Physical_Education2 PE_2;                                                                        //體育2
    Probability_Theory_and_Mathematical_Statistics PTMS;                                             //概率與數理統計
    double zhiyu_score;                                                                              //智育成績
    double tiyu_score;                                                                               //體育成績
    xuehao student_xuehao;                                                                           //學號
    bool pass_or_not;                                                                                //掛科情況
} student_zhiyu[MAXN + INCREAMENT], student_tiyu[MAXN + INCREAMENT], student_alldata[MAXN + INCREAMENT], buddle_zhiyu_tiyu; 
  //三者代表涵意不盡相同,zhiyu,tiyu是為了便於區分

typedef struct zhiyu_tiyu Score;

char nam[100]; //名字
xuehao XH;     //學號
char id[22];   //身份證號
Score sc;      //成績


//--------------------------------------------------------以 上 為 各 項 定 義 和 聲 明-------------------------------------------------------------------------//

//------------------------------------------------------------以 下 是 選 擇 菜 單-----------------------------------------------------------------------------//

Status choose_system()
{
    printf("\t********************************************************************************\n");
    printf("\t**請選擇:1.管理員身份進入系統(管理)--------------2.學生身份進入系統(查詢)**\n");
    printf("\t********************************************************************************\n");
}

Status manage_menu()
{
    printf("\t\t\t\t\t歡迎使用××屆資訊工程學院學生成績管理選單(綜測管理用)【當前學生資訊%d條】\n", STUnum);
    //printf("\t\t\t\t\t\t【密碼:xxgcxy】\n");
    printf("\n\t\t\t\t0.喚出選單-------------------------------1.使用說明\n");
    puts("");
    printf("\t\t\t\t2.從txt中讀入德育和勞動資料---------------3.從txt中讀入各科目資料(用於計算體育和智育成績)\n");
    puts("");
    printf("\t\t\t\t4.按學號匹配所有資料----------------------5.計算所有學生的總成績\n");
    puts("");
    printf("\t\t\t\t6.按學號查詢資訊--------------------------7.列印所有掛科同學的成績資訊\n");
    puts("");
    printf("\t\t\t\t8.按學號新增學生資訊----------------------9.按學號刪減學生資訊\n");
    puts("");
    printf("\t\t\t\t10.修改管理平臺的登入密碼\n");
    puts("");
    printf("\t\t\t\t11.退出系統\n");
}


Status student_menu()
{
    printf("\t\t\t\t\t歡迎使用××屆資訊工程學院學生成績管理選單(個人查詢用)【當前學生資訊%d條】\n", STUnum);
    puts("");
    printf("\t\t\t\t\t1.使用說明---------------------------2.個人大一各科目成績\n");
    puts("");
    printf("\t\t\t\t\t3.退出個人系統\n");
}


int stdio_messagebox(Elemtype ret, Elemtype choice)
{
    ret = MessageBox(NULL, TEXT("是否想要以管理員身份進入管理系統呢?"), TEXT("CHOOSE THE SYSTEM"), MB_YESNO | MB_ICONQUESTION);
    if (ret == IDYES)
    {
        CHOICE = 1;
    }
    else
    {
        ret = MessageBox(NULL, TEXT("是否想要以學生身份進入查詢系統呢?"), TEXT("CHOOSE THE SYSTEM"), MB_YESNO | MB_ICONQUESTION);
        if (ret == IDYES)
        {
            CHOICE = 2;
        }
        else
        {
            MessageBox(NULL, TEXT("那就再見咯"), TEXT("exit"), MB_OK);
            return 0;
        }
    }
}


//------------------------------------------------------------以 上 是 選 擇 菜 單-----------------------------------------------------------------------------//

//--------------------------------------------------------以 下 是 雙 系 統 通 用 函 數-------------------------------------------------------------------------//

int judge_60(Elemtype n)
{
    if (student_alldata[n].student_xuehao < 60 || student_alldata[n].ICD < 60 ||
        student_alldata[n].CA_1 < 60 || student_alldata[n].MFL < 60 || student_alldata[n].CE < 60 || student_alldata[n].CELS_1 < 60 || student_alldata[n].PE_1 < 60 || student_alldata[n].FP < 60 ||
        student_alldata[n].MT < 60 || student_alldata[n].LA < 60 || student_alldata[n].EFP < 60 || student_alldata[n].CERW_1 < 60 || student_alldata[n].CA_2 < 60 || student_alldata[n].CERW_2 < 60 ||
        student_alldata[n].CELS_2 < 60 || student_alldata[n].ECS < 60 || student_alldata[n].PTMS < 60 || student_alldata[n].AP < 60 || student_alldata[n].PE_2 < 60 || student_alldata[n].EAP < 60 ||
        student_alldata[n].CPA_1 < 60 || student_alldata[n].FIS < 60)
        return 0;
    else
        return 1;
}


Status calculate_zhiyu(int Elem)
{
    //計算智育成績
    //int student_num = 1;
    //for (; student_num <= 507; student_num++)
    {
        //zhiyu_score=(C:C+5*D:D+3*E:E+1.5*F:F+G:G+2*I:I+J:J+3*K:K+L:L+2*N:N+5*P:P+2*Q:Q+R:R+S:S+3*T:T+2*U:U+W:W+4*X:X+Y:Y)/40.5*0.7
        //各科成績乘上權的所有和除以總學分40.5,而後乘上佔比70%,即為智育成績
        student_alldata[Elem].zhiyu_score = (student_alldata[Elem].ICD + 5 * student_alldata[Elem].CA_1 + 3 * student_alldata[Elem].MFL + 1.5 * student_alldata[Elem].CE + student_alldata[Elem].CELS_1 + 2 * student_alldata[Elem].FP + student_alldata[Elem].MT + 3 * student_alldata[Elem].LA + student_alldata[Elem].EFP + 2 * student_alldata[Elem].CERW_1 + 5 * student_alldata[Elem].CA_2 + 2 * student_alldata[Elem].CERW_2 + student_alldata[Elem].CELS_2 + student_alldata[Elem].ECS + 3 * student_alldata[Elem].PTMS + 2 * student_alldata[Elem].AP + student_alldata[Elem].EAP + 4 * student_alldata[Elem].CPA_1 + student_alldata[Elem].FIS) / 40.5 * 0.7;

        student_info[Elem].student_zhiyu = student_alldata[Elem].zhiyu_score; //賦值
    }
}


Status calculate_tiyu(int Elem)
{
    //計算體育成績
    //int student_num = 1;
    //for (; student_num <= 507; student_num++)
    {
        //tiyu_score=(PE_1+PE_2)/2*0.05
        //兩學期的體育成績的平均數乘上佔比5%即為體育成績
        student_alldata[Elem].tiyu_score = (student_alldata[Elem].PE_1 + student_alldata[Elem].PE_2) / 2 * 0.05;

        student_info[Elem].student_tiyu = student_alldata[Elem].tiyu_score; //賦值
    }
}


Status manage_help()
{
    puts("\n");
    printf("××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××\n");
    printf("|                                   這是本程式的簡要功能說明:                                                        |\n");
    printf("|    歡迎使用××屆資訊工程學院學生成績 管理&學生用查詢 選單,");
    printf("本程式是為了實現通過從txt中讀取的各科成績計算出每名同學的 |\n|智育成績以及體育成績,並與錄入好的勞動成績以及德育成績相加求和並最終得出每名同學的最終成績。");
    printf("根據提供選單中的各項命令|\n|,實現對整體資料的刪除、查詢以及排序                                                                                |\n");
    printf("××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××\n");
}


Status allocte_all_password()
{
    //匹配每名同學的密碼
    int k = 0;
    struct student temp[STUnum];
    for (k; k < STUnum; k++)
    {
        strncpy(student_info[k].PW, student_info[k].id + strlen(student_info[k].id) - 6, 6);
    }
}

//-------------------------------------------------------以 上 是 雙 系 統 通 用 函 數-------------------------------------------------------------------------//

//---------------------------------------------------以 下 為 管 理 系 統 的 各 種 定 義 函 數------------------------------------------------------------------//

int manage_password()
{
    FILE *fo;
    char input[100];
    int count = 3; //密碼輸入上限次數,可修改
    char PW[100] = {'\0'};
    while((fo = fopen("C:\\Users\\Lenovo\\Desktop\\manage_password.txt", "r")) == NULL)
        return ERROR;
    fscanf(fo, "%s", PW);
    //printf("%s", PW);
    printf("\n請輸入原密碼:");
    //scanf("%[^\n]s", input);
    //getchar();
    gets(input);
    //strcpy(input, "xxgcxy2019");
    int temp = count + 1;
    while (count && strcmp(input, PW) != 0)
    {
        printf("\n密碼錯誤!請重新輸入(剩餘%d次):", count - 1);
        gets(input);
        if (strcmp(input, PW) == 0)
            break;
        count--;
    }
    if (count == 0)
    {
        printf("\n錯誤次數超過上限,程式退出\n");
        system("pause");
    }
    puts("");
    fclose(fo);
}


Status manage_order()
{
    int order;
    while (1)
    {
        printf("\n請輸入合法的命令:");
        fflush(stdin); //清理緩衝區
        scanf("%d", &order);
        //int temp = (order - '0');

        while (!(order >= 0 && order <= 11))
        {
            //system("cls");
            printf("輸入非法!請輸入合法的命令:");
            fflush(stdin); //清理緩衝區
            scanf("%d", &order);
            //temp = (order - '0');
        }

        switch (order)
        {
        case 0:
            manage_menu();
            //printf("\nSTUnum = %d\n", STUnum);//檢測STUnum是否符合
            break;
        case 1:
            manage_help();
            break;
        case 2:
            read_deyu_and_laodong();
            //printf("\nSTUnum = %d\n", STUnum);
            break;
        case 3:
            read_alldata();
            //printf("\nSTUnum = %d\n", STUnum);
            break;
        case 4:
            allocate();
            //printf("\nSTUnum = %d\n", STUnum);
            break;
        case 5:
            addScore();
            //printf("\nSTUnum = %d\n", STUnum);
            break;
        case 6:
            search_analysis();
            //printf("\nSTUnum = %d\n", STUnum);
            break;
        case 7:
            print_perpass();
            //printf("\nSTUnum = %d\n", STUnum);
            break;
        case 8:
            addstu();
            //printf("\nSTUnum = %d\n", STUnum);
            break;
        case 9:
            delstu();
            //printf("\nSTUnum = %d\n", STUnum);
            break;
        case 10:
            CHANGE_manage_password();
            break;
        case 11:
            printf("系統已結束執行,即將關閉\n");
            //system("pause");
            return OK;
            break;
        }
    }
}

//將read——alldata中的對應資料student——alldata賦值給雙值

//comp函式用於allocate函式中的qsort
//int Comp(compare p1, compare p2)
//{
//    return p1 ? 1 : -1;
//}


int allocate()
{
    start = clock();
    int j = 0, k = 0, n = 0;
    //利用qsort()函式
    //qsort(student_info, 507, sizeof(student_info[1]), comp);
    //qsort(student_alldata, 507, sizeof(student_alldata[1]), comp);
    //for(; j <=507; j++)
    //{
    //    student_info[j] = student_alldata[j];
    //}

    //buddling
    for (k = 0; k < STUnum; k++)
    {
        for (j = 0; j < STUnum - k - 1; j++)
        {
            if (student_info[j].student_xuehao > student_info[j + 1].student_xuehao) //根據單一資料項,對整個結構體進行排序
            {
                buddle_info = student_info[j + 1];
                student_info[j + 1] = student_info[j];
                student_info[j] = buddle_info;
            }
        }
    }
    //buddling
    for (k = 0; k < STUnum; k++)
    {
        for (j = 0; j < STUnum - k - 1; j++)
        {
            if (student_alldata[j].student_xuehao > student_alldata[j + 1].student_xuehao) //根據單一資料項,對整個結構體進行排序
            {
                buddle_zhiyu_tiyu = student_alldata[j + 1];
                student_alldata[j + 1] = student_alldata[j];
                student_alldata[j] = buddle_zhiyu_tiyu;
            }
        }
    }

    //將兩組資料按照對應學號進行合併
    for (j = 0; j < STUnum; j++)
    {
        calculate_zhiyu(j);
        calculate_tiyu(j);
        student_info[j].student_pass = student_alldata[j].pass_or_not;
    }
    finish = clock();

    //printf("%lf\n", student_alldata[1].tiyu_score);
    printf("\n耗時%lfms,匹配成功!\n", (double)(finish - start) / CLOCKS_PER_SEC);
    printf("是否選擇檢視處理後的資訊?(是:1,否:0):");
    enum WON choice;
    scanf("%d", &choice);
    puts("");
    start = clock();
    if (choice == 1)
    {
        printf("    學號       \t\t   姓名      \t 德育成績   體育成績  勞動成績    智育成績        掛科情況\n\n");

        for (k = 0; k < STUnum; k++)
        {
            printf("%lld     %20s      %.2f     %.4f     %.2f      %.8f", student_info[k].student_xuehao, student_info[k].name, student_info[k].student_deyu, student_info[k].student_tiyu, student_info[k].student_laodong, student_info[k].student_zhiyu);
            if (student_info[k].student_pass == pass)
            {
                printf("    未掛科\n");
            }
            else
            {
                printf("    有掛科科目\n");
            }
        }
    }
    finish = clock();
    printf("\n匹配耗時%lfms\n", (double)(finish - start) / CLOCKS_PER_SEC);

    printf("\n匹配成功!!!\n");
}


int read_deyu_and_laodong()
{
    //讀取學號 姓名 身份證號18位 德育成績 勞動成績
    FILE *fp;
    int k = 0;
    if ((fp = fopen("C:\\Users\\Lenovo\\Desktop\\all details in personinfo.txt", "r")) == NULL)
        return ERROR;

    while (fscanf(fp, "%lld %s %s %lf %lf", &student_info[k].student_xuehao, student_info[k].name, student_info[k].id, &student_info[k].student_deyu, &student_info[k].student_laodong) == 5)
    {
        k++;
    }
    //printf("%s", student_info[2].name);
    printf("“從txt中讀入德育和勞動資料”讀取成功!");
    printf("\n是否選擇檢視處理後的資訊?(是:1,否:0):");
    enum WON choice;
    scanf("%d", &choice);
    if (choice == 1)
    {
        printf("\n    學號          \t  姓名     \t        身份證號     德育成績  智育成績\n");
        for (k = 0; k < STUnum; k++)
        {
            printf("%lld    %18s    %22s    %.1f    %.1f\n", student_info[k].student_xuehao, student_info[k].name, student_info[k].id, student_info[k].student_deyu, student_info[k].student_laodong);
        }
    }
    fclose(fp);
    printf("處理完成!\n");
}


int read_alldata()
{
    //讀取學號 各科成績
    FILE *fp1;
    int n = 0;
    if ((fp1 = fopen("C:\\Users\\Lenovo\\Desktop\\the details of the all scores.txt", "r")) == NULL)
        return ERROR;
    //學號
    //計算機學科導論	微積分(Ⅰ)	思想道德修養與法律基礎	計算機技術基礎(雙語)	大學英語聽說(Ⅰ)	體育(Ⅰ)	程式設計基礎
    //軍事理論	線性代數	程式設計基礎實驗	大學英語讀寫(Ⅰ)	微積分A (Ⅱ)	大學英語讀寫(Ⅱ)	大學英語聽說(Ⅱ)	大學生禮儀
    //概率與數理統計	高階語言程式設計	體育(II)	高階語言程式設計實驗	大學物理A(I)	資訊科學前沿

    printf("以下是各科代號:\n");
    printf("××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××\n");
    printf("××計算機學科導論 ICD        微積分(Ⅰ)CA_1     思想道德修養與法律基礎 MFL  計算機技術基礎(雙語)CE   大學英語聽說(Ⅰ)CELS_1              ××\n");
    printf("××體育(Ⅰ)PE_1            程式設計基礎 FP      軍事理論 MT                線性代數 LA               程式設計基礎實驗 EFP                    ××\n");
    printf("××大學英語讀寫(Ⅰ)CERW_1  微積分A (Ⅱ) CA_2    大學英語讀寫(Ⅱ)CERW_2    大學英語聽說(Ⅱ)CELS_2   大學生禮儀 ECS                        ××\n");
    printf("××概率與數理統計 PTMS       高階語言程式設計 AP  體育(II)PE_2              高階語言程式設計實驗 EAP   大學物理A(I) CPA_1    資訊科學前沿 FIS××\n");
    printf("××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××\n");
    puts("");
    printf("    學號        ICD    CA_1    MFL    CE   CELS_1  PE_1     FP     MT     LA    EFP   CERW_1 CA_2  CERW_2  CELS_2  ECS    PTMS    AP    PE_2   EAP   CPA_2  FIS\n");
    while (fscanf(fp1, "%lld %d %d %d %d %d %lf %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", &student_alldata[n].student_xuehao, &student_alldata[n].ICD,
                  &student_alldata[n].CA_1, &student_alldata[n].MFL, &student_alldata[n].CE, &student_alldata[n].CELS_1, &student_alldata[n].PE_1, &student_alldata[n].FP,
                  &student_alldata[n].MT, &student_alldata[n].LA, &student_alldata[n].EFP, &student_alldata[n].CERW_1, &student_alldata[n].CA_2, &student_alldata[n].CERW_2,
                  &student_alldata[n].CELS_2, &student_alldata[n].ECS, &student_alldata[n].PTMS, &student_alldata[n].AP, &student_alldata[n].PE_2, &student_alldata[n].EAP,
                  &student_alldata[n].CPA_1, &student_alldata[n].FIS) == 22)
    {
        printf("%lld    %3d    %3d    %3d    %3d    %3d    %4.1f    %3d    %3d    %3d    %3d    %3d    %3d    %3d    %3d    %3d    %3d    %3d    %3d    %3d    %3d    %d\n", student_alldata[n].student_xuehao, student_alldata[n].ICD,
               student_alldata[n].CA_1, student_alldata[n].MFL, student_alldata[n].CE, student_alldata[n].CELS_1, student_alldata[n].PE_1, student_alldata[n].FP,
               student_alldata[n].MT, student_alldata[n].LA, student_alldata[n].EFP, student_alldata[n].CERW_1, student_alldata[n].CA_2, student_alldata[n].CERW_2,
               student_alldata[n].CELS_2, student_alldata[n].ECS, student_alldata[n].PTMS, student_alldata[n].AP, student_alldata[n].PE_2, student_alldata[n].EAP,
               student_alldata[n].CPA_1, student_alldata[n].FIS);
        if (judge_60(n))
        {
            student_alldata[n].pass_or_not = pass;
        }
        else
        {
            student_alldata[n].pass_or_not = Npass;
        }

        ++n;
    }

    fclose(fp1);
    printf("一共%d組資料\n", n);
    return OK;
}


Status addScore()
{
    int k;

    for (k = 0; k < STUnum; k++)
    {
        student_info[k].student_score = student_info[k].student_deyu + student_info[k].student_tiyu + student_info[k].student_laodong + student_info[k].student_zhiyu;
    }

    printf("\n求和成功!\n");
    printf("是否選擇檢視處理後的資訊?(是:1,否:0):");
    enum WON choice;
    scanf("%d", &choice);
    if (choice == 1)
    {
        printf("    學號       德育成績   體育成績   勞動成績    智育成績        總成績\n");
        for (k = 0; k < STUnum; k++)
        {
            printf("%lld     %.2f     %.4f     %.2f      %.8f      %.4f\n", student_info[k].student_xuehao, student_info[k].student_deyu, student_info[k].student_tiyu, student_info[k].student_laodong, student_info[k].student_zhiyu, student_info[k].student_score);
        }
    }
    printf("處理完成!\n");
}


Status search_analysis()
{
    //printf("請輸入查詢物件的學號(輸入0退出查詢):");
    xuehao XH;
    int k = 0;
    while (1)
    {
        printf("\n備註:諸如“201924100XXX”為原計算機同學學號,“201924080XXX”為軟體工程國際化班同學學號\n\n");
        printf("請輸入查詢物件的學號(輸入0退出查詢):");
        fflush(stdin); //此處沒有問題
        scanf("%lld", &XH);
        if (XH == 0)
        {
            printf("\n已退出查詢\n");
            break;
        }
        start = clock();
        for (k = 0; k < STUnum; k++)
        {
            if (XH == student_info[k].student_xuehao)
            {
                printf("    學號       \t\t  身份證號         德育成績   體育成績   勞動成績    智育成績        總成績      掛科情況\n\n");
                printf("%lld     %22s      %.2f     %.4f     %.2f      %.8f      %.4f", student_info[k].student_xuehao, student_info[k].id, student_info[k].student_deyu, student_info[k].student_tiyu, student_info[k].student_laodong, student_info[k].student_zhiyu, student_info[k].student_score);
                if (student_info[k].student_pass == pass)
                {
                    printf("      未掛科\n");
                }
                else
                {
                    printf("      有掛科科目\n");
                }
                break;
            }
        }
        if (k == STUnum)
        {
            printf("找不到咩,你輸的是個啷個?\n");
        }
        finish = clock();
        printf("\n查詢時間為:%lfms\n\n", (double)(finish - start) / CLOCKS_PER_SEC);
        printf("------------------------------------------------------------------------------------------------------------------\n");
    }
}


Status sorting()
{
    start = clock();
    int j, k;
    for (k = 0; k < STUnum; k++)
    {
        for (j = 0; j < STUnum - k - 1; j++)
        {
            if (student_info[j].student_score <= student_info[j + 1].student_score) //根據總成績,對整個結構體進行排序
            {
                buddle_info = student_info[j + 1];
                student_info[j + 1] = student_info[j];
                student_info[j] = buddle_info;
            }
        }
    }
    finish = clock();
    printf("\n氣泡排序完成,耗時:%lfms\n\n", (double)(finish - start) / CLOCKS_PER_SEC);
}


void shellSort(int *a, int len)
{
    start = clock();
    //len = STUnum;
    int n, j, k, gap; // gap 為步長
    for (gap = len / 2; gap > 0; gap /= 2)
    { // 步長初始化為陣列長度的一半,每次遍歷後步長減半,
        for (n = 0; n < gap; ++n)
        { // 變數 i 為每次分組的第一個元素下標
           for (j = n + gap; j < len; j += gap)
           {               //對步長為gap的元素進行直插排序,當gap為1時,就是直插排序
               buf_info[j] = student_info[j]; 
               // 備份student_info[j]的值
               k = j - gap;                   \
               // j初始化為i的前一個元素(與i相差gap長度)
               while (k >= 0 && student_info[k].student_score < buf_info[j].student_score)
               {
                   student_info[k + gap] = student_info[k]; // 將在student_info[i].student_score前且比的值大的結構體陣列向後移動一位
                   k -= gap;
                }
                student_info[k + gap] = buf_info[j];
            }
        }
    }
    finish = clock();
    printf("\n希爾排序完成,耗時:%lfms\n\n", (double)(finish - start) / CLOCKS_PER_SEC);
}

//Status using_shellSort()
//{
//    shellSort(student_info->student_score, STUnum); // 呼叫希爾排序函式
//    //printf("希爾升序排列後結果為:\n");
//    //for (i = 0; i < len; i++)
//    //{ // 排序後的結果的輸出
//    //   printf("%d\t", a[i]);
//    //}
//}


Status submenu()//更新中……
{
    //printf("\n請選擇你要排序的物件\n");
    //printf("****************************************************************************************\n");
    //printf("**   1.電腦科學導論 ICD            2.微積分(Ⅰ)CA_1                               **\n");
    //printf("**   3.思想道德修養與法律基礎 MFL    4.計算機技術基礎(雙語)CE                       **\n");
    //printf("**   5.大學英語聽說(Ⅰ)CELS_1      6.體育(Ⅰ)PE_1                                 **\n");
    //printf("**   7.程式設計基礎 FP               8.軍事理論 MT                                    **\n");
    //printf("**   9.線性代數 LA                  10.程式設計基礎實驗 EFP                           **\n");
    //printf("**   11.大學英語讀寫(Ⅰ)CERW_1    12.微積分A (Ⅱ) CA_2                              **\n");
    //printf("**   13.大學英語讀寫(Ⅱ)CERW_2    14.大學英語聽說(Ⅱ)CELS_2                       **\n");
    //printf("**   15.大學生禮儀 ECS              16.概率與數理統計 PTMS                            **\n");
    //printf("**   17.高階語言程式設計 AP         18.體育(II)PE_2                                 **\n");
    //printf("**   19.高階語言程式設計實驗 EAP    20.大學物理A(I) CPA_1        21.資訊科學前沿 FIS  **\n");
    printf("****************************************************************************************\n");
    printf("**   1.體育成績                    2.智育成績                  3.總成績               **\n");
    printf("**   0.退出排序                                                                       **\n");
    printf("****************************************************************************************\n");
    printf("\n請輸入查詢序號:");
    int choi, count = 0;
    fflush(stdin); //清理緩衝區,此處沒有問題
    scanf("%d", &choi);
    while (!(choi >= 0 && choi <= 24))
    {
        printf("\n輸入的序號有些問題,請重新輸入:");
        fflush(stdin); //清理緩衝區,此處沒有問題
        scanf("%d", &choi);
        count++;
        if (count == 0)
        {
            printf("\n是否想要結束排序?需要結束請輸入0:");
            scanf("%d", &choi);
        }
    }
    switch (choi)
    {
    case 0:
        printf("\n已退出排序子選單!\n");
        break;
        //case 1:
        //case 2:
    case 3:
        sorting();
        break;
    }
}


Status print_perpass()
{
    int k = 0;
    int num = 0;
    printf("\n進入此命令模組將會牽扯到同學們的隱私,請再三考慮:\n");
    getchar();
    char input[100];
    int count = 3; //密碼輸入上限次數,可修改
    char PW[100] = {"05060519"};
    printf("\n請輸入密碼:");
    //scanf("%[^\n]s", input);
    gets(input);
    //strcpy(input, "xxgcxy2019");
    int temp = count + 1;
    while (count && strcmp(input, PW) != 0)
    {
        printf("\n密碼錯誤!請重新輸入(剩餘%d次):", count - 1);
        gets(input);
        if (strcmp(input, PW) == 0)
            break;
        count--;
    }
    if (count == 0)
    {
        printf("\n錯誤次數超過上限,退出該功能\n");
        //system("pause");
        //exit(0);
    }
    else
    {
        puts("");
        printf("\n    學號       \t\t   姓名      \t 德育成績   體育成績  勞動成績    智育成績        掛科情況\n\n");
        for (k; k < STUnum; k++)
        {
            if (student_info[k].student_pass == 0)
            {
                printf("%lld     %20s      %.2f     %.4f     %.2f      %.8f", student_info[k].student_xuehao, student_info[k].name, student_info[k].student_deyu, student_info[k].student_tiyu, student_info[k].student_laodong, student_info[k].student_zhiyu);
                printf("    有掛科科目\n");
                num++;
            }
        }
        printf("\n本年級共有%d人,其中%d人有掛科科目,佔比%2.2f%%\n", STUnum, num, 1.0 * 100 * num / STUnum);
    }
}


Status CHANGE_manage_password()
{
    int choi;
    printf("\n是否想要對管理系統的登入密碼進行修改?(按數字0或者任意非數字退出)\n");
    fflush(stdin);
    scanf("%d", &choi);
    if(choi != 0)
    {
        getchar();
        manage_password();
        char origin_PW[100];
        char CHANGE_PW[100] = {'\0'};
        FILE *fpt;
        FILE *fin;
        fin = fopen("C:\\Users\\Lenovo\\Desktop\\manage_password.txt", "r");                   //讀開啟原檔案
        fpt = fopen("C:\\Users\\Lenovo\\Desktop\\tmp3.txt", "w");                          //寫開啟臨時檔案
        if (fin == NULL && fpt == NULL)
        {
            printf("Open the file failure...\n");
            exit(0);
        }
        printf("請輸入一個新的密碼:");
        scanf("%s", CHANGE_PW);
        while (fscanf(fin, "%s", origin_PW) == 1) //從原檔案讀取一行
        {
            fprintf(fpt, "%s\n", CHANGE_PW); //寫入臨時檔案tmp3.txt
        }
        fclose(fin);
        fclose(fpt);
        remove("C:\\Users\\Lenovo\\Desktop\\manage_password.txt");                                                       //刪除原檔案
        rename("C:\\Users\\Lenovo\\Desktop\\tmp3.txt", "C:\\Users\\Lenovo\\Desktop\\manage_password.txt");               //將臨時檔名改為原檔名

        printf("\n已完成對登入管理系統密碼的修改\n");
    }
    
}


//----------------------------------------------------------以 上 是 管 理 系 統 的 各 種 定 義 函 數------------------------------------------------------------------//

//----------------------------------------------------------以 下 是 學 生 系 統 的 各 種 聲 明 函 數------------------------------------------------------------------//

Status student_read_deyu_and_laodong()
{
    STUnum = 0;
    FILE *fp;
    if ((fp = fopen("C:\\Users\\Lenovo\\Desktop\\all details in personinfo.txt", "r")) == NULL)
        return ERROR;

    while (fscanf(fp, "%lld %s %s %lf %lf", &student_info[STUnum].student_xuehao, student_info[STUnum].name, student_info[STUnum].id, &student_info[STUnum].student_deyu, &student_info[STUnum].student_laodong) == 5)
    {
        STUnum++;
    }
    fclose(fp);
}


Status student_read_alldata()
{
    //讀取學號 各科成績
    FILE *fp1;
    int n = 0;
    if ((fp1 = fopen("C:\\Users\\Lenovo\\Desktop\\the details of the all scores.txt", "r")) == NULL)
        return ERROR;
    while (fscanf(fp1, "%lld %d %d %d %d %d %lf %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", &student_alldata[n].student_xuehao, &student_alldata[n].ICD,
                  &student_alldata[n].CA_1, &student_alldata[n].MFL, &student_alldata[n].CE, &student_alldata[n].CELS_1, &student_alldata[n].PE_1, &student_alldata[n].FP,
                  &student_alldata[n].MT, &student_alldata[n].LA, &student_alldata[n].EFP, &student_alldata[n].CERW_1, &student_alldata[n].CA_2, &student_alldata[n].CERW_2,
                  &student_alldata[n].CELS_2, &student_alldata[n].ECS, &student_alldata[n].PTMS, &student_alldata[n].AP, &student_alldata[n].PE_2, &student_alldata[n].EAP,
                  &student_alldata[n].CPA_1, &student_alldata[n].FIS) == 22)
    {
        if (judge_60(n))
        {
            student_alldata[n].pass_or_not = pass;
        }
        else
        {
            student_alldata[n].pass_or_not = Npass;
        }

        ++n;
    }
    fclose(fp1);
    //return OK;
}


Status student_allocate()
{
    int j = 0, k = 0, n = 0;

    //buddling
    for (k = 0; k < STUnum; k++)
    {
        for (j = 0; j < STUnum - k - 1; j++)
        {
            if (student_info[j].student_xuehao > student_info[j + 1].student_xuehao) //根據單一資料項,對整個結構體進行排序
            {
                buddle_info = student_info[j + 1];
                student_info[j + 1] = student_info[j];
                student_info[j] = buddle_info;
            }
        }
    }
    //buddling
    for (k = 0; k < STUnum; k++)
    {
        for (j = 0; j < STUnum - k - 1; j++)
        {
            if (student_alldata[j].student_xuehao > student_alldata[j + 1].student_xuehao) //根據單一資料項,對整個結構體進行排序
            {
                buddle_zhiyu_tiyu = student_alldata[j + 1];
                student_alldata[j + 1] = student_alldata[j];
                student_alldata[j] = buddle_zhiyu_tiyu;
            }
        }
    }

    //將兩組資料按照對應學號進行合併
    for (j = 0; j < STUnum; j++)
    {
        calculate_zhiyu(j);
        calculate_tiyu(j);
        student_info[j].student_pass = student_alldata[j].pass_or_not;
    }
}


Status student_addScore()
{
    int k;
    for (k = 0; k < STUnum; k++)
    {
        student_info[k].student_score = student_info[k].student_deyu + student_info[k].student_tiyu + student_info[k].student_laodong + student_info[k].student_zhiyu;
    }
}


Status student_account()
{
    int count = 3; //輸入次數上限,超出則退出學生查詢用系統
    int flag_1 = 0, flag_2 = 0;
    xuehao XH;
    char account[10];
    while (count--)
    {
        flag_1 = 0, flag_2 = 0;
        printf("請輸入學生使用者賬號和密碼(剩餘%d次):\n", count );
        printf("賬號:");
        //fflush(stdin);
        scanf("%lld", &XH);
        printf("密碼:");
        scanf("%s", account);
        for (i = 0; i < STUnum; i++)
        {
            if (XH == student_info[i].student_xuehao)
            {
                flag_1 = 1;
            }
            if (!strcmp(account, student_info[i].PW))
            {
                flag_2 = 1;
            }
            if (flag_1 + flag_2 == 2)
            {
                break;
            }
        }
        if (flag_1 + flag_2 == 0)
            printf("輸入不正確,請重新輸入\n");
        else if (flag_1 == 1 && flag_2 == 0)
            printf("密碼輸入不正確,請重新輸入\n");
        else if (flag_1 == 0 && flag_2 == 1)
            printf("學號輸入不正確,請重新輸入\n");
        if (flag_1 + flag_2 == 2)
        {
            break;
        }
        if (count == 0)
        {
            if (flag_1 + flag_2 != 2)
            {
                printf("\n錯誤次數超過上限,程式退出\n");
                system("pause");
                exit(0);
            }
        }
    }
}


Status student_order()
{
    int order;
    while (1)
    {
        printf("\n請輸入合法的命令:");
        fflush(stdin); //清理緩衝區,此處沒有問題
        scanf("%d", &order);
        //int temp = (order - '0');

        while (!(order >= 1 && order <= 3))
        {
            //system("cls");
            printf("輸入非法!請輸入合法的命令:");
            fflush(stdin); //清理緩衝,此處沒有問題
            scanf("%d", &order);
            //temp = (order - '0');
        }

        switch (order)
        {
        case 1:
            student_help();
            break;
        case 2:
            student_all_score();
            break;
        case 3:
            printf("系統已結束執行,即將關閉\n");
            //system("pause");
            return OK;
            break;
        }
    }
}


Status student_all_score()
{
    printf("    學號       \t\t  身份證號         德育成績   體育成績   勞動成績    智育成績        總成績      掛科情況      綜測排名\n\n");
    //printf("    學號       \t\t  身份證號         德育成績   體育成績   勞動成績    智育成績        總成績\n\n");
    printf("%lld     %22s      %.2f     %.4f     %.2f      %.8f      %.4f", student_info[i].student_xuehao,
           student_info[i].id, student_info[i].student_deyu, student_info[i].student_tiyu, student_info[i].student_laodong,
           student_info[i].student_zhiyu, student_info[i].student_score);
    if (student_info[i].student_pass == pass)
    {
        printf("      未掛科");
    }
    else
    {
        printf("     有掛科科目");
    }
    printf("       第%d名\n", i);
}


Status student_help()
{
    printf("********************************************************************************************************\n");
    printf("**此為××屆資訊工程學院學生成績學生用(查詢)系統                                                    **\n");
    printf("**平臺僅為同學們提供個人綜測中個人資訊的查詢功能,同學們輸入本人的學號(賬號)和身份證號後六位(密碼)**\n**後進入查詢介面");
    printf("輸入1,可再次調出本說明;輸入2,可查詢到本人的成績資訊;輸入3,即退出本查詢平臺       **\n");
    printf("********************************************************************************************************\n");
}


//----------------------------------------------------------以 上 是 學 生 系 統 的 各 種 聲 明 函 數------------------------------------------------------------------//


void InitList(LinkList *L) //初始化連結串列
{
    L = (LinkList *)malloc(sizeof(LinkList));
    L->next = NULL;
}


void ListInsert(LinkList *L, LinkList *p) //插入新的節點
{
    LinkList *q = NULL;
    q = L;
    p->next = q->next;
    q->next = p;
}


Status addstu()
{
    int disc = 0;
    fflush(stdin);
    printf("\n確定要進行新增功能嗎?按數字0或字母鍵退出\n");
    scanf("%d", &disc);
    if(disc != 0)
    {
        STUnum++;
        printf("請按順序輸入新增同學的學號、姓名、身份證號、德育成績、勞動成績以及計算機學科導論 ICD、微積分(Ⅰ)CA_1、思想道德修養與法律基礎 MFL、計算機技術基礎(雙語)CE、大學英語聽說(Ⅰ)CELS_1、");
        printf("體育(Ⅰ)PE_1、程式設計基礎 FP、軍事理論 MT、線性代數 LA、程式設計基礎實驗 EFP、");
        printf("大學英語讀寫(Ⅰ)CERW_1、微積分A (Ⅱ) CA_2、大學英語讀寫(Ⅱ)CERW_2、大學英語聽說(Ⅱ)CELS_2、大學生禮儀 ECS、");
        printf("概率與數理統計 PTMS、高階語言程式設計 AP、體育(II)PE_2、高階語言程式設計實驗 EAP、大學物理A(I) CPA_1、資訊科學前沿 FIS成績\n");
        fflush(stdin);
        scanf("%lld", &student_info[STUnum].student_xuehao);
        scanf("%s %s %lf %lf %d %d %d %d %d %lf %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", student_info[STUnum].name, student_info[STUnum].id, &student_info[STUnum].student_deyu,
              &student_info[STUnum].student_laodong, &student_alldata[STUnum].ICD, &student_alldata[STUnum].CA_1, &student_alldata[STUnum].MFL, &student_alldata[STUnum].CE, &student_alldata[STUnum].CELS_1, &student_alldata[STUnum].PE_1,
              &student_alldata[STUnum].FP, &student_alldata[STUnum].MT, &student_alldata[STUnum].LA, &student_alldata[STUnum].EFP, &student_alldata[STUnum].CERW_1, &student_alldata[STUnum].CA_2, &student_alldata[STUnum].CERW_2,
              &student_alldata[STUnum].CELS_2, &student_alldata[STUnum].ECS, &student_alldata[STUnum].PTMS, &student_alldata[STUnum].AP, &student_alldata[STUnum].PE_2, &student_alldata[STUnum].EAP,
              &student_alldata[STUnum].CPA_1, &student_alldata[STUnum].FIS);
        calculate_tiyu(STUnum);
        calculate_zhiyu(STUnum);
        printf("\n新增完成\n");
        FILE *fp_1;
        FILE *fp_2;
        while ((fp_1 = fopen("C:\\Users\\Lenovo\\Desktop\\the details of the all scores.txt", "a")) == NULL)
        {
            exit(ERROR);
        }
        while ((fp_2 = fopen("C:\\Users\\Lenovo\\Desktop\\all details in personinfo.txt", "a")) == NULL)
        {
            exit(ERROR);
        }
        fprintf(fp_1, "%lld %d %d %d %d %d %lf %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", student_info[STUnum].student_xuehao, student_alldata[STUnum].ICD,
                student_alldata[STUnum].CA_1, student_alldata[STUnum].MFL, student_alldata[STUnum].CE, student_alldata[STUnum].CELS_1, student_alldata[STUnum].PE_1, student_alldata[STUnum].FP,
                student_alldata[STUnum].MT, student_alldata[STUnum].LA, student_alldata[STUnum].EFP, student_alldata[STUnum].CERW_1, student_alldata[STUnum].CA_2, student_alldata[STUnum].CERW_2,
                student_alldata[STUnum].CELS_2, student_alldata[STUnum].ECS, student_alldata[STUnum].PTMS, student_alldata[STUnum].AP, student_alldata[STUnum].PE_2, student_alldata[STUnum].EAP,
                student_alldata[STUnum].CPA_1, student_alldata[STUnum].FIS);
        fclose(fp_1);
        fprintf(fp_2, "%lld %s %s %lf %lf\n", student_info[STUnum].student_xuehao, student_info[STUnum].name, student_info[STUnum].id, student_info[STUnum].student_deyu,
                student_info[STUnum].student_laodong);
        fclose(fp_2);
        printf("\n檔案寫入完成\n");
        printf("\n不要忘記再利用選單鍵入功能2.3.4.5.以便將成績錄入系統哦\n");
    }
    else
    {
        printf("\n已退出新增資訊功能區\n");
    }
    
}


Status delstu()
{
    //按學號進行刪減資訊
    printf("請輸入要刪減資訊對應的學生學號:");
    xuehao XH;
    int j, flag = 0;
    scanf("%lld", &XH);
    for (j = 0; j < STUnum; j++)
    {
        if (student_info[j].student_xuehao == XH)
        {
            flag = 1;
            break;
        }
    }
    if (!flag)
    {
        printf("\n沒有找到對應需要刪減的資訊,請重新輸入\n");
    }
    else
    {
        //{
        //    student_info[j].student_score = 0;
        //    student_info[j].student_deyu = 0;
        //    student_info[j].student_laodong = 0;
        //    student_info[j].student_zhiyu = 0;
        //    student_info[j].student_tiyu = 0;
        //} 
        //初始化,並利用sorting()函式將其排至最後從而實現剔除

        STUnum--;
        int k = 0;

        FILE *fin;
        FILE *ftp;
        fin = fopen("C:\\Users\\Lenovo\\Desktop\\the details of the all scores.txt", "r"); //讀開啟原檔案
        ftp = fopen("C:\\Users\\Lenovo\\Desktop\\tmp1.txt", "w");  //寫開啟臨時檔案
        if (fin == NULL && ftp == NULL)
        {
            printf("Open the file failure...\n");
            exit(0);
        }
        while (fscanf(fin, "%lld %d %d %d %d %d %lf %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", &student_info->student_xuehao, &student_alldata->ICD, &student_alldata->CA_1, &student_alldata->MFL, &student_alldata->CE, &student_alldata->CELS_1, &student_alldata->PE_1,
                      &student_alldata->FP, &student_alldata->MT, &student_alldata->LA, &student_alldata->EFP, &student_alldata->CERW_1, &student_alldata->CA_2, &student_alldata->CERW_2,
                      &student_alldata->CELS_2, &student_alldata->ECS, &student_alldata->PTMS, &student_alldata->AP, &student_alldata->PE_2, &student_alldata->EAP,
                      &student_alldata->CPA_1, &student_alldata->FIS) == 22) //從原檔案讀取一行
        {
            if (student_info->student_xuehao != XH)
                fprintf(ftp, "%lld %d %d %d %d %d %lf %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", student_info->student_xuehao, student_alldata->ICD, student_alldata->CA_1, student_alldata->MFL, student_alldata->CE, student_alldata->CELS_1, student_alldata->PE_1,
                        student_alldata->FP, student_alldata->MT, student_alldata->LA, student_alldata->EFP, student_alldata->CERW_1, student_alldata->CA_2, student_alldata->CERW_2,
                        student_alldata->CELS_2, student_alldata->ECS, student_alldata->PTMS, student_alldata->AP, student_alldata->PE_2, student_alldata->EAP,
                        student_alldata->CPA_1, student_alldata->FIS); //不是則將這一行寫入臨時檔案tmp1.txt
        }
        fclose(fin);
        fclose(ftp);
        remove("C:\\Users\\Lenovo\\Desktop\\the details of the all scores.txt");               //刪除原檔案
        rename("C:\\Users\\Lenovo\\Desktop\\tmp1.txt", "C:\\Users\\Lenovo\\Desktop\\the details of the all scores.txt"); //將臨時檔名改為原檔名

        printf("\n已在檔案“the details of the all scores.txt”中完成對資訊的刪減\n");

            //FILE *fin;
            //FILE *ftp;
        fin = fopen("C:\\Users\\Lenovo\\Desktop\\all details in personinfo.txt", "r"); //讀開啟原檔案
        ftp = fopen("C:\\Users\\Lenovo\\Desktop\\tmp2.txt", "w");                          //寫開啟臨時檔案
        if (fin == NULL && ftp == NULL)
        {
            printf("Open the file failure...\n");
            exit(0);
        }
        while (fscanf(fin, "%lld %s %s %lf %lf\n", &student_info->student_xuehao, student_info->name, student_info->id, &student_info->student_deyu,
                      &student_info->student_laodong) == 5) //從原檔案讀取一行
        {
            if (student_info->student_xuehao != XH)
                fprintf(ftp, "%lld %s %s %lf %lf\n", student_info->student_xuehao, student_info->name, student_info->id, student_info->student_deyu,
                                     student_info->student_laodong); //不是則將這一行寫入臨時檔案tmp1.txt
        }
        fclose(fin);
        fclose(ftp);
        remove("C:\\Users\\Lenovo\\Desktop\\all details in personinfo.txt");                                             //刪除原檔案
        rename("C:\\Users\\Lenovo\\Desktop\\tmp2.txt", "C:\\Users\\Lenovo\\Desktop\\all details in personinfo.txt");     //將臨時檔名改為原檔名

        printf("\n已在檔案“all details in personinfo.txt”中完成對資訊的刪減\n");

        system("pause");
    }
}



//----------------------------------------------------------以 上 是 學 生 系 統 的 各 種 聲 明 函 數------------------------------------------------------------------//

int main()
{
    char WHT[100];
    {
        printf("提前處理資料中的排序方式:1.氣泡排序 2.希爾排序\n");
        int CH = -1;
        fflush(stdin);
        scanf("%d", &CH);
        student_read_deyu_and_laodong(); //計數 STUnum
        student_read_alldata();
        student_allocate();
        student_addScore();
        allocte_all_password();
        if(CH == 1)
        {
            sorting();//氣泡排序
        }
        else
        {
            shellSort(student_info, STUnum);//希爾排序
        }
        printf("\n即將進入雙系統選擇視窗······\n");
    }
    //提前處理資料
    //system("cls");
    //for(int j = 0; j < STUnum; j++)
    //printf("%lld %s\n", student_info[j].student_xuehao, student_info[j].PW);//驗證密碼是否正確
    //choose_system();
    int choice = -1;
    fflush(stdin); //此處沒有問題
    //scanf("%d", &choice);
    stdio_messagebox(ret, choice);
    system("cls");
    switch (CHOICE)
    {
    case 1:
        manage_menu();
        manage_password();
        printf("\t\t\t******************\n");
        printf("\t\t\t* 歡迎使用本系統 *\n");
        printf("\t\t\t******************");
        puts("");
        manage_order();
        system("pause");
        //printf("STUnum = %d\n", STUnum);//檢查STUnum是否符合
        break;
    case 2:
        student_menu();
        student_account();
        printf("\t\t\t******************\n");
        printf("\t\t\t* 歡迎使用本系統 *\n");
        printf("\t\t\t******************");
        puts("");
        student_order();
        system("pause");
        break;
    }
    
    return 0;
}

功能流程圖(功能上有略微改動):
在這裡插入圖片描述

相關文章