当前位置:网站首页>案例描述:比赛分数管理系统,需要统计历届冠军所得比赛得分,并记录到文件中,其中系统有如下需求:- 打开系统有欢迎界面,并显示可选择的选项- 选项1:记录比赛得分- 选项2:查看往届
案例描述:比赛分数管理系统,需要统计历届冠军所得比赛得分,并记录到文件中,其中系统有如下需求:- 打开系统有欢迎界面,并显示可选择的选项- 选项1:记录比赛得分- 选项2:查看往届
2022-06-26 19:11:00 【laocooon】
案例描述:比赛分数管理系统,需要统计历届冠军所得比赛得分,并记录到文件中,其中系统有如下需求:
- 打开系统有欢迎界面,并显示可选择的选项
- 选项1:记录比赛得分
- 选项2:查看往届记录
- 选项3:清空比赛记录
- 选项4:退出当前系统
根据用户不同的输入,实现不同的需求,若输入为其他值,视为清空屏幕重新选择
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/*
案例描述:比赛分数管理系统,需要统计历届冠军所得比赛得分,并记录到文件中,其中系统有如下需求:
- 打开系统有欢迎界面,并显示可选择的选项
- 选项1:记录比赛得分
- 选项2:查看往届记录
- 选项3:清空比赛记录
- 选项4:退出当前系统
根据用户不同的输入,实现不同的需求,若输入为其他值,视为清空屏幕重新选择
*/
int FileIsEmpty = 0; // 1 代表文件为空 0 文件不为空
void clearFile()
{
if (FileIsEmpty)
{
printf("文件记录为空!\n");
system("pause");
system("cls");
return;
}
printf("确认清空?\n");
printf("1、确定!\n");
printf("2、返回!\n");
int select = 0;
int num = scanf("%d", &select);
if (select == 1)
{
FILE* fp = fopen("score.txt", "w");
fclose(fp);
printf("清空完毕!\n");
FileIsEmpty = 1;
}
system("pause");
system("cls");
}
void initFlag()
{
FILE* fp = fopen("score.txt", "r");
if (fp == NULL)
{
printf("文件打开失败\n");
return;
}
char ch = fgetc(fp);
if (ch == EOF)
{
//printf("文件为空\n");
FileIsEmpty = 1;
}
else
{
//printf("文件不为空\n");
FileIsEmpty = 0;
}
}
//记录分数
void setScore()
{
printf("请输入新记录分数:\n");
double score = 0;
int num = scanf("%lf", &score);
FILE* fp = fopen("score.txt", "a"); //a代表追加的方式写文件
if (fp == NULL)
{
printf("文件打开失败!\n");
return;
}
fprintf(fp, "%lf\n", score);
printf("分数记录成功!\n");
FileIsEmpty = 0;
//关闭文件
fclose(fp);
system("pause");
system("cls");
}
void showScore()
{
if (FileIsEmpty)
{
printf("文件记录为空!\n");
system("pause");
system("cls");
return;
}
FILE* fp = fopen("score.txt", "r");
int index = 1;
while (!feof(fp))
{
double score;
int ret = fscanf(fp, "%lf", &score);
//if (feof(fp))
if(ret == -1)
{
break;
}
printf("%d届分数为: %.2lf\n", index, score);
index++;
}
fclose(fp);
system("pause");
system("cls");
}
void show_Menu()
{
printf("*********************************************\n");
printf("************* 欢迎使用本程序 *************\n");
printf("************* 1、记录比赛得分 *************\n");
printf("************* 2、查看往届记录 *************\n");
printf("************* 3、清空比赛记录 *************\n");
printf("************* 4、退出当前系统 *************\n");
printf("*********************************************\n");
}
int main()
{
initFlag();
int choice = 0; //用来存储用户的选择
int num = 0;
while (1)
{
show_Menu();
printf("请输入您的选择:\n");
num = scanf("%d", &choice);
switch (choice)
{
case 1: //记录比赛得分
setScore();
break;
case 2: //查看往届记录
showScore();
break;
case 3: //清空比赛记录
clearFile();
break;
case 4: //退出当前系统
printf("欢迎您下次使用\n");
system("pause");
exit(0); //退出当前系统
break;
default:
system("cls");
break;
}
}
system("pause");
return EXIT_SUCCESS;
}边栏推荐
猜你喜欢

Leetcode 238 product of arrays other than itself

Refresh the strong pointer assignment problem in the HP-UX system of Sanguan

Decompilation of zero time technology smart contract security series articles

mysql的充值问题

项目实战四:用户登录及token访问验证(reids+jwt)

(几何) 凸包问题

抖音实战~分享模块~复制短视频链接

Installation and use of filebeat

Wechat applet custom pop-up components

50 lines of code to crawl TOP500 books and import TXT documents
随机推荐
Nftgamefi chain game system development detailed solution - chain game system development principle analysis
tsconfig. json
读书笔记:《过程咨询 III》
Installation and use of filebeat
知識點總結
Web resource preloading - production environment practice
【推荐收藏】这8个常用缺失值填充技巧一定要掌握
基于tensorflow的手写数字识别
[MySQL series] collection of common working SQL (continuous update)
Solidity - contract inheritance sub contract contains constructor errors and one contract calls the view function of another contract to charge gas fees
成功解决之微服务@Value获取配置文件乱码问题
Minimum spanning tree, shortest path, topology sorting, critical path
Button how to dynamically set drawablebottom (setcomposunddrawables is invalid)
System table SQLite of SQLite database_ master
数据库范式和主码的选择
Database SQL statement writing
Tiktok practice ~ sharing module ~ generate short video QR code
Reading notes: process consulting III
Project practice 5: build elk log collection system
The cross compilation environment appears So link file not found problem