利用指针实现小学生数学四则运算小软件 2018年12月20日
以下内容仅供娱乐,欢迎随时探讨,请多指教!
利用函数指针、指针函数、数组指针以及指针数组完成小学生数学四则运算小软件,具体要求如下:
1)要具有自动批改功能。
2)要具有统计已完成题目数量和正确率功能。
3)要具有错题记录和回放功能。
4)参与运算的数据范围可以由使用者设定
5)参与运算的数据在使用者设定范围后随机生成。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//一道题的结构体
struct problem {
int value1;
char fuhao;
int value2;
double answer;
double result;
};
//一张试卷的结构体
struct testpaper {
int txuhao;
int num;
int dataMin;//范围
int dataMax;
struct problem** next;
/*
<param name="ap">
题目集合
一级指针指向aTopic结构体,二级指针指向一级指针
申请空间时,需要多少个题,就申请多少个aTopic结构体的一级指针
当然直接申请aTopic结构体*N的空间大小给aTopic结构体的一级指针也可以
*/
};
double keep2(double a);//求百分比约小数点后两位小数的函数
struct testpaper* makeTestPaper();//出试卷函数
void doExam(struct testpaper* tp);//做题函数
struct testpaper* correct(struct testpaper* tp);//批改试卷函数
void showTestPaper(struct testpaper* tp,int answer);//展示结果函数
//主函数
int main()
{
int doAgain=0;
struct testpaper* tp;
struct testpaper* worngtp;
struct testpaper* (*poniter)();//函数指针使用
poniter=makeTestPaper;
beforel:
tp=poniter();//出题
srand(time(NULL));
system("cls");
printf("开始答题:\n"
"(除法最多保留两位小数,需要四舍五入)\n"
"____________分割线_______________\n");
doExam(tp);
worngtp=correct(tp);
while(worngtp->num != 0) {
printf("其中做错的题:\n");
showTestPaper(worngtp,0);
before:
printf("\n你是否重做做错的题目?\