運動會積分系統
運動會積分系統
問題描述:學生運動會成績資料庫系統記錄某校運動會上全部運動專案,各系獲得的分數及排名情況,運動會專案包括100,400,1500米,跳高,跳遠等。分設男子組和女子組。請設計一個積分系統,方便學校對比賽成績進行統計管理
功能要求:
管理員:
1) 管理員憑密碼進入系統,完成以下工作
填寫比賽結果(每專案取前三名,分別為積7,5,4分),輸入各專案獲獎運動員的資訊
2)可以按各系院名稱輸出該學院獲得的總分,並按總分排序
3)輸出男子團體,女子團體總分排序結果
4)實現按院系名稱,運動專案名稱查詢比賽成績
普通使用者:
普通使用者可以查詢運動員個人比賽成績,檢視參賽院系的成績和各比賽專案最終名次等。
以下程式碼執行須知:
1.在vc6.0下fstream標頭檔案要改成fstream.h
2.在工程目錄下手動新建三個.txt檔案
1) password.txt (輸入******並儲存)
2) game_data.txt (空檔案)
3) department_data.txt (空檔案)
3.性別男為m,女為f,不能輸入別的無關字元
4.部分環境不支援中文,與字元編碼有關
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fstream>
typedef struct athlete
{
char name[20]; //姓名
char code[10]; //號碼
char department[20]; //院系
}Athlete;
typedef struct award_name
{
char sport[20]; //專案名稱
char sex[10]; //f女 m男
Athlete award_ath;
int rank;
int score;
}Award;
typedef struct statistic
{
char department[20];
int score_fm;
int score_m;
int score;
}Statistic;
int Judge_Password()
{
char inp[20];
char p[20];
FILE *fp = NULL;
fp = fopen("password.txt", "r+");
fscanf(fp, "%s", p);
if(strcmp(p, "******") == 0) //輸入原始密碼
{
printf("Please input init password (no more than 15ch)\n");
scanf("%s", p);
fprintf(fp, "%s", p);
fclose(fp);
return 1;
}
else
{
printf("Please input the password\n");
scanf("%s", inp);
if(strcmp(inp, p + 6) == 0)
{
fclose(fp);
return 1;
}
else
{
printf("wrong password!\n");
fclose(fp);
return 0;
}
}
}
void a_input_result()
{
int i, j, flag1, flag2, d_num = 0, a_num = 0, tmpd, tmpa;
FILE *fp1, *fp2;
Award a[3], af[100];
Statistic s[3], sf[100];
memset(a, 0, sizeof(a));
memset(s, 0, sizeof(s));
fp1 = fopen("game_data.txt", "r");
fp2 = fopen("department_data.txt", "r");
fscanf(fp2, "%d\n", &d_num);
fscanf(fp1, "%d\n", &a_num);
for(i = 0; i < d_num; i++)
fscanf(fp2, "%s %d %d %d\n", sf[i].department, &sf[i].score_fm, &sf[i].score_m, &sf[i].score);
for(i = 0; i < a_num; i++)
fscanf(fp1, "%s %s %s %s %s %d %d\n", af[i].sport, af[i].award_ath.name, af[i].award_ath.code, af[i].award_ath.department, af[i].sex, &af[i].rank, &af[i].score);
fclose(fp1);
fclose(fp2);
printf("按專案輸入前三名資訊(專案名稱 姓名 編號 院系 性別 排名):\n");
for(i = 0; i < 3; i++)
{
scanf("%s %s %s %s %s %d", a[i].sport, a[i].award_ath.name, a[i].award_ath.code, a[i].award_ath.department, a[i].sex, &a[i].rank);
if(i == 0)
{
if(a[i].sex[0] == 'f')
s[i].score_fm += 7;
else
s[i].score_m += 7;
s[i].score += 7;
a[i].score += 7;
}
else if(i == 1)
{
if(a[i].sex[0] == 'f')
s[i].score_fm += 5;
else
s[i].score_m += 5;
s[i].score += 5;
a[i].score += 5;
}
else if(i == 2)
{
if(a[i].sex[0] == 'f')
s[i].score_fm += 4;
else
s[i].score_m += 4;
s[i].score += 4;
a[i].score += 4;
}
strcpy(s[i].department, a[i].award_ath.department);
}
for(i = 0; i < 3; i++)
{
af[a_num + i] = a[i];
sf[d_num + i] = s[i];
}
a_num += 3;
d_num += 3;
fp1 = fopen("game_data.txt", "w");
fp2 = fopen("department_data.txt", "w");
fprintf(fp2, "%d\n", d_num);
fprintf(fp1, "%d\n", a_num);
for(i = 0; i < a_num; i++)
fprintf(fp1, "%s %s %s %s %s %d %d\n", af[i].sport, af[i].award_ath.name, af[i].award_ath.code, af[i].award_ath.department, af[i].sex, af[i].rank, af[i].score);
for(i = 0; i < d_num; i++)
fprintf(fp2, "%s %d %d %d\n", sf[i].department, sf[i].score_fm, sf[i].score_m, sf[i].score);
fclose(fp1);
fclose(fp2);
}
void Swap(Statistic x, Statistic y)
{
Statistic tmp;
tmp = x;
x = y;
y = tmp;
}
void Sort(Statistic *s, int num, int op) //0總分 1男 2女
{
int i, j, mi, idx;
for(i = 0; i < num; i++)
{
mi = 1000000;
for(j = i; j < num; j ++)
{
if(op == 0)
{
if(s[j].score < mi)
{
mi = s[j].score;
idx = j;
}
}
else if(op == 1)
{
if(s[j].score_m < mi)
{
mi = s[j].score_m;
idx = j;
}
}
else
{
if(s[j].score_fm < mi)
{
mi = s[j].score_fm;
idx = j;
}
}
}
Swap(s[i], s[j]);
}
}
void a_output_total_goal()
{
int i, j, num, cnt = 0, flag = 0, idx;
Statistic s[100], rs[100];
FILE *fp;
memset(rs, 0, sizeof(rs));
fp = fopen("department_data.txt", "r");
fscanf(fp, "%d", &num);
for(i = 0; i < num; i++)
fscanf(fp, "%s %d %d %d\n", s[i].department, &s[i].score_fm, &s[i].score_m, &s[i].score);
for(i = 0; i < num; i++)
{
for(j = 0; j < cnt; j++)
{
flag = 0;
if(strcmp(s[i].department, rs[j].department) == 0)
{
flag = 1;
idx = j;
break;
}
}
if(flag)
{
rs[idx].score += s[i].score;
}
else
{
strcpy(rs[cnt].department, s[i].department);
rs[cnt].score += s[i].score;
cnt ++;
}
}
Sort(rs, cnt, 0);
for(i = 0; i < cnt; i++)
printf("院系名稱: %s 總分: %d\n", rs[i].department, rs[i].score);
fclose(fp);
}
void a_output_fandfm_goal()
{
int i, j, num, cnt1 = 0, cnt2 = 0, f1 = 0, f2 = 0, idx;
Statistic s[100], rfs[100], rms[100];
FILE *fp;
fp = fopen("department_data.txt", "r");
memset(rfs, 0, sizeof(rfs));
memset(rms, 0, sizeof(rms));
fscanf(fp, "%d", &num);
for(i = 0; i < num; i++)
fscanf(fp, "%s %d %d %d\n", s[i].department, &s[i].score_fm, &s[i].score_m, &s[i].score);
for(i = 0; i < num; i++)
{
for(j = 0; j < cnt1; j++)
{
f1 = 0;
if(strcmp(s[i].department, rms[j].department) == 0)
{
f1 = 1;
idx = j;
break;
}
}
if(f1)
{
rms[idx].score_m += s[i].score_m;
//printf("rms[%d].score_m = %d\n", idx, rms[idx].score_m);
}
else
{
//printf("rms[%d].score_m = %d\n", cnt1, rms[cnt1].score_m);
strcpy(rms[cnt1].department, s[i].department);
rms[cnt1].score_m += s[i].score_m;
cnt1 ++;
}
}
Sort(rms, cnt1, 1);
for(i = 0; i < cnt1; i++)
printf("院系名稱: %s 男團分: %d\n", rms[i].department, rms[i].score_m);
printf("\n\n");
for(i = 0; i < num; i++)
{
for(j = 0; j < cnt2; j++)
{
f2 = 0;
if(strcmp(s[i].department, rfs[j].department) == 0)
{
f2 = 1;
idx = j;
break;
}
}
if(f2)
rfs[idx].score_fm += s[i].score_fm;
else
{
strcpy(rfs[cnt2].department, s[i].department);
rfs[cnt2].score_fm += s[i].score_fm;
cnt2 ++;
}
}
Sort(rfs, cnt2, 2);
for(i = 0; i < cnt2; i++)
printf("院系名稱: %s 女團分: %d\n", rfs[i].department, rfs[i].score_fm);
fclose(fp);
}
void query_by_department()
{
int i, num, flag = 0, sum = 0, fm_sum = 0, m_sum = 0;
FILE *fp;
Statistic s[20];
char d_name[100];
fp = fopen("department_data.txt", "r");
fscanf(fp, "%d", &num);
for(i = 0; i < num; i++)
fscanf(fp, "%s %d %d %d\n", s[i].department, &s[i].score_fm, &s[i].score_m, &s[i].score);
printf("請輸入查詢的院系名稱:\n");
scanf("%s", d_name);
for(i = 0; i < num; i++)
{
if(strcmp(d_name, s[i].department) == 0)
{
flag = 1;
sum += s[i].score;
m_sum += s[i].score_m;
fm_sum += s[i].score_fm;
}
}
if(!flag)
printf("沒有該院系的相關資訊\n");
else
printf("院系名稱: %s\n", d_name);
printf("總分: %d\n", sum);
printf("男子總分: %d\n", m_sum);
printf("女子總分: %d\n", fm_sum);
fclose(fp);
}
void a_query_by_aname()
{
int i, num, flag = 0, cnt = 0;
FILE *fp;
Award ad[100], Tar[100];
char a_name[100];
memset(Tar, 0, sizeof(Tar));
fp = fopen("game_data.txt", "r");
fscanf(fp, "%d", &num);
for(i = 0; i < num; i++)
fscanf(fp, "%s %s %s %s %s %d %d\n", ad[i].sport, ad[i].award_ath.name, ad[i].award_ath.code, ad[i].award_ath.department, ad[i].sex, &ad[i].rank, &ad[i].score);
printf("請輸入查詢的專案名稱:\n");
scanf("%s", a_name);
for(i = 0; i < num; i++)
{
if(strcmp(a_name, ad[i].sport) == 0)
{
flag = 1;
Tar[cnt ++] = ad[i];
}
}
if(!flag)
printf("沒有該專案的相關資訊\n");
else
{
printf("專案名稱: %s\n", a_name);
for(i = 0; i < cnt; i++)
{
printf("運動員姓名: %s 編號: %s 學院: %s\n", Tar[i].award_ath.name, Tar[i].award_ath.code, Tar[i].award_ath.department);
printf("運動員性別: %s 得分: %d 排名: %d\n", Tar[i].sex, Tar[i].score, Tar[i].rank);
printf("\n");
}
}
fclose(fp);
}
int Admin_opt() //管理員選項
{
int opt = 0;
printf("請選擇操作\n");
printf("1 - 填寫比賽結果\n");
printf("2 - 輸出學院總分\n");
printf("3 - 輸出男子團體,女子團體的總分\n");
printf("4 - 按院系名稱查詢比賽成績\n");
printf("5 - 按運動專案名稱查詢比賽成績\n");
printf("6 - 退出\n");
scanf("%d", &opt);
switch(opt)
{
case 1:
a_input_result();
break;
case 2:
a_output_total_goal();
break;
case 3:
a_output_fandfm_goal();
break;
case 4:
query_by_department();
break;
case 5:
a_query_by_aname();
break;
case 6:
return 0;
}
return 1;
}
void u_query_by_person()
{
int i, num, flag = 0, cnt = 0;
FILE *fp;
Award ad[100], Tar[100];
char p_name[100];
memset(Tar, 0, sizeof(Tar));
fp = fopen("game_data.txt", "r");
fscanf(fp, "%d", &num);
for(i = 0; i < num; i++)
fscanf(fp, "%s %s %s %s %s %d %d\n", ad[i].sport, ad[i].award_ath.name, ad[i].award_ath.code, ad[i].award_ath.department, ad[i].sex, &ad[i].rank, &ad[i].score);
printf("請輸入查詢的運動員姓名:\n");
scanf("%s", p_name);
for(i = 0; i < num; i++)
{
if(strcmp(p_name, ad[i].award_ath.name) == 0)
{
flag = 1;
Tar[cnt ++] = ad[i];
}
}
if(!flag)
printf("沒有該運動員的相關資訊\n");
else
{
printf("姓名: %s 編號: %s 學院: %s 性別: %s\n", p_name, Tar[0].award_ath.code, Tar[0].award_ath.department, Tar[0].sex);
for(i = 0; i < cnt; i++)
printf("專案名稱: %s 得分: %d 排名: %d\n", Tar[i].sport, Tar[i].score, Tar[i].rank);
}
fclose(fp);
}
void u_query_final_rank()
{
int i, num, flag = 0, cnt = 0;
FILE *fp;
Award ad[100], Tar[100];
char s_name[100];
fp = fopen("game_data.txt", "r");
fscanf(fp, "%d", &num);
for(i = 0; i < num; i++)
fscanf(fp, "%s %s %s %s %s %d %d\n", ad[i].sport, ad[i].award_ath.name, ad[i].award_ath.code, ad[i].award_ath.department, ad[i].sex, &ad[i].rank, &ad[i].score);
printf("請輸入查詢的專案名稱:\n");
scanf("%s", s_name);
for(i = 0; i < num; i++)
{
if(strcmp(s_name, ad[i].sport) == 0)
{
flag = 1;
Tar[cnt ++] = ad[i];
}
}
if(!flag)
printf("沒有該專案的相關資訊\n");
else
{
printf("專案名稱: %s\n", Tar[0].sport);
for(int i = 0; i < cnt; i++)
{
printf("姓名: %s 編號: %s 學院: %s\n", Tar[i].award_ath.name, Tar[i].award_ath.code, Tar[i].award_ath.department);
printf("性別: %s 得分: %d 排名: %d\n", Tar[i].sex, Tar[i].score, Tar[i].rank);
printf("\n");
}
}
fclose(fp);
}
int user_opt()
{
int opt = 0;
printf("請選擇操作\n");
printf("1 - 查詢運動員個人比賽成績\n");
printf("2 - 檢視參賽院系的成績\n");
printf("3 - 各比賽專案最終名次\n");
printf("4 - 退出\n");
scanf("%d", &opt);
switch(opt)
{
case 1:
u_query_by_person();
break;
case 2:
query_by_department();
break;
case 3:
u_query_final_rank();
break;
case 4:
return 0;
}
return 1;
}
int main()
{
char id[20]; //管理員or使用者
printf("You can enter Q to quit\n\nPlease enter admin or user\n");
while(scanf("%s", id))
{
if(strcmp(id, "admin") == 0)
{
while(!Judge_Password());
while(Admin_opt());
exit(0);
}
else if(strcmp(id, "user") == 0)
{
while(user_opt());
exit(0);
}
else if(strcmp(id, "Q") == 0)
{
exit(0);
}
else
{
printf("invalid input\n");
}
}
return 0;
}
相關文章
- 積分商城_積分系統_積分業務邏輯與管理_OctShop
- 會員積分體系設計
- ThinkPHP會員積分機制分享平臺系統原始碼PHP原始碼
- 區塊鏈積分商城開發運營版丨區塊鏈積分商城系統開發(案例及詳細)區塊鏈
- Unity遊戲積分/計分系統製作方法Unity遊戲
- 3分鐘學會如何排程運營海量Redis系統Redis
- 搭建免費版會員積分商城系統需要考慮哪些問題?
- 羽毛球比賽積分系統02
- 羽毛球比賽積分系統03
- 企業員工福利積分商城系統
- 1002,概統,積分
- 羽毛球比賽積分系統--需求分析
- 區塊鏈積分聯盟模式系統如何開發?(區塊鏈積分聯盟模式系統開發原始碼demo)區塊鏈模式原始碼
- 【微積分】不定積分
- 會員分銷返利系統開發APP,會員返利小程式系統APP
- 虛擬商品積分兌換商城搭建會員權益體系
- 使用 django middleware 和 celery 隔離業務系統和積分系統的嘗試Django
- 數商雲S2B2C積分商城系統
- 欣動時刻系統開發|智慧運動系統開發搭建
- 仿運動社交軟體 噠噠運動APP系統開發APP
- win10系統下玩命運2滑鼠不會動怎麼解決Win10
- 會員分銷返利APP系統開發APP
- 積分
- 如何設計一個電商平臺積分兌換系統?
- 數商雲分銷管理系統開發,解決傳統企業運營分銷商城系統難點
- BT自動檔案分發系統
- 運維自動化之賬單系統運維
- Thinkphp開發的積分商城系統原始碼詳情開發示例PHP原始碼
- 不定積分
- 半球積分
- 《10分鐘剖析》系統啟動2——啟動zygoteGo
- 微積分小感——3.簡單積分
- 阿里二面:設計一個電商平臺積分兌換系統!阿里
- 智慧黨建資訊化管理平臺,黨員積分系統開發
- 10分鐘學會使用 Loki 日誌聚合系統Loki
- 系統性體育運動可提高NAD+
- Android 之 MIT積木搭建系統AndroidMIT
- matlab對不定積分和定積分的計算Matlab
- 欣動時刻運動零擼NFT系統開發搭建