溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

C語言實(shí)現(xiàn)簡單學(xué)生選課管理系統(tǒng)

發(fā)布時(shí)間:2020-09-20 01:46:57 來源:腳本之家 閱讀:424 作者:AlbeltBO 欄目:編程語言

本文實(shí)例為大家分享了C語言實(shí)現(xiàn)學(xué)生選課管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

這是我們大一C語言課程設(shè)計(jì)的最終作品,涉及文件讀寫操作、鏈表的一系列操作。

源代碼由頭文件all.h、主函數(shù)文件main.cpp以及功能函數(shù)文件student.cpp、manager.cpp、common.cpp組成。

涉及的文件讀寫操作需要先手動(dòng)創(chuàng)建文件,文件路徑可以在all.h的宏定義中更改

使用vs2017的c++編譯器,兼容c語言,現(xiàn)貼上源代碼和運(yùn)行截圖,供感興趣的童鞋參考,水平有限還望多多包涵。

運(yùn)行截圖

C語言實(shí)現(xiàn)簡單學(xué)生選課管理系統(tǒng)

all.h

#pragma once
#define MAXN 50
#define STU_F  "C:\\stu_cour_info_system\\date\\student.txt"  //文件存放路徑及文件名
#define COUR_F  "C:\\stu_cour_info_system\\date\\course.txt"  //文件存放路徑及文件名
#define MAN_F  "C:\\stu_cour_info_system\\date\\manager.txt"     //文件存放路徑及文件名
 
#define STU_F_BACKUP  "C:\\stu_cour_info_system\\backup\\student.txt"  //備份文件存放路徑及文件名
#define COUR_F_BACKUP  "C:\\stu_cour_info_system\\backup\\course.txt"   //備份文件存放路徑及文件名
#define MAN_F_BACKUP  "C:\\stu_cour_info_system\\backup\\manager.txt"      //備份文件存放路徑及文件名
 
struct student //學(xué)生信息結(jié)構(gòu)體
{
 char name[MAXN];      //姓名
 char num[MAXN];  //學(xué)號(hào)
 char sch_cla[20];       //學(xué)院和班級(jí)
 double score_all = 0; //應(yīng)選總學(xué)分
 double score_sel = 0; //已選課總學(xué)分
 char password[9];  //學(xué)生登陸密碼,共8位
 int course_sum;  //選課總數(shù)
 char course[50][MAXN];  //記錄選課課程的編號(hào)
 struct student *next;  //鏈表指針
};
 
struct course //課程信息結(jié)構(gòu)體
{
 char num[MAXN];  //課程編號(hào)
 char name[MAXN];  //課程名稱
 char nature[MAXN];  //課程性質(zhì)
 char term[MAXN];  //開課學(xué)期
 double time_all;    //總學(xué)時(shí)
 double time_teach;   //授課學(xué)時(shí)
 double time_exp;   //實(shí)驗(yàn)或上機(jī)學(xué)時(shí)
 double score;    //該課程學(xué)分
 int stu_max;   //能夠容納的學(xué)生總數(shù)
 int stu_sum;   //已經(jīng)選課學(xué)生總數(shù)
 char stu[100][MAXN];  //已經(jīng)選課學(xué)生學(xué)號(hào)
 struct course *next;  //鏈表指針
};
 
/*通用函數(shù)*/
int judge_num(char *ch);         //用于檢測輸入的字符串ch是否全部為數(shù)字,全部為數(shù)字則返回1,否則返回0
int input_num();          //用于輸入數(shù)字,如果輸入的全部為數(shù)字則返回該數(shù)字,否則一直停在輸入狀態(tài)
double input_double();                                   //用于輸入小數(shù)
int input_limit(int n);         //輸入選項(xiàng),控制輸入的數(shù)字范圍為0-n,在這個(gè)范圍內(nèi)則返回該數(shù)字,否則一直停在輸入狀態(tài)
int input_limit0(int n);
int keyexam(char *actual_key, char *input_key);   //密碼檢測函數(shù),x為密碼位數(shù),actul_key[]為真實(shí)密碼,input_key為輸入密碼,密碼匹配返回1否則返回0
student* load_stu();          //將學(xué)生文件生成鏈表,返回鏈表頭指針
void store_stu(student *p_head);       //將學(xué)生鏈表存入學(xué)生文件,需傳入鏈表頭指針
course* load_cour();          //將課程文件生成鏈表,返回鏈表頭指針
void store_cour(course *p_head);       //將課程鏈表存入課程文件,需傳入鏈表頭指針 
student* locate_end(student *head);                         //傳入頭節(jié)點(diǎn),返回尾節(jié)點(diǎn)
course* locate_end(course *head);                          //傳入頭節(jié)點(diǎn),返回尾節(jié)點(diǎn)
void help();            //顯示幫助信息
int link_count(student* head);
int link_count(course* head);        //計(jì)算鏈表節(jié)點(diǎn)數(shù)量
int judge_ascii_num(char in[]);                             //檢測輸入是否全部為ASCII的數(shù)字,是返回1否則返回0
 
 
           /*管理員函數(shù)*/
int man_login();          //管理員登陸函數(shù),密碼正確返回1,否則返回0
int man_menu();           //管理員主菜單,返回對(duì)應(yīng)的輸入值
void student_add(student *head);        //增加學(xué)生的函數(shù)
void student_delete(student *head);        //刪除學(xué)生的函數(shù)
void man_search_stu(student *head);        //搜索學(xué)生的函數(shù)
void student_modify(student *head);       //管理員修改學(xué)生信息
void course_add(course *head);        //增加課程的函數(shù)
void course_delete(course *head);       //刪除課程的函數(shù)
void course_modify(course *head);       //修改課程信息的函數(shù)
void print_all();                                     //打印所有學(xué)生和課程的函數(shù)
void man_modifyKey();         //管理員修改密碼
void man_backups_recover();        //管理員備份和恢復(fù)數(shù)據(jù)
void courseshowone_man(course *ad);     //管理員顯示一門課程信息
void courseshowall_man(course *ad);      //管理員顯示所有課程信息
 
          /*學(xué)生函數(shù)*/
student* stu_login(student* head);       //學(xué)生登陸函數(shù),學(xué)號(hào)和密碼都正確則返回鏈表中該學(xué)生的指針,錯(cuò)誤則返回null
int stu_menu();          //學(xué)生菜單,返回對(duì)應(yīng)的輸入值
void student_showone(student *p);       //顯示一個(gè)學(xué)生的信息
void student_showall(student *head);      //顯示所有學(xué)生的信息
student *studentnamefind_char(student *head, char tar[]);   //根據(jù)學(xué)生姓名查找學(xué)生,如果學(xué)生為頭節(jié)點(diǎn)則返回空指針,不為頭節(jié)點(diǎn)則返回前一個(gè)節(jié)點(diǎn)的指針,不存在則返回尾節(jié)點(diǎn)
student *studentnamefind_num(student *head, char tar[]);   //根據(jù)學(xué)生學(xué)號(hào)查找學(xué)生,如果學(xué)生為頭節(jié)點(diǎn)則返回空指針,不為頭節(jié)點(diǎn)則返回前一個(gè)節(jié)點(diǎn)的指針,不存在則返回尾節(jié)點(diǎn)
void stu_modifyKey(student* stu);       //學(xué)生修改密碼
void coursechoose(course* head, student* stu);   //選課函數(shù),min為最少要達(dá)到的學(xué)分
void courseshow_nature(course *head);      //根據(jù)課程性質(zhì)查找并顯示課程信息
void courseshow_term(course *head);      //根據(jù)開課學(xué)期查找并顯示課程信息
void cour_nat_te(course* head);                          //根據(jù)課程性質(zhì)與開課學(xué)期組合查找課程信息
void coursenumfindtip(course *head);      //查課子函數(shù)
void coursenamefindtip(course *head);      //查課子函數(shù)2
void stu_dele_cour(course* head, student* stu);    //刪除已選課程
 
          /*課程函數(shù)*/
