我是一个普通的医学生,还在末流的211,期末备战组织胚胎学的时候发现我实在是缺乏一本地题库,用来对于短时间必须要知道的题目进行自测.
于是在网上搜集了一大堆资料,东查查,西找找,缝缝补补造出了个四不像,此前没有系统学习编程,更不具编程思想,好在最终软件可以平稳运行,即使局限性较大
原来不打算分享代码的,但是这几天看到了网上的大神的项目,顿感自己闭门造出的垃圾着实没有什么收藏价值,此前也在朋友圈分享过这个小程序,只是没有公布源码,现在附上:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <string.h>
//生成随机函数的头文件
#include <time.h>
//可以退出的头文件
#include <stdlib.h>
//结构体的长度
#define DATALEN 2//可以存放的最大题目数量:DATALEN +1
#define k 3 //随机数数组元素个数
//上述两个常量应该保持一致,并且恰好等于 text22.txt的题目数量
//函数声明
//定义结构数组
struct wordUnit {
int title_turn;
char title[400]; //title
char choice_A[80]; //A
char choice_B[80]; //B
char choice_C[80]; //C
char choice_D[80]; //D
char choice_E[80]; //E
char answer[200]; //答案
char answer_help[100];//解析
}words[DATALEN];
struct User
{
char answer_user[10];
char add_help[100];
char choice_E_delete[80]="delete"; //用来删除选项E,当我们录入的字符串为delete时,跳过打印E选项
}H[DATALEN];
int main() {
//读取文档
FILE* data;//要读取的文件指针
int i = 0;//结构题数组移动
//struct wordUnit words[DATALEN]{};
if ((data = fopen("C:\\Users\\19355\\Desktop\\test22.txt", "r")) == NULL) {
printf("test22.txt文件不存在于桌面\n");
return 0;
}
while (!feof(data)) {
//原txt文档的数据之间是以空格隔开的
fscanf(data, "%d %s %s %s %s %s %s %s %s\n", &words[i].title_turn, words[i].title, words[i].choice_A, words[i].choice_B, words[i].choice_C, words[i].choice_D, words[i].choice_E, words[i].answer, words[i].answer_help);
i++;
}
fclose(data);
//程序运行状况检查和警告建议
printf("程序随机模式下运行状况检查和警告建议: ");
if (i < k) {
printf("可能会在随机模式下出现空题的状况\n");
}
else {
printf("在随机模式下不会出问题\n");
}
printf("\n");
printf("程序顺序模式下运行状况检查和警告建议: ");
printf("看到这个界面就不会出现问题\n");
printf("\n");
system("pause");
//添加密码校验程序
caidan:
//打印功能菜单
system("cls");
int input_user;
printf("*******仲源的简单医学题库程序*******\n");
printf("以下是功能菜单:\n");
printf("输入 1 进入顺序刷题\n");
printf("输入 2 进入乱序刷题\n");
printf("输入 3 查软件相关说明\n");
printf("输入 4 退出软件\n");
printf("请输入1 2 3 4 中的任何一个数字以进行选择\n");
scanf("%d", &input_user);
if (input_user == 1) {
system("cls");
goto list_1;
}
else {
if (input_user == 2) {
system("cls");
goto list_2;
}
else {
if (input_user == 3) {
system("cls");
printf("作者:***\n");
printf("感想:真的头秃,老实摆烂不香吗\n");
system("pause");
return 0;
}
else {
if (input_user == 4) {
system("exit");
return 0;
}
else {
printf("你所输入的值无效,请从新输入");
system("pause");
goto caidan;
}
}
}
}
return 0;
//这一段实现的是顺序打印题目并且作答(功能菜单 1)
list_1:
for (int j = 0; j < i; j++) {
printf("第%d题,共%d题", j + 1, i );
printf("\n%d %s\nA.%s\nB.%s\nC.%s\nD.%s\n", words[j].title_turn, words[j].title, words[j].choice_A, words[j].choice_B, words[j].choice_C, words[j].choice_D);
while (strcmp(words[j].choice_E,H[j].choice_E_delete)!=0)
{
printf("E.%s\n", words[j].choice_E);
break;
}
printf("请输入你选择的答案(请使用大写字母):");
scanf("%s",H[j].answer_user);
system("cls");
printf("你选择的答案%s", H[j].answer_user);
if ( strcmp(H[j].answer_user, words[j].answer)==0 ) {
printf("正确\n");
}
else {
printf("错误,答案是:%s\n", words[j].answer);
printf("解析:%s\n", words[j].answer_help);
}
system("pause");
system("cls");
}
return 0;
//这一段实现的是乱序打印题目并且作答(功能菜单 2)
list_2:
int a[k]={}, m = 0, j, r;
srand((int)time(0)); //用当前时间作为随机种子
while (m < k)
{
r = rand() % k + 1; //生成一个1-k的随机数
for (j = m; j >= 0; j--)
{
if (r == a[j]) //与之前已存的随机数比较
break;
}
if (j < 0) //没有重复即保存到数组中
{
a[m] = r;
m++;
}
}
for (int j = 0; j < i; j++) {
printf("第%d题,共%d题", j + 1, i);
printf("\n%d %s\nA.%s\nB.%s\nC.%s\nD.%s\n", j+1, words[a[j] - 1].title, words[a[j] - 1].choice_A, words[a[j] - 1].choice_B, words[a[j] - 1].choice_C, words[a[j] - 1].choice_D);
while (strcmp(words[a[j] - 1].choice_E, H[a[j] - 1].choice_E_delete) != 0)
{
printf("E.%s\n", words[a[j] - 1].choice_E);
break;
}
printf("请输入你选择的答案(请使用大写字母):");
scanf("%s", H[a[j] - 1].answer_user);
system("cls");
printf("你选择的答案%s", H[a[j] - 1].answer_user);
if (strcmp(H[a[j] - 1].answer_user, words[a[j] - 1].answer) == 0) {
printf("正确\n");
}
else {
printf("错误,答案是:%s\n", words[a[j] - 1].answer);
printf("解析:%s\n", words[a[j] - 1].answer_help);
}
system("pause");
system("cls");
}
return 0;
}
//小小规划
//实现功能菜单,密码登录验证
//实现乱序不重复的做题
//实现统计错题计算正确率,然后实现输出正确率和日期
//实现上一题,下一题功能目录打印
//刷题过程中允许进行退出,记录上次做题进度,从标记处开始
//打印做题心得体会并且
最后面的注释是原本想要加入的功能,但是因为自身的业余性,最后果断放弃,暑期还有见习的社会实践,下学期还有生理生化,头已经巨大无比,何苦继续自寻烦恼.