#include<stdio.h> /*库函数*/
#include<time.h> /*时间函数*/
long t1,t2;
int n;
main() /*主函数*/
{
int word();
int english();
int Class();
int c1();
int c2();
int c3();
int n;
textcolor(0); /*文本色*/
textbackground(1); /*背景色*/
clrscr();
gotoxy(28,8);
cprintf("dan zi lian xi an 1");
printf("\n");
gotoxy(28,10);
cprintf("ying wen lian xi an 2");
printf("\n");
gotoxy(28,12);
cprintf("wen zhang lian xi an 3");
printf("\n");
scanf("%d",&n);
switch(n) /*菜单选择*/
{
case 1:{clrscr();word();}break;
case 2:{clrscr();english();}break;
case 3:{clrscr();Class();};break;
}
getch();
} /*单字打字练习函数*/
int word()
{
char a[20],b[20];
int i; /*开始时间*/
t1=time(NULL); /*初始化随机数*/
srand(time(NULL));
for(i=0;i<20;i++)
{
a[i]=97+rand()%26; /*随机生成字母*/
printf("%c",a[i]);
b[i]=getch();
if(a[i]==b[i])
{
n++;
printf("%c\n",b[i]);
}
else
{
textcolor(4);
cprintf("%c",b[i]);
printf("\n");
}
}
t2=time(NULL); /*结束时间*/
printf("mei fen zhong da zi%d",60*n/((int) (t2-t1))); /*计算速度*/
}
int english() /*英文练习*/
{
char a[10][30],b[10][30];
int i,j,m;
t1=time(NULL);
srand(time(NULL));
for(j=0,i=1;j<10;j++,i+=2,gotoxy(1,i))
{
for(m=0;m<30;m++) {
a[j][m]=97+rand()%26;
cprintf("%c",a[j][m]);}
}
gotoxy(1,2);
for(j=0,i=1;j<10;j++,i+=2,gotoxy(1,i+1))
for(m=0;m<30;m++)
{
if((b[j][m]=getch())=='\n') /*判断是否换行*/
{
fflush(stdin);break;
}
if(b[j][m]==a[j][m])
{
n++;
printf("%c",b[j][m]);
}
else
{
textcolor(4);
cprintf("%c",b[j][m]);
}
}
t2=time(NULL);
printf("mei fen zhong da zi %d ge .",60*n/((int)(t2-t1)));
}
int Class() /*文章练习函数*/
{
int n; /*文章选择菜单*/
printf("1 A boy\n");
printf("2 lal\n");
printf("3 big head\n");
printf("qing xuan ze 1~3\n");
scanf("%d",&n);
switch(n)
{
case 1:{clrscr();c1();}break;
case 2:{clrscr();c2();}break;
case 3:{clrscr();c3();}break;
}
}
int c1() /*文章1函数*/
{
FILE *fp;
int a[200],b[200],i=0;
fp=fopen("A BOY.txt","r"); /*调用文件*/
while((a[i]=fgetc(fp))!=EOF) /*读取文件信息*/
{
printf("%c",a[i]);
i++;
}
gotoxy(1,1);
t1=time(NULL);
for(i=0;i<200;i++)
{
b[i]=getch();
if(a[i]==b[i])
{
textcolor(1); /*用蓝色输出正确结果*/
cprintf("%c",b[i]);
}
else
{
textcolor(4); /*用红色输出错误结果*/
cprintf("%c",a[i]);
}
}
fclose(fp);
t2=time(NULL);
printf("mei fen zhong da zi%d",60*n/((int) (t2-t1)));
}
int c2() /*文章2函数*/
{
FILE *fp;
int a[500],b[500],i=0;
fp=fopen("lal.txt","r");
while((a[i]=fgetc(fp))!=EOF)
{
printf("%c",a[i]);
i++;
}
gotoxy(1,1);
t1=time(NULL);
for(i=0;i<500;i++)
{
b[i]=getch();
if(a[i]==b[i])
{
textcolor(1);
cprintf("%c",b[i]);
}
else
{
textcolor(4);
cprintf("%c",a[i]);
}
}
fclose(fp);
t2=time(NULL);
printf("mei fen zhong da zi%d",60*n/((int) (t2-t1)));
}
int c3() /*文章3函数*/
{
FILE *fp;
int a[300],b[300],i=0;
fp=fopen("big head.txt","r");
while((a[i]=fgetc(fp))!=EOF)
{
printf("%c",a[i]);
i++;
}
gotoxy(1,1);
t1=time(NULL);
for(i=0;i<300;i++)
{
b[i]=getch();
if(a[i]==b[i])
{
textcolor(1);
cprintf("%c",b[i]);
}
else
{
textcolor(4);
cprintf("%c",a[i]);
}
}
fclose(fp);
t2=time(NULL);
printf("mei fen zhong da zi%d",60*n/((int) (t2-t1)));
}
在两位大哥的帮助下,我终于实现我的课题,哈哈,可惜还有个问题,怎么按esc键退出,并且在打字的时候按回车键不让它换行