void course_showone(course *ad);       //顯示一門的信息
void course_showall(course *head);       //顯示所有課程的信息
void search_course(course *head);        //搜索課程的函數(shù)
course *coursenamefind_char(course* head, char tar[]);    //根據(jù)課程名稱查找課程節(jié)點(diǎn),如果課程為頭節(jié)點(diǎn)則返回空指針,不為頭節(jié)點(diǎn)則返回前一個(gè)節(jié)點(diǎn)的指針,不存在則返回尾節(jié)點(diǎn)
course *coursenumfind_num(course* head, char tar[]);    //根據(jù)課程編號(hào)查找課程,如果課程為頭節(jié)點(diǎn)則返回空指針,不為頭節(jié)點(diǎn)則返回前一個(gè)節(jié)點(diǎn)的指針,不存在則返回尾節(jié)點(diǎn)

main.cpp

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include"all.h"
 
student* stu_head;
course* cour_head;
course *cour_tail; 
student *stu_tail;     //這四個(gè)指針是全局變量
 
int main()
{
 /*對(duì)四個(gè)指針變量初始化*/
 stu_head = load_stu();    //stu_head指向?qū)W生鏈表頭
 stu_tail = locate_end(stu_head);  //stu_tail指向?qū)W生鏈表尾
 cour_head = load_cour();   //cour_head指向課程鏈表頭
 cour_tail = locate_end(cour_head); //cour_tail指向課程鏈表尾
 
 //{/*這段代碼用于生成原始管理員密碼:10個(gè)0;
 // 編譯鏈接后執(zhí)行一次然后注釋掉*/
 // FILE *fp = fopen(MAN_F, "w+");
 // for (int i = 0; i < 10; i++)
 // {
 // fputc('0', fp);
 // }
 // fclose(fp); 
 //}
 
 
 printf("\n\t\t--------------------------------歡迎使用選課系統(tǒng)!---------------------------------\n");
 int status=-1;
 while (1)//判斷登陸類型
 {
 status = -1;
 printf("\n\n\t\t*****請(qǐng)選擇登陸類型 [1]學(xué)生  [2]管理員  [3]顯示幫助  [0]退出系統(tǒng):");
 status = input_limit0(3);
 if ((status == 0) || (status == 1) || (status == 2)||(status==3))
  break;
 else
  printf("\n\t\t##### 輸入錯(cuò)誤!只能選擇1、2或0 #######\n");
 }
 
 while (1)
 {
 if (status == 2)//管理員登陸
 {
  if (man_login() == 1)
  {
  printf("\n\n\t\t-----------------------------------管理員登陸成功!--------------------------------\n\n");
  int menu_return = man_menu();
  while (1)
  {
   switch (menu_return)
   {
   case 1:
   student_add(stu_head); break;
   case 2:
   student_delete(stu_head); break;
   case 3:
   student_modify(stu_head); break;
   case 4:
   man_search_stu(stu_head); break;
   case 5:
   course_add(cour_head); break;
   case 6:
   course_delete(cour_head); break;
   case 7:
   course_modify(cour_head); break;
   case 8:
   search_course(cour_head); break;
   case 9:
   print_all(); break;
   case 10:
   man_modifyKey(); break;
   case 11:
   man_backups_recover(); break;
   case 0:
   break;
   default:
   printf("\t\t\t#####輸入錯(cuò)誤,請(qǐng)重新輸入######!\n");
   }
 
   if (menu_return == 0)
   break;
   menu_return = man_menu();
  }
  }
  else
  printf("\t\t######密碼錯(cuò)誤,請(qǐng)重新登陸!######\n");
 }
 
 else if (status == 1)//student login
 {
  student* p_stu = stu_login(stu_head);
  if (p_stu != NULL)//p_stu為指向該學(xué)生的指針
  {
  printf("\t\t*******請(qǐng)輸入登陸密碼:");
  char input[100];
  scanf("%s", input);
  while (getchar() != '\n');
  if (strcmp(p_stu->password, input) == 0)
  {
   printf("\n\n\t\t-----------------------------%s 歡迎進(jìn)入選課系統(tǒng)! ---------------------------------\n\n", p_stu->name);
   int menu_return = stu_menu();
   while (1)
   {
   switch (menu_return)
   {
   case 1:
    course_showall(cour_head); break;
   case 2:
    search_course(cour_head); break;
   case 3:
    coursechoose(cour_head,p_stu); break;
   case 4:
    stu_dele_cour(cour_head, p_stu); break;
   case 5:
    student_showone(p_stu); break;
   case 6:
    stu_modifyKey(p_stu); break;
   case 0:
    break;
   default:
    printf("\t\t######輸入錯(cuò)誤,請(qǐng)重新輸入!######\n");
   }
 
   if (menu_return == 0)
    break;
   menu_return = stu_menu();
   }
  }
  else
  {
   printf("\t\t#####密碼錯(cuò)誤,請(qǐng)重新登陸!#######\n");
  }
  }
  else
  printf("\t\t#####該學(xué)號(hào)不存在,請(qǐng)重新登陸!######\n");
  p_stu = NULL;
 }
 
 else if (status == 3)//顯示幫助信息
  help();
 
 else if (status == 0)//關(guān)閉系統(tǒng)
  return 0;
 
  while (1)//再次判斷登陸類型
  {
  status = -1;
  printf("\n\n\t\t*****請(qǐng)選擇登陸類型 [1]學(xué)生  [2]管理員  [3]顯示幫助  [0]退出系統(tǒng):");
  status = input_limit0(3);
  if ((status == 0) || (status == 1) || (status == 2) || (status == 3))
   break;
  else
   printf("\n\t\t##### 輸入錯(cuò)誤!只能選擇1、2或0 #######\n");
  }
 }
}

common.cpp

#include<stdio.h>
#include<string.h>
#include"all.h"
#include<stdlib.h>
#include<malloc.h>
#include<ctype.h>
 
extern student* stu_head;
extern course* cour_head;
extern course *cour_tail;
extern student *stu_tail;  // 這四個(gè)指針變量在main.cpp中已經(jīng)聲明為全局變量
 
int keyexam(char *actual_key, char *input_key)//密碼正確則返回1,否則返回0
{
 if (strcmp(actual_key, input_key) == 0)
 return 1;
 else
 return 0;
}
 
student* load_stu()//經(jīng)調(diào)試已經(jīng)正確
{
 int count = 0;
 FILE *fp;
 if ((fp = fopen(STU_F, "r")) == NULL)
 {
 printf("\t\tcannot open the file:STU_F\n");
 exit(0);
 }
 student* temp = (student*)malloc(sizeof(student));
 while (!feof(fp))
 {
 if (fread(temp, sizeof(student), 1, fp))
  count++;
 }
 free(temp);
 temp = NULL;
 
 if (count == 0)
 return NULL;
 else
 {
 rewind(fp);
 student *p_head = NULL;//文件中有鏈表信息,則創(chuàng)建一個(gè)頭指針
 p_head = (student*)malloc(sizeof(student));
 fread(p_head, sizeof(student), 1, fp);//用文件內(nèi)容初始化鏈表節(jié)點(diǎn)
 p_head->next = NULL;
 count--;
 student* p_new = p_head;
 student* p_end = p_head;
 for (int i = 0; i < count; i++)
 {
  p_new = (student*)malloc(sizeof(student));
  fread(p_new, sizeof(student), 1, fp);
  p_new->next = NULL;
  p_end->next = p_new;
  p_end = p_new;
 }
 fclose(fp);
 return p_head;
 }
}
 
void store_stu(student * p_head)//經(jīng)調(diào)試已正確
{
 FILE *fp;
 if ((fp = fopen(STU_F, "w")) == NULL)//以只寫方式打開文件,覆蓋以前數(shù)據(jù)
 {
 printf("\t***STU_F missed,please quit the system and check for that!\n\n");
 exit(0);
 }
 while (p_head != NULL)//將鏈表所有節(jié)點(diǎn)寫入緩沖區(qū)
 {
 fwrite(p_head, sizeof(student), 1, fp);//將鏈表一個(gè)節(jié)點(diǎn)寫入緩沖區(qū)
 p_head = p_head->next;      //p_head指向下一個(gè)節(jié)點(diǎn)
 }
 fclose(fp);//保存文件,清空緩沖區(qū)
}
 
