校園運動會報名系統
阿新 • • 發佈:2019-01-07
main.cpp #include "Campus.h" #include "List.h" /*校園運功會報名系統 實現報名資訊錄入 和 展示 */ /* 資訊錄入 1 . 建立運動會專案資訊表 , 欄位包括 , 專案編號 , 專案名稱 , 學生姓名 ,院系 ,班級 ,性別 年齡,參賽時間 ,報名時間 ; 2 完成運動會報名資訊新增頁 , 3 查詢報名 情況 4管理員系統可以更改報名截止時間 和 運動員的可想更改 (可以改成英文版和中文版切換) */ int main() { ShowPage(); return 0; }
Campush.h #ifndef CAMPUS_H #define CAMPUS_H #include "List.h" void ShowPage(); void MenuChoose(); // 主選單 void Apply_System();// 報名系統 void Show_Apply_System(); // 報名系統頁面 void Apply_Information_Query();// 資訊查詢 void show_in_AdSYstem();// 管理員展示頁面 void Administrator_System();// 管理員系統; void Athlete_Information(); // 運動員資訊查詢 void Sport_item_sign(); // 運動專案報名 void printList_new(Message &M); // 列印帶有專案的資訊 bool Judge_IF_sign(char *) ; // 判斷學生是否報名專案 void Point_Base_Me(char *Temp); // 列印運動員資訊 void AD_Menu(); // 管理員系統選單 void Manage_system();// 管理員系統 void Log_Administrator(); void AD_Menu2(); void Cancel_signup(); void Revise_Data(); void Enter_Adsystem(); // 管理員登入 bool Judge_IF_Past_due();// 判斷是否逾期; extern void Go_back1(); // 返回第一頁 extern void Go_back2(); // 返回第二頁; extern void Go_back3(); extern void Go_back4(); #endif // CAMPUS_H
List.cpp #include "List.h" #include "Campus.h" #include <iostream> #include <cstdio> #include <cstdlib> #include <windows.h> #include <io.h> using namespace std ; void Gettime_f(int &year ,int &month ,int &day ,int &hours ,int &minutes ,int &second ) { /*獲取本地時間 */ time_t now ; struct tm *tm_now ; time(&now) ; tm_now = localtime(&now) ; year = tm_now->tm_year+1900 ; month = tm_now->tm_mon+1 ; day = tm_now->tm_mday ; hours = tm_now->tm_hour ; minutes = tm_now->tm_min ; second = tm_now->tm_sec ; return ; } Status List::CreatList(LinkList &L,int n) { // 建立連結串列; int i ; time_t now ; struct tm *tm_now ; time(&now) ; tm_now = localtime(&now) ; LinkList p ; LinkList head =NULL ; LinkList Last ; for(i=0 ; i<n ;i++) { system("cls"); cout<<"請輸入第 " <<i+1<<"名學生資訊 : "<<endl; p = (LinkList )malloc(sizeof(LNode)) ; if(p==NULL) { cout<<"CreatList fail "<<endl; exit(ERROR) ; } cout<<"姓名"<<" " ; cin>> p->data.name ; cout<<endl; cout<<"學號"<<" :"; cin >>p->data.IDcard ; cout<<endl; cout<<"性別"<<" :" ; cin>> p->data.gender; cout<<endl; cout<<"年齡"<<" :" ; cin>> p->data.age ; cout<<endl; cout<<"學院"<<" :" ; cin>> p->data.Institute ; cout<<endl; cout<<"班級"<<" :" ; cin>> p->data.Class; cout<<endl; /* strcpy(p->data.sport_it1,"000"); strcpy(p->data.sport_it2,"000");*/ p->next = NULL ; Gettime_f(p->data.Join_time.year ,p->data.Join_time.month ,p->data.Join_time.day ,p->data.Join_time.hours ,p->data.Join_time.minutes ,p->data.Join_time.second) ; if(head == NULL) head = p ; else { Last->next = p ; } Last = p ; } L = head ; FILE_Memory(L); cout<< " 資訊錄用成功"<< endl; return OK ; } Status List::GetElem(LinkList &L,int i ,Message &e) { /* 條件:線性表存在; 操作結果 : 如果 i 合法 得到線性表第i位置上的元素,反饋給e ; L 是不帶頭結點的; */ LinkList p ; if(!L) { cout<<" GetElem failed"<<endl; exit(ERROR) ; } p = L ; int k = 1 ; while(p) { if(k>=i) break ; ++k; p = p->next ; } if(!p || k>i) { cout<<"沒找到"<<endl; e.age = UNFOUND ; e.gender = 'F' ; strcpy(e.Class,""); strcpy(e.Institute,""); strcpy(e.name,""); } e = p->data ; return OK ; } Status List::printList(LinkList &L ) { /* 列印線性表 */ LinkList p = L ; while(p) { cout<<"姓名 : " <<p->data.name <<endl; cout<<"學號 : " <<p->data.IDcard <<endl; cout<<"性別 : "<<p->data.gender<<endl; cout<<"年齡 : "<<p->data.age<<endl; cout<<"學院 : "<<p->data.Institute<<endl; cout<<"班級 : "<<p->data.Class<<endl; cout<<"報名時間 : "<<p->data.Join_time.year<<"-"<<p->data.Join_time.month<<"-"<< p->data.Join_time.day <<" "<<p->data.Join_time.hours<<":"<<p->data.Join_time.minutes<<":"<<p->data.Join_time.second<<endl; p = p->next ; } return OK; } void FILE_Memory(LinkList &L) { FILE *fin ; int res ; char m[MAX] ; char n[MAX] ; char Name[MAX] ; LinkList p = L; if(L==NULL) { cout<<"L is NULL "<<endl; exit(0); } char cpy_Path[MAX] ={'\0'} ; system("cls"); while(p) { //再加一個掃描 , 看是否有重名 ; strcpy(cpy_Path,Path1) ; char T[MAX] ; strcpy(T,strcat( strcat(cpy_Path,p->data.IDcard),".txt")); int Judge = ScanRepetition(T) ;// 掃描是否有重名; if(Judge == 0) // 存在返回0 { char ch ; cout<<"你輸入的學號已經被錄入或者您輸入的學號有誤,請不要重複錄入. "<<endl; remove(T); // 操作失敗檔案刪除 Go_back2(); } else { strcpy(Name,p->data.IDcard ) ; strcpy(n,strcat(Name, ".txt")); // zhs.txt strcpy(m,Path1); // D://dos//SportSystem// strcat(m,n); // D://dos//SportSystem//zhs.txt } fin = fopen(m,"a+"); if( !fin) { cout<<"Creat_fin ERROR "<<endl; exit(0) ; } fprintf(fin,"%s %s %d %c %s %s %d %d %d %d %d %d \n",p->data.IDcard ,p->data.name,p->data.age,p->data.gender ,p->data.Institute, p->data.Class ,p->data.Join_time.year ,p->data.Join_time.month , p->data.Join_time.day ,p->data.Join_time.hours ,p->data.Join_time.minutes, p->data.Join_time.second); memset(m,'\0',sizeof(m)); memset(n,'\0',sizeof(n)); memset(Name,'\0',sizeof(Name)); memset(cpy_Path,'\0',sizeof(cpy_Path)) ; memset(T,'\0',sizeof(T)); p = p->next ; } fclose(fin); return ; } int ScanRepetition(char *file_name) { // 掃描 ; /* int access(const char *filename, int amode); amode引數為0時表示檢查檔案的存在性,如果檔案存在,返回0,不存在,返回-1。 */ return access(file_name,0); }
List.h
#ifndef LIST_H
#define LIST_H
#include <iostream>
#include <cstdlib>
#include <direct.h>
#include <time.h>
#define OK 1
#define ERROR 0
#define UNFOUND -1
#define Path1 "D:\\dos\\SportSystem\\"
using namespace std ;
const int MAX = 200 ;
typedef int Status ;
typedef int ElemType ;
typedef struct AD_number{
char num[MAX];
char password[MAX];
}AD;
typedef struct Person{
char num[MAX] ;
char name[MAX] ;
}Per;
typedef struct Data_location{
int year ;
int month ;
int day ;
int hours ;
int minutes ;
int second ;
}Data;
typedef struct Athlete_Message{
char IDcard[MAX] ;
char name[MAX] ; // 姓名
char gender ; // 性別
int age ;
char Institute[MAX] ; // 學院
char Class[MAX] ;// 班級;
Data Join_time; //
char sport_it1[MAX] ; // 專案一
char sport_it2[MAX] ; // 專案二
}Message;
typedef struct node{
Message data ;
struct node *next ;
}LNode, *LinkList;
class List
{
public:
Status CreatList(LinkList &L,int n) ;
Status GetElem(LinkList &L,int i ,Message &e) ;
Status printList(LinkList &L ) ;
private :
Message e ;
};
int ScanRepetition(char * );
void FILE_Memory(LinkList &L);
void Srearch_city_fiction(FILE *fp);
void Gettime_f(int &year ,int &month ,int &day ,int &hours ,int &minutes ,int &second );
#endif // LIST_H
Campus.cpp
#include "Campus.h"
#include "List.h"
#include <windows.h>
#define Path2 "D:\\dos\\Administrator\\"
void ShowPage()
{
cout<<endl<<endl;
cout<<"\t\t\t ***********************************"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t校 園 運 動 會 報 名 系 統 *"<<endl ;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ☆"<<" 1 報名系統進入 ☆ *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ☆"<<" 2 報名資訊查詢 ☆ *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ☆"<<" 3 運動員資訊 ☆ *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ☆"<<" 4 退出系統 ☆ *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ☆"<<" 0 管理員系統 ☆ *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t ***********************************"<<endl;
MenuChoose();
return ;
}
void MenuChoose()
{
int num ;
cout<<endl;
cout<<"========================================================================"<<endl;
cout<<"功能選擇"<<endl;
if(scanf("%d",&num)) // 正常輸入
{
switch (num)
{
case 1:
{
system("cls");// 清屏轉換下一級功能;
Show_Apply_System();
}
break ;
case 2:
{
Apply_Information_Query();
}
break ;
case 3:
{
Athlete_Information();
}
break ;
case 0:
{
Administrator_System();
}
break ;
case 4:
{
exit(0);
}
default :
{
cout<<"ERORR"<<endl;
exit(ERROR);
}
}
}
return ;
}
void Apply_System()
{
/*報名系統 */
FILE *fp ;
List a ; // 物件
LinkList L ; //
int i ,n ;
char ch1,ch2 ;
char ch3 ;
cout<<"個數"<<endl;
cin >> n ;
a.CreatList(L,n);
cout<<" 身份資訊確認 "<<"[y/n]"<<" ";
cin >>ch1 ;
if(ch1=='y')
{
cout<<" 確認成功 "<<endl;
Sleep(1);
}
cout<<" 身份資訊檢視 "<<"[y/n]"<<" ";
cin >>ch2 ;
if(ch2=='y')
{
a.printList(L);
Sleep(500);
}
Go_back1();
return ;
}
void Show_Apply_System()
{
int index ;
cout<<endl<<endl<<endl;
cout<<"\t\t\t ***********************************"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t 報 名 系 統 *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ◎"<<" 1 學生資訊錄入 ◎ *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ◎"<<" 2 運動專案報名 ◎ *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ◎"<<" 3 返回上一頁 ◎ *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t ***********************************"<<endl;
cout<<"請選擇"<<endl;
cin >>index ;
if(index == 1)
{
Apply_System();// 錄用資訊
}
else if(index ==2 )
{
LinkList L ;
cout<<"運動專案報名"<<endl;
Sport_item_sign();
}
else if( index == 3)
{
system("cls");
ShowPage();
}
else
{
Go_back2();
}
return ;
}
void Sport_item_sign()
{
// 首先 參看運動會參賽注意事項;
char ch ;
char ih ;
int it1,it2 ;
char Id[MAX] ;
char Cpy_path1[MAX] ;
Message M ,Stu;
Data d ;
FILE *fp = fopen("Data.txt","r");
cout<<"注意報名截止時間 : ";
if(!fp)
{
exit(0);
}
fscanf(fp ,"%d%d%d%d%d%d",&d.year,&d.month,&d.day,&d.hours ,&d.minutes ,&d.second);
printf("[ %d -%d -%d %d:%d: %d ]\n",d.year,d.month,d.day,d.hours ,d.minutes ,d.second);
cout<<endl;
if(Judge_IF_Past_due() == true )
{
// 時間過期;
cout<<" 報名時間已經截止 ";
Go_back2();
}
else
{
cout<<"輸入你的學生證號 : ";
cin >>Id ;
strcpy(Cpy_path1,Path1) ;
strcat(Cpy_path1,Id);
strcat(Cpy_path1,".txt");
if(ScanRepetition(Cpy_path1) == -1)
{
cout<<"沒有該學生資訊"<<endl;
Go_back1();
}
if(ScanRepetition(Cpy_path1)==0 && Judge_IF_sign(Cpy_path1))
{
cout<<"該生已經報名,請勿重複報名"<<endl;
Go_back2();
}
FILE *fIDCARD = fopen(Cpy_path1 ,"a+"); // 新增運動專案
if(!fIDCARD)
{
cout<<"open the file "<<endl;
exit(0) ;
}
/*識別性別*/
rewind(fIDCARD);
fscanf(fIDCARD,"%s %s %d %c %s %s %d %d %d %d %d %d ",Stu.IDcard ,Stu.name ,&Stu.age ,&Stu.gender ,Stu.Institute ,Stu.Class,
&Stu.Join_time.year ,&Stu.Join_time.month ,&Stu.Join_time.day ,&Stu.Join_time.hours ,&Stu.Join_time.minutes,&Stu.Join_time.second
);
system("cls");
FILE *SPORT_IN_FILE = fopen("SPORT.txt","r");
if(!SPORT_IN_FILE)
{
cout<<"SPORT_IN_FILE open ERROR"<<endl;
exit(0);
}
ch = fgetc(SPORT_IN_FILE);
while(!feof(SPORT_IN_FILE))
{
putchar(ch);
ch = fgetc(SPORT_IN_FILE);
Sleep(5);
}
fclose(SPORT_IN_FILE);
system("pause");
system("cls");
cout<<endl <<endl ;
if (Stu.gender == 'm')// 如果是男的
{
Per p[MAX] ;
// num ;
// name ;
char t1[MAX] ,t2[MAX] ;
FILE *sport = fopen("sportitemM.txt","r");
if(!sport)
{
cout<<"sportitemM open ERROR"<<endl;
exit(0);
}
ih = fgetc(sport);
while(!feof(sport))
{
putchar(ih);
ih = fgetc(sport);
Sleep(10);
}
fclose(sport);
FILE *fin = fopen("M.txt","r");
cout<<endl;
cout<<"選擇參加專案"<<endl;
cout<<"每名運動員可任意選擇兩種專案 (選一種的選擇000)"<<endl;
//cin >> M.sport_it1 >> M.sport_it2 ;
cin >> t1 >> t2 ;
int i = 0 ;
int flag1 , flag2 ;
while(!feof(fin))
{
fscanf(fin , "%s %s",p[i].num ,p[i].name);
i++ ;
}
int j = 0 ;
while(j<=i)
{
if (strcmp(t1 , p[j].num)==0)
{
flag1 = j ;
}
if (strcmp(t2 , p[j].num)==0)
{
flag2 = j ;
}
j++ ;
}
strcpy(M.sport_it1 , p[flag1].name);
strcpy(M.sport_it2 , p[flag2].name);
fprintf(fIDCARD,"%s %s",M.sport_it1 ,M.sport_it2);
rewind(fIDCARD);
fscanf(fIDCARD,"%s %s %d %c %s %s %d %d %d %d %d %d %s %s",M.IDcard ,M.name ,&M.age ,&M.gender ,M.Institute ,M.Class,
&M.Join_time.year ,&M.Join_time.month ,&M.Join_time.day ,&M.Join_time.hours ,&M.Join_time.minutes,&M.Join_time.second,
M.sport_it1,M.sport_it2);
cout<<"選擇成功"<<endl;
printList_new(M);
fclose(fIDCARD);
Sleep(500);
Go_back1();
}
else if (Stu.gender == 'f')
{
Per p[MAX] ;
char t1[MAX] ,t2[MAX] ;
FILE *sport = fopen("sportitemF.txt","r");
if(!sport)
{
cout<<"sportitemM open ERROR"<<endl;
exit(0);
}
ih = fgetc(sport);
while(!feof(sport))
{
putchar(ih);
ih = fgetc(sport);
Sleep(10);
}
fclose(sport);
FILE *fin = fopen("F.txt","r");
cout<<endl;
cout<<"選擇參加專案"<<endl;
cout<<"每名運動員可任意選擇兩種專案 (選一種的選擇000)"<<endl;
cin >> t1 >> t2 ;
int i = 0 ;
int flag1 , flag2 ;
while(!feof(fin))
{
fscanf(fin , "%s %s",p[i].num ,p[i].name);
if (strcmp(t1 , p[i].num)==0)
{
flag1 = i ;
}
if (strcmp(t2 , p[i].num)==0)
{
flag2 = i ;
}
i++ ;
}
strcpy(M.sport_it1 , p[flag1].name);
strcpy(M.sport_it2 , p[flag2].name);
fprintf(fIDCARD,"%s %s",M.sport_it1 ,M.sport_it2);
rewind(fIDCARD);
fscanf(fIDCARD,"%s %s %d %c %s %s %d %d %d %d %d %d %s %s",M.IDcard ,M.name ,&M.age ,&M.gender ,M.Institute ,M.Class,
&M.Join_time.year ,&M.Join_time.month ,&M.Join_time.day ,&M.Join_time.hours ,&M.Join_time.minutes,&M.Join_time.second,
M.sport_it1,M.sport_it2);
cout<<"選擇成功"<<endl;
printList_new(M);
fclose(fIDCARD);
Sleep(500);
Go_back1();
}
}
}
void Apply_Information_Query()
{
// 報名資訊查詢 ;
int i ;
char id_register[MAX] ;
char Temp[MAX];
system("cls");
cout <<"請輸入學號 :"<<" " ;
cin>>id_register ;
strcpy(Temp,Path1);
strcat(id_register,".txt");
strcat(Temp,id_register);
if(ScanRepetition(Temp)== -1 )
{
cout<<"沒有該生的相關資訊!"<<endl;
Go_back1();
}
if(Judge_IF_sign(Temp)== false)
{
cout<<"狀態 : 未報名"<<endl;
}
else
cout<<"狀態 : 已報名"<<endl;
Go_back1();
return ;
}
void Athlete_Information()
{
int i ;
char id_register[MAX] ;
char Temp[MAX];
system("cls");
cout <<"請輸入學號 :"<<" " ;
cin>>id_register ;
strcpy(Temp,Path1);
strcat(id_register,".txt");
strcat(Temp,id_register);
if(ScanRepetition(Temp)== -1)
{
cout<<"沒有該生的相關資訊!"<<endl;
Go_back1();
}
if(Judge_IF_sign(Temp))
{
Point_Base_Me(Temp);
Go_back1();
}
else
{
cout<<"還沒報名哦 ,請現在報名才能檢視哦 !"<<endl;
Go_back1();
}
return ;
}
bool Judge_IF_sign(char *Path)
{
// 判斷學生是否已報名專案;
bool flag = false ;
char Temp[MAX] ;
int count = 0;
FILE *fp = fopen(Path ,"r") ;
if(!fp)
{
cout<<"該生沒有錄入資訊"<<endl;
exit(0) ;
}
while(!feof(fp))
{
count +=fscanf(fp,"%s",Temp);
}
if (count == 14)// 如果已經報名;
flag = true ;
return flag ;
}
void Go_back1()
{
char ch ;
cout<<" 返回主頁面 "<<" [y/n] ";
cin >>ch ;
if(ch=='y')
{
system("cls");
ShowPage();
}
else
{
cout<<"伺服器錯誤00044xx"<<endl;
exit(0);
}
return ;
}
void Go_back2()
{
char ch ;
cout<<" 返回上一級 "<<" [y/n] ";
cin >>ch ;
if(ch=='y')
{
system("cls");
Show_Apply_System();
}
else
{
cout<<"伺服器錯誤00044xx"<<endl;
exit(0);
}
return ;
}
void Go_back3()
{
// 返回管理系統上一級;
char ch ;
cout<<" 返回上一級 "<<" [y/n] ";
cin >>ch ;
if(ch=='y')
{
system("cls");
show_in_AdSYstem();
}
else
{
cout<<"伺服器錯誤00044xx"<<endl;
exit(0);
}
return ;
}
void Go_back4()
{
char ch ;
cout<<" 返回上一級 "<<" [y/n] ";
cin >>ch ;
if(ch=='y')
{
system("cls");
Manage_system();
}
else
{
cout<<"伺服器錯誤00044xx"<<endl;
exit(0);
}
return ;
}
void printList_new(Message &M)
{
cout<<"姓名 : " <<M.name <<endl;
cout<<"學號 : " <<M.IDcard <<endl;
cout<<"性別 : "<<M.gender<<endl;
cout<<"年齡 : "<<M.age<<endl;
cout<<"學院 : "<<M.Institute<<endl;
cout<<"班級 : "<<M.Class<<endl;
cout<<"報名專案 : "<<M.sport_it1 <<" "<<M.sport_it2 <<endl;
cout<<"報名時間 : "<<M.Join_time.year<<"-"<<M.Join_time.month<<"-"<<
M.Join_time.day <<" "<<M.Join_time.hours<<":"<<M.Join_time.minutes<<":"<<M.Join_time.second<<endl;
return ;
}
void Point_Base_Me(char *Temp)
{
FILE *fp = fopen(Temp,"r");
Message M ;
fscanf(fp,"%s %s %d %c %s %s %d %d %d %d %d %d %s %s",M.IDcard ,M.name ,&M.age ,&M.gender ,M.Institute ,M.Class,
&M.Join_time.year ,&M.Join_time.month ,&M.Join_time.day ,&M.Join_time.hours ,&M.Join_time.minutes,&M.Join_time.second,
M.sport_it1,M.sport_it2);
printList_new(M);
Go_back1();
return ;
}
void Administrator_System()
{
// 管理員 ;
// 加一個 管理員登入 ;
Enter_Adsystem();
}
void show_in_AdSYstem()
{
/*
cout<<"您已進入管理員系統"<< endl;
cout<<"請輸入管理員賬號和密碼"<<endl;*/
system("cls");
cout<<endl<<endl;
cout<<"\t\t\t ***********************************"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t 管 理 員 系 統 *"<<endl ;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ☆"<<" 1 賬號註冊 ☆ *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ☆"<<" 2 管理系統 ☆ *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ☆"<<" 3 返回上一頁 ☆ *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t ***********************************"<<endl;
AD_Menu();
return ;
}
void AD_Menu()
{
int num ;
cout<<endl;
cout<<"========================================================================"<<endl;
cout<<"功能選擇"<<endl;
if(scanf("%d",&num)) // 正常輸入
{
switch (num)
{
case 1:
{
Log_Administrator();
}
break ;
case 2:
{
Manage_system();
}
break ;
case 3:
{
system("cls");
ShowPage();
}
break ;
default :
{
cout<<"ERORR"<<endl;
exit(ERROR);
}
}
}
return ;
}
void Log_Administrator()
{
// 賬號註冊 ;
FILE *fp ;
AD admin ;
char Pass_word[MAX] ;
char Temp[MAX] ;
strcpy(Temp,Path2);
cout<<"輸入姓名"<<" : ";
cin>>admin.num ;
strcat(Temp,admin.num);
strcat(Temp,".txt");
cout<<endl;
cout<<"輸入密碼"<<" : ";
cin>>admin.password ;
cout<<endl;
OP: cout<<"重複密碼"<<" : ";
cin>>Pass_word ;
if(strcmp(admin.password,Pass_word) == 0 )
{// 密碼正確 並且檔案不存在
if(ScanRepetition(Temp)==0)
{
cout<<"賬戶存在"<<endl;
exit(ERROR);
}
cout<<"注 冊 成 功"<<endl;
fp = fopen(Temp,"w");
if(!fp)
{
cout<<"open Temp failed "<<endl;
exit(ERROR) ;
}
fprintf(fp,"%s",admin.password);
fclose(fp);
Go_back3();
}
else
{
cout<<"密碼不一致"<<endl;
goto OP ;
}
return ;
}
void Manage_system()
{
system("cls");
cout<<endl<<endl;
cout<<"\t\t\t ***********************************"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t 管 理 系 統 *"<<endl ;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ☆"<<" 1 運動員報名取消 *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ☆"<<" 2 修改截止日期 *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t *\t"<<" ☆"<<" 3 返回上一頁 *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t * *"<<endl;
cout<<"\t\t\t ***********************************"<<endl;
AD_Menu2();
return ;
}
void AD_Menu2()
{
int num ;
cout<<endl;
cout<<"========================================================================"<<endl;
cout<<"功能選擇"<<endl;
if(scanf("%d",&num)) // 正常輸入
{
switch (num)
{
case 1:
{
// 運動員報名取消 刪除檔案
Cancel_signup();
}
break ;
case 2:
{
// 修改截止日期;
Revise_Data();
Go_back3();
}
break ;
case 3:
{
show_in_AdSYstem();
}
default :
{
cout<<"ERORR"<<endl;
exit(ERROR);
}
}
}
return ;
}
void Cancel_signup()
{
// 報名取消;
// 殺出檔案
char id[MAX] ; //
char Temp[MAX] ;
cout<<" 輸入報名取消的運動員學號"<<" :";
cin >> id ;
strcpy(Temp,Path1);
strcat(Temp,id);
strcat(Temp,".txt");
if(ScanRepetition(Temp) == -1)
{
cout<<"沒有該運動員的資訊,報名取消錯誤"<<endl;
exit(0);
}
else
{
remove(Temp);
cout<<"刪除成功"<<endl;
}
Go_back3();
return ;
}
void Revise_Data()
{
// 修改日期 ;
FILE *fp = fopen("Data.txt","w");
Data D ;
cout<< "輸入年份"<<" : ";
cin >> D.year ;
cout<<endl;
cout<< "輸入月份"<<" : ";
cin >> D.month ;
cout<<endl;
cout<< "輸入天數"<<" : ";
cin >> D.day ;
cout<<endl;
cout<< "輸入小時"<<" : ";
cin >> D.hours ;
cout<<endl;
cout<< "輸入分鐘"<<" : ";
cin >> D.minutes ;
cout<<endl;
cout<< "輸入秒數"<<" : ";
cin >> D.second ;
cout<<endl;
fprintf(fp,"%d %d %d %d %d %d",D.year,D.month,D.day ,D.hours ,D.minutes ,D.second);
cout<<"修改成功"<<endl;
fclose(fp);
return ;
}
void Enter_Adsystem()
{
char name[MAX] ;
char Temp[MAX] ;
char Password[MAX] ;
char PW[MAX] ;
FILE *fp ;
cout <<" 請輸入管理員賬號名 : ";
cin >> name ;
cout<<endl;
strcpy(Temp , Path2) ;
strcat(Temp , name) ;
strcat(Temp , ".txt");
if(ScanRepetition(Temp) == -1)
{
// 不存在
cout<<" 管理員賬號不存在 "<<endl ;
exit(0) ;
}
fp = fopen(Temp , "r") ;
if(!fp)
{
cout<<" open the file failed "<<endl;
exit(0) ;
}
fscanf(fp , "%s",Password);
fclose(fp) ;
cout <<" 你輸入密碼驗證 "<<" : ";
cin >> PW ;
if ( strcmp(PW,Password)==0)
{
int i ;
cout<<"驗證成功"<<endl ;
for(i = 1 ; i<= 4 ; i++)
{
cout <<i;
Sleep(500) ;
system("cls");
}
show_in_AdSYstem();
}
else
{
cout <<"驗證失敗"<<endl;
Go_back1();
}
return ;
}
bool Judge_IF_Past_due()
{
Message M ;
Data D ; // 截止時間
Data SD ; // 當前時間 ;
// bool C = true ; // 初始值時過期了
FILE *Dp = fopen("Data.txt","r");
if(!Dp)
{
exit(0);
}
fscanf(Dp,"%d%d%d%d%d%d",&D.year,&D.month,&D.day ,&D.hours ,&D.minutes ,&D.second);
//printf("截止時間 :%d -%d- %d %d :%d :%d \n",D.year,D.month,D.day ,D.hours ,D.minutes ,D.second);
Gettime_f(SD.year ,SD.month ,SD.day ,SD.hours ,SD.minutes ,SD.second); //獲取當前時間
printf("當前時間 : [ %d -%d- %d %d :%d :%d ]\n",SD.year ,SD.month ,SD.day ,SD.hours ,SD.minutes ,SD.second);
if( SD.year < D.year )
{
// 截止時間 :2019 -5- 47 8 :63 :12
// 當前時間 :2018 -7- 11 15 :46 :24
return false ; // 還沒截止
}
else if (SD.year == D.year && SD.month != D.month)
{
if(SD.month < D.month)
{
return false ;
}
else if ( SD.month > D.month)
{
return true ;
}
}
else if (SD.year == D.year && SD.month == D.month && SD.day != D.day)
{
if (SD.day <D.day )
{
// 如果當前天數 小於 截止天數
return false ;
}
else if ( SD.day > D.day)
{
return true ;
}
}
else if ( SD.year == D.year && SD.month == D.month && SD.day == D.day && SD.hours !=D.hours)
{
if (SD.hours <D.hours )
{
return false ;
}
else if ( SD.hours > D.hours)
{
return true ;
}
}
}
程式碼有點多,應該還能改進 ,路徑可以自己改.