共有回帖数 0 个
-
#include stdio.h
#include conio.h
#include stdlib.h
#include time.h
#include math.h
#include "qipan.c"
struct users{
char id[20]; /*定义一个存放用户名,密码的结构体*/
char password[20];
};
struct test{
int i;
int num1; /*定义一个结构体用来存放产生的数字和运算符号*/
int num2;
int type;
};
char username[20]; /*定义一个全局变量用来存放用户的名称*/
/*错误提示开始*/
void error(char s[40]){
window(13,10,40,15);
textcolor(YELLOW);
textbackground(RED);
clrscr();
gotoxy(2,5);
cprintf("%s",s);
window(14,10,39,11);
textbackground(BLUE);
textcolor(YELLOW);
clrscr();
gotoxy(10,1);
cputs("error");
getch();
}
/*错误提示结束*/
/************开始界面*****************************************/
int hello(){
char i;
clrscr();
window(10,5,70,20); /*画一个方框背景颜色是绿色*/
textcolor(RED);
textbackground(LIGHTGREEN);
clrscr();
gotoxy(5,5);
cputs("1.login");
gotoxy(5,6);
cputs("2.reg");
gotoxy(5,7);
cputs("3.exit");
gotoxy(5,3);
textcolor(BLACK);
cputs("wlcome to use version1.0");
gotoxy(40,14);
cputs("copyright weiber");
gotoxy(5,9);
textcolor(BLUE);
cputs("input your choose:");
gets(i);
return(i);
}
/************开始界面结束*****************************************/
/************注册界面开始***************************************/
int login(){
FILE *fp;
char repassword[20];
struct users user;
window(10,5,70,20); /*画一个方框背景颜色是绿色*/
textcolor(RED);
textbackground(LIGHTGREEN);
clrscr();
gotoxy(18,3);
textcolor(BLACK);
cputs("wolcome to use");
gotoxy(10,6);
textcolor(BLUE);
cputs("input your id:");
gotoxy(4,8);
cputs("input your password:");
gotoxy(3,10);
cputs("again input password:");
gotoxy(24,6);
cscanf("%s",user.id);
gotoxy(24,8);
cscanf("%s",user.password);
gotoxy(24,10);
cscanf("%s",repassword);
if(strcmp(user.password,repassword)==0) /*如果正确的密码*/
{
fp=fopen("mima.txt","wb");
fwrite(&user,sizeof(struct users),1,fp);
fclose(fp);
clrscr();
gotoxy(20,5);
cputs("congratulate");
gotoxy(12,8);
textcolor(RED);
cputs("already logined press any key to go back");
getch();
return(1);
}
else /*如果错误的密码*/
{
clrscr();
gotoxy(23,5);
cputs("error");
gotoxy(12,11);
textcolor(RED);
error("the two password isn't equl");
getch();
return(0);
}
}
/************注册界面结束***************************************/
/************登陆的界面开始*************************************/
int reg(){
FILE *fp1;
struct users user1; /*定义的一个用来接收从文件里面id和Password的机构体变量*/
char uid[20];
char upass[20];
window(10,5,70,20); /*画一个方框背景颜色是绿色*/
textcolor(RED);
textbackground(LIGHTGREEN);
clrscr();
gotoxy(15,2);
cputs("reg the ware");
gotoxy(10,8);
cputs("id:");
gotoxy(4,9);
cputs("password:");
gotoxy(13,8);
cscanf("%s",uid); /*接收用户输入的id*/
gotoxy(13,9);
cscanf("%s",upass); /*接收用户输入的密码*/
fp1=fopen("mima.txt","rb");
fread(&user1,sizeof(struct users),1,fp1);
if(strcmp(user1.id,uid)==0&&strcmp(user1.password,upass)==0){
strcpy(username,user1.id);
return(1);
}
else{
error("wrong id and password"); getch();
return(0);
}
}
/************登陆的界面结束********************************************/
/************主菜单界面开始**********************************************/
int welcome(){
char a;
window(10,5,70,20); /*画一个方框背景颜色是绿色*/
textcolor(RED);
textbackground(LIGHTGREEN);
clrscr();
cprintf("%s welcome you!!",username);
gotoxy(24,2);
cputs("Menun");
gotoxy(8,5);
textcolor(BLACK);
cputs("1.");
textcolor(BLUE);
cputs("number test under 10(ten times a group)");
gotoxy(8,7); /*产生的菜单*/
textcolor(BLACK);
cputs("2.");
textcolor(BLUE);
cputs("number test under 50(ten times a group)");
gotoxy(8,9);
textcolor(BLACK);
cputs("3.");
textcolor(BLUE);
cputs("do the wrong before(ten times a group)");
gotoxy(8,11);
textcolor(BLACK);
cputs("4.");
textcolor(BLUE);
cputs("play games");
gotoxy(8,13);
textcolor(BLACK);
cputs("5.");
textcolor(BLUE);
cputs("exit the ware");
gotoxy(8,15);
textcolor(BLACK);
cputs("input your choose:");
gets(a);
return(a);
}
/************主菜单界面结束**********************************************/
/************产生随机数并运算******************************************/
void test(int temp){
struct test num; /*用来接收产生的数据的结构体变量*/
int right=0,wrong=0;
FILE *fp; /*用来保存错题的文件*/
char result;
int n=0,i;
window(10,5,70,20); /*画一个方框背景颜色是绿色*/
do{
n=n+1;
textcolor(RED);
textbackground(LIGHTGREEN);
clrscr();
srand(time(NULL));
num.num1=rand()%temp+1;
num.num2=rand()%temp+1; /*产生数据*/
num.type=rand()%4+1;
gotoxy(5,10);
cputs("result:");
gotoxy(5,5);
textcolor(BLUE);
switch(num.type)
{
case 1: cprintf("%d+%d=",num.num1,num.num2);num.i=num.num1+num.num2;break;
case 2: if(num.num1num.num2){i=num.num1;
num.num1=num.num2; /*如果num1num2将两者交换,保证米有负数*/
num.num2=i;}
cprintf("%d-%d=",num.num1,num.num2);num.i=num.num1-num.num2;break;
case 3: cprintf("%d*%d=",num.num1,num.num2);num.i=num.num1*num.num2;break;
case 4: num.i=num.num1*num.num2; i=num.num1; num.num1=num.i; num.i=i;
cprintf("%d/%d=",num.num1,num.num2);num.i=num.num1/num.num2;break; /*利用乘法的转换作除法保证答案为整数*/
default: break;
}
gets(result);
gotoxy(13,10);
if(atoi(result)==num.i)
{
right=right+1;
cprintf("right!");
}
if(atoi(result)!=num.i)
{ wrong=wrong+1; /*验证数据的准确性,如不正确就保存进文件*/
cprintf("wrong!");
fp=fopen("wrong.txt","ab");
fwrite(&num,sizeof(struct test),1,fp);
fclose(fp);
}
getchar();
}while(n!=10);
window(13,10,40,15);
textcolor(YELLOW);
textbackground(RED);
clrscr();
gotoxy(2,5);
cprintf("right:%d wrong:%d",right,wrong); /*给出10次的正确与错误的*/
window(14,10,39,11);
textbackground(BLUE);
textcolor(YELLOW);
clrscr();
gotoxy(10,1);
cputs("result");
getch();getch();
}
/************产生随机数并运算结束******************************************/
/*************错题重做开始********************************************/
void dowrong(){
FILE *fp;
char result;
struct test num;
int right=0,wrong=0;
int n=0,i;
fp=fopen("wrong.txt","rb");
window(10,5,70,20);
srand(time(NULL));
i=rand()%2;
if(i==1)i=2;
do{ /*画一个方框背景颜色是绿色*/
fseek(fp,n*sizeof(struct test),i);
fread(&num,sizeof(struct test),1,fp);
n=n+1;
textcolor(RED);
textbackground(LIGHTGREEN);
clrscr();
gotoxy(5,10);
cputs("result:");
gotoxy(5,5);
textcolor(BLUE);
switch(num.type)
{
case 1: cprintf("%d+%d=",num.num1,num.num2);break;
case 2: cprintf("%d-%d=",num.num1,num.num2);num.i=num.num1-num.num2;break;
case 3: cprintf("%d*%d=",num.num1,num.num2);num.i=num.num1*num.num2;break;
case 4: cprintf("%d/%d=",num.num1,num.num2);num.i=num.num1/num.num2;break;
default: break;
}
gets(result); /*接收用户的输入*/
gotoxy(13,10);
if(atoi(result)==num.i){
cprintf("right!"); /*判断是否正确*/
right=right+1;
}
else{
cprintf("wrong!");
wrong=wrong+1;
}
getch();
}while(n!=10); /*10次为一轮*/
window(13,10,40,15);
textcolor(YELLOW);
textbackground(RED);
clrscr();
gotoxy(2,5);
cprintf("right:%d wrong:%d",right,wrong); /*给出10次的正确与错误的*/
window(14,10,39,11);
textbackground(BLUE);
textcolor(YELLOW);
clrscr();
gotoxy(10,1);
cputs("result");
getch();
}
/*************错题重做结束********************************************/
/***********main函数开始**********************************************/
void main(){
int i,j,k;
do{
j=atoi(hello());
switch(j){
case 1:i=login();break; /*i来接受返回的值0为注册失败*/
case 2:k=reg();break; /*j来接受返回的值0为登陆失败*/
case 3: exit(0);break;
default: error("no choose"); break;
}
}while(k!=1||j!=1&&j!=2&&j!=3); /*如果选择的结果超出界限或者注册,登陆失败,从新返回菜单界面*/
;
do{ /*如果登陆成功则进行以下的操作*/
i=atoi(welcome());
switch(i){
case 1: test(10);break;
case 2: test(50);break;
case 3: dowrong();break;
case 4: break;
case 5: exit(0);
default: error("no choose");break;
}
}while(i!=4); /*调用欢迎界面*/
getchar();getchar();
}
/***********main函数结束**********************************************/
1、 小学数学学习系统
[问题描述]
具有随机出题、自动评分、查看正确答案、错题重做等功能的测试系统。
[设计要求]
(1) 设计程序运行界面
(2) 用户登录功能
(3) 能用菜单选择测试系统的各功能
楼主 2016-02-25 11:06 回复
Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号
意见反馈 |
关于直线 |
版权声明 |
会员须知