course * load_cour()
{
 int count = 0;
 FILE *fp;
 if ((fp = fopen(COUR_F, "r")) == NULL)
 {
 printf("\t\tcannot open the file:COUR_F\n");
 exit(0);
 }
 course* temp = (course*)malloc(sizeof(course));
 while (!feof(fp))
 {
 if (fread(temp, sizeof(course), 1, fp))
  count++;
 }
 free(temp);
 temp = NULL;
 
 if (count == 0)
 return NULL;
 else
 {
 rewind(fp);
 course *p_head = NULL;//文件中有鏈表信息,則創(chuàng)建一個(gè)頭指針
 p_head = (course*)malloc(sizeof(course));
 fread(p_head, sizeof(course), 1, fp);//用文件內(nèi)容初始化鏈表節(jié)點(diǎn)
 p_head->next = NULL;
 count--;
 course* p_new = p_head;
 course* p_end = p_head;
 for (int i = 0; i < count; i++)
 {
  p_new = (course*)malloc(sizeof(course));
  fread(p_new, sizeof(course), 1, fp);
  p_new->next = NULL;
  p_end->next = p_new;
  p_end = p_new;
 }
 fclose(fp);
 return p_head;
 }
 
}
 
void store_cour(course * p_head)
{
 FILE *fp;
 if ((fp = fopen(COUR_F, "w")) == NULL)//以只寫方式打開文件,覆蓋以前數(shù)據(jù)
 {
 printf("\t***COUR_F missed,please quit the system and check for that!\n\n");
 exit(0);
 }
 while (p_head != NULL)//將鏈表所有節(jié)點(diǎn)寫入緩沖區(qū)
 {
 fwrite(p_head, sizeof(course), 1, fp);//將鏈表一個(gè)節(jié)點(diǎn)寫入緩沖區(qū)
 p_head = p_head->next;      //p_head指向下一個(gè)節(jié)點(diǎn)
 }
 fclose(fp);//保存文件,清空緩沖區(qū)
}
 
student * locate_end(student * head)
{
 student* end = head;
 while (head != NULL)
 {
 end = head;
 head = head->next;
 }
 return end;
}
 
course* locate_end(course * head)
{
 course* end = head;
 while (head != NULL)
 {
 end = head;
 head = head->next;
 }
 return end;
}
 
void help()
{
 int input = -1;
 while (1)
 {
 printf("\n\t\t*****請(qǐng)選擇需要的幫助類型 [1]學(xué)生幫助 [2]管理員幫助 [3]版權(quán)信息 [0]返回主頁:");
 scanf("%d", &input);
 while (getchar() != '\n');
 if (input == 0)
  break;
 else if (input == 1)//學(xué)生使用說明
 {
  printf("\n\t\t--------------------------------學(xué)生使用說明---------------------------------------\n");
  printf("\t\t密碼:初始密碼為學(xué)號(hào),忘記密碼請(qǐng)聯(lián)系管理員\n");
  printf("\t\t\n");
  printf("\t\t\n");
  printf("\t\t\n");
  printf("\t\t-----------------------------------------------------------------------------------\n\n");
 }
 else if (input == 2)//管理員使用說明
 {
  printf("\n\t\t-------------------------------管理員使用說明---------------------------------------\n");
  printf("\t\t密碼:初始密碼為10個(gè)0,首次使用務(wù)必修改密碼!\n");
  printf("\t\t警告:該軟件的文件夾必須放在C盤根目錄下,否則不能使用!\n");
  printf("\t\t提示:請(qǐng)定時(shí)備份數(shù)據(jù),防止數(shù)據(jù)丟失!\n");
  printf("\t\t提示:學(xué)生學(xué)號(hào)和課程編號(hào)只能是數(shù)字!\n");
  printf("\t\t------------------------------------------------------------------------------------\n\n");
 }
 else if (input == 3)//版權(quán)信息
 {
  printf("\n\t\t------------------------------版權(quán)信息-------------------------------------------------\n");
  printf("\t\t軟件名稱:學(xué)生及課程信息管理系統(tǒng)\n");
  printf("\t\t開發(fā)人員:焦智洋、文詩波、韓旭\n");
  printf("\t\t版本:beta1.0\n");
  printf("\t\t版權(quán)保護(hù):版權(quán)所有,翻版必究\n");
  printf("\t\t---------------------------------------------------------------------------------------\n\n");
 }
 else
  printf("\n\t\t#####輸入錯(cuò)誤,請(qǐng)重新輸入!#####\n");
 }
}
 
int link_count(student * head)
{
 int count = 0;
 while (head != NULL)
 {
 count++;
 head = head->next;
 }
 return count;
}
 
int link_count(course * head)
{
 int count = 0;
 while (head != NULL)
 {
 count++;
 head = head->next;
 }
 return count;
}
 
int judge_ascii_num(char in[])
{
 int i = 0;
 while (in[i]!='\0')
 {
 if ((in[i] < '0') || (in[i] > '9'))
  return 0;
 i++;
 }
 return 1;
}
 
int judge_num(char *ch)
{
 int sum = 0, len = strlen(ch);
 for (int i = 0; i < len; i++)
 {
 if (ch[i] >= '0'&&ch[i] <= '9')
  sum++;
 }
 if (sum == len)
 return 1;
 else
 return 0;
}
 
int input_num()
{
 int num;
 char buf[MAXN];
 while ((scanf("%s", buf) == 0) || (judge_num(buf) == 0))
 {
 while (getchar() != '\n');
 printf("\n\t\t###輸入錯(cuò)誤,請(qǐng)重新輸入:");
 }
 num = atoi(buf);
 return num;
}
 
double input_double()
{
 double temp = -1.00;
 while (1)
 {
 scanf("%lf", &temp);
 while (getchar() != '\n');
 if (temp < 0)
  printf("\n\t\t#####輸入錯(cuò)誤,請(qǐng)重新輸入:");
 else
  break;
 }
 return temp;
}
 
double judge_input_dou()
{
 printf("\n\t\t是否修改該項(xiàng)?[1]修改  [0]不修改:");
 int judge = 0;
 scanf("%d", &judge);
 while (getchar() != '\n');
 if (judge == 1)
 {
 while (1)
 {
  printf("\n\t\t請(qǐng)輸入修改后的內(nèi)容:");
  double in = 0.00;
  scanf("%lf", &in);
  while (getchar() != '\n');
  if (in<=0)
  printf("\n\t\t#####輸入錯(cuò)誤,請(qǐng)重新輸入!######");
  else
  {
  return in;
  break;
  }
 }
 }
 else
 return -1.0;
}
 
course *coursenamefind_char(course* head, char tar[])//根據(jù)課程名稱查找課程節(jié)點(diǎn),返回前一節(jié)點(diǎn)地址
{
 course *p, *q;
 p = head;
 q = NULL;
 while (p != NULL)
 {
 if (strcmp(tar, p->name) == 0)
  return q;
 q = p;
 p = p->next;
 }
 return q;
}
 
course *coursenumfind_num(course* head, char tar[])//根據(jù)課程編號(hào)查找課程
{course *p, *q;
 p = head;
 q = NULL;
 while (p != NULL)
 {
 if (strcmp(tar, p->num)==0)
  return q;
 q = p;
 p = p->next;
 }
 return q;
 
}
 
student *studentnamefind_char(student *head, char tar[])
{
 student *p, *q;
 p = head;
 q = NULL;
 while (p != NULL)
 {
 if (strcmp(tar, p->name) == 0)
  return q;
 q = p;
 p = p->next;
 }
 return q;
}
 
student* studentnamefind_num(student *head, char tar[])
{
 student *p, *q;
 p = head;
 q = NULL;
 while (p != NULL)
 {
 if (strcmp(tar, p->num) == 0)
  return q;
 q = p;
 p = p->next;
 }
 return q;
}
 
int input_limit(int n)
{
 int m;
 while (1)
 {
 m = input_num();
 if (m > 0 && m <= n)
  break;
 printf("\n\t\t####無此選項(xiàng),請(qǐng)重新輸入!####\n");
 }
 return m;
}
 
int input_limit0(int n)
{
 int m;
 while (1)
 {
  m = input_num();
  if (m >= 0 && m <= n)
  break;
  printf("\n\t\t####無此選項(xiàng),請(qǐng)重新輸入!####\n");
 }
 return m;
}
 
void student_showone(student *p)
{
 printf("\n\t\t------------------------------------------------------");
 printf("\n\t\t學(xué)號(hào):%s", p->num);
 printf("\n\t\t姓名:%s", p->name);
 printf("\n\t\t學(xué)院與班級(jí):%s", p->sch_cla);
 printf("\n\t\t密碼:%s", p->password);
 if (p->course_sum == 0)
 printf("\n\t\t該學(xué)生無已選課程!\n");
 else
 {
 printf("\n\t\t已選課程:\n");
 for (int i = 0; i < p->course_sum; i++)
  printf("\t\t\t[%d]:%s\n", i + 1, p->course[i]);
 }
 printf("\t\t選課總數(shù):%d", p->course_sum);
 printf("\n\t\t已選課程總學(xué)分:%lf", p->score_sel);
 printf("\n\t\t已得學(xué)分統(tǒng)計(jì):%lf", p->score_all);
 printf("\n\t\t------------------------------------------------------");
}
 
void student_showall(student *head)
{
 student *p;
 p = head;
 while (p != NULL)
 {
 student_showone(p);
 p = p->next;
 }
}
 
void course_showone(course *ad)
{
 if (ad == NULL)
 printf("\t\t無課程\n");
 else
 {
 printf("\n\t\t------------------------------------------------------");
 printf("\n\t\t課程名稱:%s\n", ad->name);
 printf("\n\t\t課程編號(hào):%s\n", ad->num);
 printf("\t\t課程性質(zhì):%s\n", ad->nature);
 printf("\t\t開課學(xué)期:%s\n", ad->term);
 printf("\t\t總學(xué)時(shí):%lf\n", ad->time_all);
 printf("\t\t授課學(xué)時(shí):%lf\n", ad->time_teach);
 printf("\t\t實(shí)驗(yàn)或上機(jī)學(xué)時(shí):%lf\n", ad->time_exp);
 printf("\t\t學(xué)分:%lf\n\n", ad->score);
 printf("\n\t\t------------------------------------------------------");
 }
}
 
void course_showall(course *head)
{
 course *p;
 p = head;
 while (p != NULL)
 {
 course_showone(p);
 p = p->next;
 }
 return;
}
 
void cour_nat_te(course* head)
{
 while (1)
 {
 printf("\n\t\t請(qǐng)輸入要查找課程的性質(zhì),返回上級(jí)菜單請(qǐng)輸入0000:");
 char input1[50];
 scanf("%s", input1);
 while (getchar() != '\n');
 if (strcmp(input1, "0000") == 0)
  break;
 
 printf("\n\t\t請(qǐng)輸入要查找課程的開課學(xué)期:");
 char input2[50];
 scanf("%s", input2);
 while (getchar() != '\n');
 
 int count = 0;
 while (head != NULL)
 {
  if ((strcmp(input1, head->nature) == 0) && (strcmp(input2, head->term) == 0))
  {
  course_showone(head);
  count++;
  }
  head = head->next;
 }
 if (count == 0)
  printf("\n\t\t#####沒有符合查找條件的課程!#####\n");
 }
}
 
void search_course(course *head)
{
 int flag;
 while (true)
 {
 flag = 0;
 printf("\n\t\t請(qǐng)輸入查找條件 [1]課程編號(hào)  [2]課程名稱  [3]課程性質(zhì)\n\t\t[4]開課學(xué)期  [5]課程性質(zhì)與開課學(xué)期  [0]返回上級(jí)菜單:");
 scanf("%d", &flag);
 while (getchar() != '\n');
 switch (flag)
 {
 case(1):coursenumfindtip(head); break;
 case(2):coursenamefindtip(head); break;
 case(3):courseshow_nature(head); break;
 case(4):courseshow_term(head); break;
 case(5):cour_nat_te(head); break;
 case(0):break;
 default:
  printf("\n\t\t#####輸入錯(cuò)誤,請(qǐng)重新輸入!#####");
 }
 if (flag == 0)
  break;
 }
}

manager.cpp

#include<stdio.h>
#include<string.h>
#include"all.h"
#include<stdlib.h>
#include<malloc.h>
#include<ctype.h>
 
extern student* stu_head;
extern course* cour_head;
extern course *cour_tail;
extern student *stu_tail;  // 這四個(gè)指針變量在main.cpp中已經(jīng)聲明為全局變量
 
int man_login()
{
 FILE *fp;
 if ((fp = fopen(MAN_F, "r")) == NULL)
 {
 printf("\t\t#######無法找到文件:MAN_F######\n");
 return -1;
 }
 char key[11];
 fread(key, 10, 1, fp);
 key[10] = '\0';
 fclose(fp);
 char input[1000];
 printf("\t\t*******請(qǐng)輸入管理員密碼:");
 scanf("%s", input);
 while (getchar() != '\n');
 if (strcmp(input, key) == 0)
 return 1;
 else
 return 0;
}
 
int man_menu()
{
 printf("\n\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~管理員菜單~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
 printf("\n\t\t---[1]:添加學(xué)生");
 printf("\n\t\t---[2]:刪除學(xué)生");
 printf("\n\t\t---[3]:修改學(xué)生信息");
 printf("\n\t\t---[4]:查找學(xué)生信息\n");
 printf("\n\t\t---[5]:添加課程");
 printf("\n\t\t---[6]:刪除課程");
 printf("\n\t\t---[7]:修改課程信息");
 printf("\n\t\t---[8]:查找課程信息\n");
 printf("\n\t\t---[9]:打印所有課程/學(xué)生信息");
 printf("\n\t\t---[10]:修改管理員密碼");
 printf("\n\t\t---[11]:數(shù)據(jù)備份與恢復(fù)");
 printf("\n\t\t---[0]:注銷\n");
 printf("\n\t\t----請(qǐng)從<0-10>中選擇操作類型:");
 int n = input_limit0(11);
 return n;
}
 
void student_add(student *head) //增加學(xué)生的函數(shù)
{
 while (1)
 {
 char input[50];
 while (1)
 {
  printf("\n\t\t請(qǐng)輸入要添加學(xué)生的學(xué)號(hào)(數(shù)字),返回上級(jí)菜單請(qǐng)輸入0000:");
  scanf("%s", input);
  while (getchar() != '\n');
  if (judge_ascii_num(input) == 1)
  break;
  else
  printf("\n\t\t####輸入錯(cuò)誤!#####");
 }
 if (strcmp(input, "0000") == 0)
  break;
 if (studentnamefind_num(stu_head, input) != stu_tail)
 {
  printf("\t\t###已存在該學(xué)生,請(qǐng)重新輸入!####\n");
  continue;
 }
 
 /*初始化學(xué)生信息*/
 student* p = (student *)malloc(sizeof(student));
 strcpy(p->num, input);
 printf("\t\t請(qǐng)輸入學(xué)生姓名:");
 scanf("%s", p->name);
 while (getchar() != '\n');
 printf("\t\t請(qǐng)輸入學(xué)生學(xué)院和班級(jí)(用--隔開):");
 scanf("%s", p->sch_cla);
 while (getchar() != '\n');
 printf("\t\t請(qǐng)輸入當(dāng)前該學(xué)生總學(xué)分:");
 p->score_all = input_double();
 p->course_sum = 0;
 p->score_sel = 0.0;
 strcpy(p->password, p->num);
 
 if (stu_head == NULL)//當(dāng)前鏈表中沒有節(jié)點(diǎn)
 {
  p->next = NULL;
  stu_head = p;
  stu_tail = p;
 }
 else
 {
  if (strcmp(p->num, stu_head->num) < 0)//新增節(jié)點(diǎn)的標(biāo)號(hào)比頭節(jié)點(diǎn)還小
  {
  p->next = stu_head;
  stu_head = p;
  }
  else if (strcmp(p->num, stu_tail->num) > 0)//新增節(jié)點(diǎn)的標(biāo)號(hào)比尾節(jié)點(diǎn)還大
  {
  p->next = NULL;
  stu_tail->next = p;
  stu_tail = p;
  }
  else//新增節(jié)點(diǎn)的標(biāo)號(hào)在頭節(jié)點(diǎn)和尾節(jié)點(diǎn)之間
  {
  student* temp = stu_head;
  while (temp != stu_tail)
  {
   if (strcmp(p->num, temp->num) > 0)
   {
   p->next = temp->next;
   temp->next = p;
   break;
   }
  }
  }
 }
 printf("\n\t\t學(xué)生信息錄入成功!\n");
 }
 
 store_stu(stu_head);
}
 
void student_delete(student *head)
{
 while (true)
 {
 printf("\n\t\t請(qǐng)輸入要?jiǎng)h除學(xué)生的學(xué)號(hào)或姓名,取消刪除請(qǐng)輸入0000:");
 char input[50];
 scanf("%s", input);
 while (getchar() != '\n');
 if (strcmp(input, "0000") == 0)
  break;
 
 student *p;
 if ((input[0] >= 48) && (input[0] <= 57))
  p = studentnamefind_num(stu_head, input);
 else
  p = studentnamefind_char(stu_head, input);
 
 if (p == stu_tail)//沒有該學(xué)生
 {
  printf("\n\t\t####沒有該學(xué)生信息!#####");
  continue;
 }
 
 printf("\n\t\t確定刪除%s?[1]是 [0]否:", input);
 int in = 0;
 scanf("%d", &in);
 while (getchar() != '\n');
 if (in == 1)
 {
  if (p == NULL)//鏈表頭節(jié)點(diǎn)
  {
  if (stu_head->next == NULL)
  {
   stu_tail = NULL;
  }
  student* temp = stu_head;
  stu_head = stu_head->next;
  free(temp);
  temp = NULL;
  }
  else if (p->next == stu_tail)//鏈表尾節(jié)點(diǎn)
  {
  p->next = NULL;
  free(stu_tail);
  stu_tail = p;
  }
  else//鏈表中間節(jié)點(diǎn)
  {
  student* delete_point = p->next;
  p->next = delete_point->next;
  free(delete_point);
  delete_point = NULL;
  }
  printf("\n\t\t已經(jīng)刪除該學(xué)生的信息!\n");
 }
 else
  printf("\n\t\t####未刪除該學(xué)生的信息!####\n");
 }
 
 store_stu(stu_head);
}
 
void student_modify(student *head)
{
 char input[100];
 student* find = NULL;
 while (1)
 {
 printf("\t\t請(qǐng)輸入要修改學(xué)生的學(xué)號(hào)或姓名,取消修改請(qǐng)輸入0000:");
 scanf("%s", input);
 while (getchar() != '\n');
 if (strcmp(input, "0000") == 0)
  break;
 if ((input[0] >= 48) && (input[0] <= 57))//按學(xué)號(hào)查找
  find = studentnamefind_num(head, input);
 else//按姓名查找
  find = studentnamefind_char(head, input);
 if (find == stu_tail)
 {
  printf("\n\t\t####你所查找的學(xué)生不存在!");
  continue;
 }
 else
 {
  char temp[50];
  if (find == NULL)
  find = head;
  else
  find = find->next;
  printf("\n\t\t請(qǐng)分別輸入需要修改的內(nèi)容,若某一項(xiàng)不需要修改請(qǐng)輸入0");
 
  printf("\n\t\t原姓名:%s  修改后的姓名:", find->name);
  scanf("%s", &temp);
  while (getchar() != '\n');
  if (strcmp(temp, "0") != 0)
  strcpy(find->name, temp);
 
  printf("\t\t原學(xué)院和班級(jí):%s  修改后的學(xué)院和班級(jí)(中間用--隔開):", find->sch_cla);
  scanf("%s", &temp);
  while (getchar() != '\n');
  if (strcmp(temp, "0") != 0)
  strcpy(find->sch_cla, temp);
 
  printf("\t\t原密碼:%s  修改后的密碼:", find->password);
  scanf("%s", &temp);
  while (getchar() != '\n');
  if (strcmp(temp, "0") != 0)
  strcpy(find->password, temp);
 
  printf("\t\t原總學(xué)分:%lf  (增加學(xué)分請(qǐng)使用+,減少學(xué)分請(qǐng)使用-,例如“-10” “+10”):", find->score_all);
  scanf("%s", &temp);
  while (getchar() != '\n');
  if (strcmp(temp, "0") != 0)
  {
  int change = (int)temp[0];
  temp[0] = '0';
  double number = atof(temp);
  if (change == 43)
   find->score_all += number;
  else if (change == 45)
   find->score_all -= number;
  }
 
  printf("\t\t修改完成!\n\n");
 }
 }
 
 store_stu(stu_head);
}
 
void course_add(course *head)
{
 while (1)
 {
 char input[50];
 while (1)
 {
  printf("\n\t\t請(qǐng)輸入要添加課程的編號(hào),返回上一級(jí)菜單請(qǐng)輸入0000:");
  scanf("%s", input);
  while (getchar() != '\n');
  if (judge_ascii_num(input) == 1)
  break;
  else
  printf("\n\t\t#####輸入錯(cuò)誤!####");
 }
 if (strcmp(input, "0000") == 0)
  break;
 
 if (coursenumfind_num(cour_head, input) != cour_tail)
 {
  printf("\t\t###已存在該課程,請(qǐng)重新輸入!####\n");
  continue;
 }
 
 course* p = (course*)malloc(sizeof(course));
 /*初始化課程信息*/
 strcpy(p->num, input);
 printf("\n\t\t請(qǐng)輸入課程名稱:");
 scanf("%s", p->name);
 while (getchar() != '\n');
 printf("\n\t\t請(qǐng)輸入課程性質(zhì):");
 scanf("%s", p->nature);
 while (getchar() != '\n');
 printf("\n\t\t請(qǐng)輸入課程總學(xué)時(shí):");
 p->time_all = input_double();
 printf("\n\t\t請(qǐng)輸入課程授課學(xué)時(shí):");
 p->time_teach = input_double();
 printf("\n\t\t請(qǐng)輸入課程實(shí)驗(yàn)或上機(jī)學(xué)時(shí):");
 p->time_exp = input_double();
 printf("\n\t\t請(qǐng)輸入課程最大容納人數(shù):");
 p->stu_max = input_num();
 printf("\n\t\t請(qǐng)輸入課程學(xué)分:");
 p->score = input_double();
 printf("\n\t\t請(qǐng)輸入課程開課學(xué)期:");
 scanf("%s", p->term);
 while (getchar() != '\n');
 p->stu_sum = 0;
 
 if (cour_head == NULL)//鏈表中沒有節(jié)點(diǎn)
 {
  p->next = NULL;
  cour_head = p;
  cour_tail = p;
 }
 else
 {
  if (strcmp(p->num, cour_head->num) < 0)//新增節(jié)點(diǎn)的標(biāo)號(hào)比頭節(jié)點(diǎn)還小
  {
  p->next = cour_head;
  cour_head = p;
  }
  else if (strcmp(p->num, cour_tail->num) > 0)//新增節(jié)點(diǎn)的標(biāo)號(hào)比尾節(jié)點(diǎn)還大
  {
  p->next = NULL;
  cour_tail->next = p;
  cour_tail = p;
  }
  else//新增節(jié)點(diǎn)的標(biāo)號(hào)在頭節(jié)點(diǎn)和尾節(jié)點(diǎn)之間
  {
  course* temp = cour_head;
  while (temp != cour_tail)
  {
   if (strcmp(p->num, temp->num) > 0)
   {
   p->next = temp->next;
   temp->next = p;
   break;
   }
  }
  }
 }
 printf("\n\t\t課程信息錄入成功!\n");
 }
 store_cour(cour_head);
}
 
void course_delete(course *head)
{
 course *p;
 char input[50];
 while (true)
 {
 printf("\n\t\t請(qǐng)輸入要?jiǎng)h除課程的編號(hào)或名稱,取消刪除請(qǐng)輸入0000:");
 scanf("%s", input);
 while (getchar() != '\n');
 if (strcmp(input, "0000") == 0)
  break;
 if ((input[0] >= 48) && (input[0] <= 57))
  p = coursenumfind_num(head, input);
 else
  p = coursenamefind_char(head, input);
 
 if (p == cour_tail)//沒有該課程
 {
  printf("\n\t\t####沒有該課程信息!####"); continue;
 }
 
 printf("\n\t\t確定刪除%s?[1]是 [0]否:", input);
 int in = 0;
 scanf("%d", &in);
 while (getchar() != '\n');
 if (in == 1)
 {
  if (p == NULL)//鏈表頭節(jié)點(diǎn)
  {
  if (head->next == NULL)
   cour_tail = NULL;
  course* temp = head;
  head = head->next;
  cour_head = head;
  free(temp);
  }
  else if (p->next == cour_tail)//鏈表尾節(jié)點(diǎn)
  {
  free(cour_tail);
  p->next = NULL;
  cour_tail = p;
  }
  else//鏈表中間節(jié)點(diǎn)
  {
  course* delete_point = p->next;
  p = (p->next)->next;
  free(delete_point);
  }
  printf("\n\t\t%s已經(jīng)刪除!\n", input);
 }
 else
  printf("\n\t\t#####未刪除課程%s的信息!######\n", input);
 }
 store_cour(cour_head);
}
 
void course_modify(course *head)
{
 char input[100];
 course* find = NULL;
 while (1)
 {
 printf("\t\t請(qǐng)輸入要修改課程的編號(hào)號(hào)或名稱,取消修改請(qǐng)輸入0000:");
 scanf("%s", input);
 while (getchar() != '\n');
 if (strcmp(input, "0000") == 0)
  break;
 if ((input[0] >= 48) && (input[0] <= 57))//按學(xué)號(hào)查找
  find = coursenumfind_num(head, input);
 else//按姓名查找
  find = coursenamefind_char(head, input);
 if (find == cour_tail)
 {
  printf("\n\t\t####你所查找的課程不存在!####");
  continue;
 }
 else
 {
  char temp[50];
  if (find == NULL)
  find = head;
  else
  find = find->next;
  printf("\n\t\t請(qǐng)分別輸入需要修改的內(nèi)容,若某一項(xiàng)不需要修改請(qǐng)輸入0");
 
  printf("\n\t\t原名稱:%s     修改后的名稱:", find->name);
  scanf("%s", &temp);
  while (getchar() != '\n');
  if (strcmp(temp, "0") != 0)
  strcpy(find->name, temp);
 
  printf("\t\t原性質(zhì):%s     修改后的性質(zhì):", find->nature);
  scanf("%s", &temp);
  while (getchar() != '\n');
  if (strcmp(temp, "0") != 0)
  strcpy(find->nature, temp);
 
  printf("\t\t原開課學(xué)期:%s     修改后的開課學(xué)期:", find->term);
  scanf("%s", &temp);
  while (getchar() != '\n');
  if (strcmp(temp, "0") != 0)
  strcpy(find->term, temp);
 
  //int time_all;    //總學(xué)時(shí)
  //int time_teach;   //授課學(xué)時(shí)
  //int time_exp;   //實(shí)驗(yàn)或上機(jī)學(xué)時(shí)
  //int score;    //該課程學(xué)分
  //int stu_max;   //能夠容納的學(xué)生總數(shù)
 
  printf("\t\t原總學(xué)時(shí):%lf     修改后的總學(xué)時(shí):", find->time_all);
  scanf("%s", &temp);
  while (getchar() != '\n');
  if (strcmp(temp, "0") != 0)
  find->time_all = atof(temp);
 
  printf("\t\t原授課學(xué)時(shí):%lf     修改后的授課學(xué)時(shí):", find->time_teach);
  scanf("%s", &temp);
  while (getchar() != '\n');
  if (strcmp(temp, "0") != 0)
  find->time_teach = atof(temp);
 
  printf("\t\t原實(shí)驗(yàn)或上機(jī)學(xué)時(shí):%lf     修改后的實(shí)驗(yàn)或上機(jī)學(xué)時(shí):", find->time_exp);
  scanf("%s", &temp);
  while (getchar() != '\n');
  if (strcmp(temp, "0") != 0)
  find->time_exp = atof(temp);
 
  printf("\t\t原課程學(xué)分:%lf     修改后的課程學(xué)分:", find->score);
  scanf("%s", &temp);
  while (getchar() != '\n');
  if (strcmp(temp, "0") != 0)
  find->score = atof(temp);
 
  printf("\t\t原能容納學(xué)生總數(shù):%d     修改后的能容納學(xué)生總數(shù):", find->stu_max);
  scanf("%s", &temp);
  while (getchar() != '\n');
  if (strcmp(temp, "0") != 0)
  find->stu_max = atoi(temp);
 
  printf("\t\t修改完成!\n\n");
 }
 }
 
 store_cour(cour_head);
}
 
void print_all()
{
 while (1)
 {
 printf("\n\t\t選擇操作類型: [1]打印所有學(xué)生信息  [2]打印所有課程信息 [0]返回主菜單:");
 int input = 0;
 scanf("%d", &input);
 while (getchar() != '\n');
 if (input == 1)
 {
  printf("\n\t\t學(xué)生總數(shù):%d", link_count(stu_head));
  student_showall(stu_head);
 }
 else if (input == 2)
 {
  printf("\n\t\t課程總數(shù):%d\n", link_count(cour_head));
  courseshowall_man(cour_head);
 }
 else if (input == 0)
  break;
 else
  printf("\n\t\t####輸入錯(cuò)誤!請(qǐng)重新輸入!#####\n");
 }
}
 
void man_modifyKey()
{
 printf("\t\t******請(qǐng)輸入原密碼(10位):");
 char input[20];
 scanf("%s", input);
 while (getchar() != '\n');
 
 FILE *fp;
 if ((fp = fopen(MAN_F, "r")) == NULL)
 {
 printf("\t\t-------- 無法打開文件:MAN_F\n");
 exit(0);
 }
 char keyOld[11];
 fread(keyOld, 10, 1, fp);
 keyOld[10] = '\0';
 if (strcmp(keyOld, input) == 0)//修改
 {
 fclose(fp);
 char new1[100];
 char new2[100];
 while (1)
 {
  printf("\t\t*******請(qǐng)輸入新密碼(10位):");
  scanf("%s", new1);
  while (getchar() != '\n');
  printf("\t\t******請(qǐng)?jiān)俅未_認(rèn)新密碼(10位):");
  scanf("%s", new2);
  while (getchar() != '\n');
  if (keyexam(new1, new2) == 1)
  {
  fp = fopen(MAN_F, "w");
  fwrite(new1, 10, 1, fp);
  fclose(fp);
  printf("\n\t\t------密碼修改成功!\n");
  break;
  }
  else
  printf("\t\t####前后密碼不一致,請(qǐng)重新輸入!####\n");
 }
 }
 else
 {
 fclose(fp);
 printf("\t\t####原密碼輸入錯(cuò)誤,請(qǐng)重新選擇操作類型####\n");
 }
}
 
void man_backups_recover()
{
 printf("\t\t*****[1]數(shù)據(jù)備份 [2]數(shù)據(jù)恢復(fù) [3]取消\n");
 printf("\t\t*****選擇操作類型:");
 int input = 0;
 scanf("%d", &input);
 while (getchar() != '\n');
 if (input == 1)
 {
 FILE *fp_source;
 FILE *fp_destination;
 {//課程信息備份
  if ((fp_source = fopen(COUR_F, "r")) == NULL)
  {
  printf("\t\t##課程數(shù)據(jù)備份失敗:無法找到COUR_F文件!##\n");
  exit(0);
  }
  fp_destination = fopen(COUR_F_BACKUP, "w");
  char temp;
  int count = 0;
  while (!feof(fp_source))
  {
  if (fread(&temp, 1, 1, fp_source))
   count++;
  }
  rewind(fp_source);
  for (int i = 0; i < count; i++)
  {
  fread(&temp, 1, 1, fp_source);
  fwrite(&temp, 1, 1, fp_destination);
  }
  fclose(fp_destination);
  fclose(fp_source);
 }
 {//學(xué)生信息備份
  if ((fp_source = fopen(STU_F, "r")) == NULL)
  {
  printf("\t\t##學(xué)生數(shù)據(jù)備份失?。簾o法找到STU_F文件!##\n");
  exit(0);
  }
  fp_destination = fopen(STU_F_BACKUP, "w");
  char temp;
  int count = 0;
  while (!feof(fp_source))
  {
  if (fread(&temp, 1, 1, fp_source))
   count++;
  }
  rewind(fp_source);
  for (int i = 0; i < count; i++)
  {
  fread(&temp, 1, 1, fp_source);
  fwrite(&temp, 1, 1, fp_destination);
  }
  fclose(fp_destination);
  fclose(fp_source);
 }
 {//管理員信息備份
  if ((fp_source = fopen(MAN_F, "r")) == NULL)
  {
  printf("\t\t##管理員數(shù)據(jù)備份失敗:無法找到MAN_F文件!##\n");
  exit(0);
  }
  fp_destination = fopen(MAN_F_BACKUP, "w");
  char temp;
  for (int i = 0; i < 10; i++)
  {
  fread(&temp, 1, 1, fp_source);
  fwrite(&temp, 1, 1, fp_destination);
  }
  fclose(fp_destination);
  fclose(fp_source);
 }
 printf("\n\t\t所有數(shù)據(jù)已經(jīng)備份完畢!備份目錄為C:\ stu_cour_info_system\backup\n");
 }
 else if (input == 2)
 {
 printf("\t\t選擇恢復(fù)類型:[1]課程數(shù)據(jù)  [2]學(xué)生數(shù)據(jù) [3]管理員數(shù)據(jù):");
 int in = 0;
 scanf("%d", &in);
 while (getchar() != '\n');
 FILE *fp_source;
 FILE *fp_destination;
 if (in == 1)//course information recover
 {  //課程信息恢復(fù)
  if ((fp_source = fopen(COUR_F_BACKUP, "r")) == NULL)
  {
  printf("\t\t###課程信息恢復(fù)失??!未能找到C:\\stu_cour_info_system\\backup\\course_back.txt###\n");
  exit(0);
  }
  fp_destination = fopen(COUR_F, "w");
  char temp;
  int count = 0;
  while (!feof(fp_source))
  {
  if (fread(&temp, 1, 1, fp_source))
   count++;
  }
  rewind(fp_source);
  for (int i = 0; i < count; i++)
  {
  fread(&temp, 1, 1, fp_source);
  fwrite(&temp, 1, 1, fp_destination);
  }
  fclose(fp_destination);
  fclose(fp_source);
  printf("\n\t\t課程信息恢復(fù)成功!\n");
  cour_head = load_cour();
  cour_tail = locate_end(cour_head);
 }
 else if (in == 2)//student information recover
 { //學(xué)生信息恢復(fù)
  if ((fp_source = fopen(STU_F_BACKUP, "r")) == NULL)
  {
  printf("\t\t###學(xué)生信息恢復(fù)失??!未能找到C:\\stu_cour_info_system\\backup\\student_back!###\n");
  exit(0);
  }
  fp_destination = fopen(STU_F, "w");
  char temp;
  int count = 0;
  while (!feof(fp_source))
  {
  if (fread(&temp, 1, 1, fp_source))
   count++;
  }
  rewind(fp_source);
  for (int i = 0; i < count; i++)
  {
  fread(&temp, 1, 1, fp_source);
  fwrite(&temp, 1, 1, fp_destination);
  }
  fclose(fp_destination);
  fclose(fp_source);
  printf("\n\t\t學(xué)生數(shù)據(jù)恢復(fù)成功!\n");
  stu_head = load_stu();
  stu_tail = locate_end(stu_head);
 }
 else if (in == 3)//manager information recover
 {
  //恢復(fù)管理員數(shù)據(jù)
  if ((fp_source = fopen(MAN_F_BACKUP, "r")) == NULL)
  {
  printf("\t\t###管理員數(shù)據(jù)恢復(fù)失??!未能找到C:\\stu_cour_info_system\\backup\\course_back\n");
  exit(0);
  }
  fp_destination = fopen(MAN_F, "w");
  char temp;
  for (int i = 0; i < 10; i++)
  {
  fread(&temp, 1, 1, fp_source);
  fwrite(&temp, 1, 1, fp_destination);
  }
  fclose(fp_destination);
  fclose(fp_source);
  printf("\n\t\t管理員數(shù)據(jù)恢復(fù)成功!\n");
 }
 else
  printf("\t\t###輸入錯(cuò)誤!###\n");
 }
 else if (input == 3)
 ;
 else
 printf("\t\t###輸入錯(cuò)誤,請(qǐng)重新輸入!####\n");
}
 
void man_search_stu(student *head)
{
 while (1)
 {
 printf("\n\t\t請(qǐng)輸入學(xué)號(hào)或姓名進(jìn)行查找,返回上級(jí)菜單請(qǐng)輸入0000:");
 char input[50];
 scanf("%s", input);
 while (getchar() != '\n');
 if (strcmp(input, "0000") == 0)
  break;
 
 student* p_stu;
 if ((input[0] >= 48) && (input[0] <= 57))
  p_stu = studentnamefind_num(head, input);
 else
  p_stu = studentnamefind_char(head, input);
 
 if (p_stu == stu_tail)
 {
  printf("\n\t\t#####沒有該學(xué)生的信息,請(qǐng)重新輸入!#####/n");
  continue;
 }
 
 if (p_stu == NULL)
  p_stu = head;
 else
  p_stu = p_stu->next;
 
 printf("\n\t\t該學(xué)生信息如下:");
 student_showone(p_stu);
 }
}
 
void courseshowone_man(course *ad)
{
 if (ad == NULL)
 printf("無課程");
 else
 {
 printf("\n\t\t------------------------------------------------------");
 printf("\n\t\t課程編號(hào):%s\n", ad->num);
 printf("\t\t課程名稱:%s\n", ad->name);
 printf("\t\t課程性質(zhì):%s\n", ad->nature);
 printf("\t\t開課學(xué)期:%s\n", ad->term);
 printf("\t\t總學(xué)時(shí):%lf\n", ad->time_all);
 printf("\t\t授課學(xué)時(shí):%lf\n", ad->time_teach);
 printf("\t\t實(shí)驗(yàn)或上機(jī)學(xué)時(shí):%lf\n", ad->time_exp);
 printf("\t\t學(xué)分:%lf\n", ad->score);
 printf("\t\t總?cè)菁{學(xué)生人數(shù):%d\n", ad->stu_max);
 printf("\t\t已選學(xué)生人數(shù):%d\n", ad->stu_sum);
 printf("\t\t已選學(xué)生:\n");
 if (ad->stu_sum == 0)
  printf("\t\t沒有人選該課程\n");
 else
  for (int i = 0; i <ad->stu_sum; i++)
  {
  if (i % 5 == 0)
   printf("\t\t");
  student* temp = studentnamefind_num(stu_head, ad->stu[i]);
  if (temp == NULL)
   temp = stu_head;
  else
   temp = temp->next;
  printf("[%d] %s", i + 1, temp->name);
  if (i > 0 && i % 5 == 0)
   printf("\n");
  }
 printf("\n\t\t------------------------------------------------------");
 }
}
 
void courseshowall_man(course *head)
{
 
 course *p;
 p = head;
 if (p == NULL)
 {
 printf("\t\t無課程\n");
 return;
 }
 while (p != NULL)
 {
 courseshowone_man(p);
 p = p->next;
 }
}

studetn.cpp

#include<stdio.h>
#include<string.h>
#include"all.h"
#include<stdlib.h>
#include<malloc.h>
#include<ctype.h>
 
extern student* stu_head;
extern course* cour_head;
extern course *cour_tail; 
extern student *stu_tail;// 這四個(gè)指針變量在main.cpp中已經(jīng)聲明為全局變量
 
student* stu_login(student* head)
{
 student* copy_head = head;
 char input[100];
 printf("\t\t*******請(qǐng)輸入學(xué)號(hào):");
 scanf("%s", input);
 while (getchar() != '\n');
 student* temp;
 temp = studentnamefind_num(head, input);
 if (temp == NULL)//the first student
 return copy_head;
 else if ((temp != NULL) && (temp->next == NULL))//no such a student
 return NULL;
 else
 return temp->next;
}
 
int stu_menu()
{
 printf("\n\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~學(xué)生菜單~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
 printf("\n\t\t---[1]:打印課程信息");
 printf("\n\t\t---[2]:查找課程信息");
 printf("\n\t\t---[3]:選擇新的課程");
 printf("\n\t\t---[4]:刪除已選課程");
 printf("\n\t\t---[5]:查看個(gè)人信息");
 printf("\n\t\t---[6]:修改登陸密碼");
 printf("\n\t\t---[0]:注銷");
 printf("\n\n\t\t---請(qǐng)從<0-6>中選擇操作類型:");
 int n = input_limit0(6);
 return n;
}
 
void courseshow_nature(course *head)
{
 
 course *p;
 char ad[MAXN];
 while (true)
 {
 int flag = 0, sum = 0;
 p = head;
 printf("\t\t請(qǐng)輸入要查找課程的性質(zhì),取消查找請(qǐng)輸入0000:");
 scanf("%s", ad);
 while (getchar() != '\n');
 if (strcmp(ad, "0000") == 0)
  break;
 while (p != NULL)
 {
  if (strcmp(ad, p->nature) == 0)
  {
  course_showone(p);
  flag = 1;
  sum++;
  }
  p = p->next;
 }
 if (flag == 0)
  printf("\n\t\t沒有該課程!####");
 }
 return;
}
 
void courseshow_term(course *head)
{
 
 course *p;
 char ad[MAXN];
 while (true)
 {
 int flag = 0, sum = 0;
 p = head;
 printf("\t\t請(qǐng)輸入要查找課程的開課學(xué)期,取消查找請(qǐng)輸入0000:");
 scanf("%s", ad);
 while (getchar() != '\n');
 if (strcmp(ad, "0000") == 0)
  break;
 while (p != NULL)
 {
  if (strcmp(ad, p->term) == 0)
  {
  course_showone(p);
  flag = 1;
  sum++;
  }
  p = p->next;
 }
 if (flag == 0)
  printf("\n\t\t#####沒有該課程!#####");
 }
 return;
}
 
void coursechoose( course* head, student* stu)//選課函數(shù)
{
 if (stu->score_sel <stu->score_all )
 printf("\n\t\t你的總學(xué)分少于%lf,趕快去選課吧!\n", stu->score_all);
 while (1)
 {
 printf("\n\t\t請(qǐng)輸入課程的編號(hào)或名稱進(jìn)行選課,取消選課請(qǐng)輸入0000:");
 char input[50];
 scanf("%s", input);
 while(getchar()!='\n');
 if (strcmp(input, "0000")==0)
  break;
 course* find = NULL;
 if ((input[0] >= 48) && (input[0] <= 57))
  find = coursenumfind_num(head, input);
 else
  find = coursenamefind_char(head, input);
 
 if (find == cour_tail)
 {
  printf("\n\t\t#####該課程不存在!請(qǐng)重新輸入#####\n");
  continue;
 }
 else if (find == NULL)
  find = head;
 else
  find = find->next;
 
 if (find->stu_sum == find->stu_max)
  printf("\n\t\t####該課程人數(shù)已滿,無法選擇!#####\n");
 else
 {
  int judge = 0;
  for (int i = 0; i < stu->course_sum; i++)
  {
  if (strcmp(stu->course[i], find->num)==0)
  {judge = 1; break;}
  }
  if (judge == 1)
  {
  printf("\n\t\t####該課程已經(jīng)選擇過了!####\n");
  continue;
  }
  else
  {
  stu->course_sum++;
  strcpy(stu->course[stu->course_sum - 1], find->num);
  stu->score_sel += find->score;
 
  find->stu_sum++;
  strcpy(find->stu[find->stu_sum - 1], stu->num);
  printf("\n\t\t該課程選擇成功!\n");
  }
 }
 
 }
 
 store_cour(cour_head);
 store_stu(stu_head);
}
 
void coursenumfindtip(course *head)
{
 char buf[MAXN];
 course *result;
 while (true)
 {
 
 printf("\t\t請(qǐng)輸入要查找課程的編號(hào),取消查找請(qǐng)輸入0000:");
 scanf("%s", buf);
 while (getchar() != '\n');
 if (strcmp(buf, "0000") == 0)
  break;
 result = coursenumfind_num(head, buf);
 if (result != cour_tail)
 {
  if (result == NULL)
  result = head;
  else
  result = result->next;
  course_showone(result);
 }
 else
  printf("\t\t#####沒有該課程!#####\n");
 }
}
 
void coursenamefindtip(course *head)
{
 char buf[MAXN];
 course *result;
 while (1)
 {
 printf("\t\t請(qǐng)輸入要查找課程的名稱,取消查找請(qǐng)輸入0000:");
 scanf("%s", buf);
 while (getchar() != '\n');
 if (strcmp(buf, "0000") == 0)
  break;
 result = coursenamefind_char(head, buf);
 if (result != cour_tail)
 {
  if (result == NULL)
  result = head;
  else
  result = result->next;
  course_showone(result);
 }
 else
  printf("\t\t#####無所查找的課程!#####\n");
 }
}
 
void stu_dele_cour( course * head, student * stu)
{
 while (1)
 {
 printf("\n\t\t請(qǐng)輸入需要?jiǎng)h除課程的編號(hào),返回上級(jí)菜單請(qǐng)輸入0000:");
 char input[50];
 scanf("%s", input);
 while (getchar() != '\n');
 if (strcmp(input, "0000") == 0)
  break;
 int i = 0, result = -1;
 
 /*刪除該學(xué)生記錄中選課的信息*/
 for (; i < stu->course_sum; i++)
 {
  if (strcmp(input, stu->course[i]) == 0)
  { result = i; break; }
 }
 if (result == -1)
  {printf("\n\t\t####你沒有選擇這門課程!請(qǐng)重新輸入!");continue;}
 strcpy(stu->course[result], stu->course[stu->course_sum - 1]);
 stu->course_sum--;   
 
 course* find= coursenumfind_num(head, input);
 if (find == NULL)
  find = head;
 else
  find =find->next;
 
 /*刪除該課程記錄中學(xué)生的信息*/
 i = 0, result = 0;
 for (; i < find->stu_sum; i++)
 {
  if(strcmp(input,find->stu[i])==0)
  { result = i; break;}
 }
 strcpy(find->stu[result], find->stu[find->stu_sum - 1]);
 find->stu_sum --;                            
 
 printf("\n\t\t課程刪除成功!\n");
 }
 
 store_stu(stu_head);
 store_cour(cour_head);
}
 
void stu_modifyKey(student* stu)
{
 printf("\t\t******請(qǐng)輸入原密碼(8位):");
 char input[20];
 scanf("%s", input);
 while (getchar() != '\n');
 
 char keyOld[10];
 strcpy(keyOld, stu->password);
 if (keyexam(keyOld, input) == 1)//修改
 {
 char new1[100];
 char new2[100];
 while (1)
 {
  printf("\t\t*******請(qǐng)輸入新密碼(8位):");
  scanf("%s", new1);
  while (getchar() != '\n');
  printf("\t\t******請(qǐng)?jiān)俅未_認(rèn)新密碼(8位):");
  scanf("%s", new2);
  while (getchar() != '\n');
  if (keyexam(new1, new2) == 1)
  {
  strcpy(stu->password, new1);
  store_stu(stu_head);
  printf("\n\t\t------密碼修改成功!\n");
  break;
  }
  else
  printf("\t\t####前后密碼不一致,請(qǐng)重新輸入!####\n");
 }
 }
 else
 printf("\t\t####原密碼輸入錯(cuò)誤,請(qǐng)重新選擇操作類型####\n");
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI