|
有会编程序的朋友吗?麻烦请进
这是写好的一个源程序吧,能把它变成可运行的软件吗?万分感谢!!!
英语单词测试小软件2009-08-04 22:39 今天突发奇想写了这么一个小软件,主要功能就是测试英语单词,事先将本章节的单词记录到任意一个文件中,以便随时进行英语单词侧测试,给出汉意写出英语答案,输入0为推出测试,完后给予评分,一下就是源代码,主要训练的就是文本函数的操作,相对而言没有什么复杂的算法,都是一些很容易理解的函数,就不做介绍,如果使用的cmd无法输入汉字开始->运行->reg add HKCU\console /v LoadConIme /t REG_DWORD /d 1 /f就可以了#define MAXWORD 100
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
typedef struct
{
char chinese[30];
char english[20];
}word;//一个单词
typedef struct
{
word danci[MAXWORD];
int line;
}group;//单词表
void openwordlist();//打开已经存在的单词表
void foundwordlist();//创建新的单词表
void amendword(char *);//修改单词
void deleteword(char *);//删除单词
void appendword(char *);//添加单词
void examination(char *);//对选中单词表单词进行测试
void putwordlist(char *);//将单词表输出
FILE *fp;
main()
{
char ch;
srand((unsigned)time(NULL));
printf("是否打开已存在的单词表?(y/n)\n");
fflush(stdin);
ch=getchar();
if(ch=='y'||ch=='Y')
openwordlist();
else if(ch=='n'||ch=='N')
{
printf("是否要构建新的单词表(y/n)?\n");
fflush(stdin);
ch=getchar();
if(ch=='n'||ch=='N')
{
printf("退出程序\n");
exit(1);
}
else if(ch=='Y'||ch=='y')
foundwordlist();
else
{
printf("输入错误程序退出");
exit(1);
}
}
else
printf("输入出错退出程序\n");
exit(1);
}
void openwordlist()//打开已经存在的单词表
{
char wordlistname[20],ch;
printf("请输入要打开的单词表的位置\n");
fflush(stdin);
scanf("%s",wordlistname);
system("cls");
while(1)
{
printf("请选择要进行的操作\n1.输出单词表\n2.修改一个单词\n3.删除一个单词\n4.添加一个单词\n5.对此单词表进行考试\n6.退出本程序\n");
fflush(stdin);
ch=getchar();
switch(ch)
{
case '1':system("cls"),putwordlist(wordlistname);break;//输出单词表
case '2':system("cls"),amendword(wordlistname);break;//修改一个单词
case '3':system("cls"),deleteword(wordlistname);break;//删除一个单词
case '4':system("cls"),appendword(wordlistname);break;//添加一个单词
case '5':system("cls"),examination(wordlistname);break;//考试
case '6':break;
default :system("cls"),printf("输入错误\n");
}
if(ch=='6')
break;
}
}
void foundwordlist()//新建单词表
{
group g;
char ch[30];
printf("请输入要创建的文件位置及名称\n");
fflush(stdin);
scanf("%s",ch);
if(!(fp=fopen(ch,"w")))
{
printf("文件创建失败\n");
exit(1);
}
printf("先输入汉意,再输入英语,汉意0表示结束输入\n");
g.line=0;
while(1)
{
printf("请输入第%d个单词的汉意\n",g.line+1);
fflush(stdin);
scanf("%s",g.danci->chinese);
if(!strcmp(g.danci->chinese,"0"))
break;
printf("请输入第%d个单词的英文\n",g.line+1);
fflush(stdin);
scanf("%s",g.danci->english);
fprintf(fp,"%-30s%-50s\n",g.danci->chinese,g.danci->english);
g.line++;
}
fclose(fp);
}
void amendword(char *wordlistname)//修改单词
{
group g;
char amend[30];
long offset;
int i;
if(!(fp=fopen(wordlistname,"r+")))
{
printf("打开文件失败,请检查输入文件路径正确性\n");
exit(1);
}
printf("请输入要修改的单词的汉意\n");
fflush(stdin);
scanf("%s",amend);
i=0;
while(!feof(fp))
{
offset=ftell(fp);
fscanf(fp,"%s%s\n",g.danci->chinese,g.danci->english);
if(!strcmp(g.danci->chinese,amend))
{
i=1;
break;
}
}
if(i)
{
printf("已经找到,记录为");
printf("%s %s",g.danci->chinese,g.danci->english);
printf("请输入新的汉意及英文\n");
fflush(stdin);
scanf("%s%s",g.danci->chinese,g.danci->english);
fseek(fp,offset,SEEK_SET);
fprintf(fp,"%-30s%-50s\n",g.danci->chinese,g.danci->english);
}
else
printf("对不起,单词表中未找到此单词");
fclose(fp);
}
void deleteword(char *wordlistname)//删除单词
{
group g;
char amend[30];
long offset;
int i;
if(!(fp=fopen(wordlistname,"r+")))
{
printf("打开文件失败,请检查输入文件路径正确性\n");
exit(1);
}
printf("请输入要删除的单词的汉意\n");
fflush(stdin);
scanf("%s",amend);
i=0;
while(!feof(fp))
{
offset=ftell(fp);
fscanf(fp,"%s%s\n",g.danci->chinese,g.danci->english);
if(!strcmp(g.danci->chinese,amend))
{
i=1;
break;
}
}
if(i)
{
printf("已经找到,记录为");
printf("%-30s%-50s",g.danci->chinese,g.danci->english);
fseek(fp,offset,SEEK_SET);
fprintf(fp,"%-30s%-50s\n","","");
}
else
printf("对不起,单词表中未找到此单词");
fclose(fp);
}
void appendword(char *wordlistname)//添加单词
{
group g;
if(!(fp=fopen(wordlistname,"a")))
{
printf("打开文件失败,请检查输入文件路径正确性\n");
exit(1);
}
printf("请输入要添加的汉意及英文\n");
fflush(stdin);
scanf("%s%s",g.danci->chinese,g.danci->english);
fprintf(fp,"%-30s%-50s\n",g.danci->chinese,g.danci->english);
fclose(fp);
}
void examination(char *wordlistname)//对选中单词表单词进行测试
{
group g;
int i,j,k,l;
char resule[30];
i=0;
if(!(fp=fopen(wordlistname,"r")))
{
printf("打开文件失败,请检查输入文件路径正确性\n");
exit(1);
}
while(!feof(fp))
fscanf(fp,"%s%s\n",g.danci[i].chinese,g.danci[i++].english);
g.line=i;
j=0;//计算成绩的
k=0;
printf("答案处输入'0'为退出考试\n");
while(1)
{
j++;
i=rand()%g.line;
printf("%s",g.danci[i].chinese);
fflush(stdin);
scanf("%s",resule);
if(!strcmp(resule,g.danci[i].english))
k++;
else if(!strcmp(resule,"0"))
{
j--;
break;
}
else
printf("抱歉输入错误正确答案是%s\n",g.danci[i].english);
}
l=k*100/j;
printf("一共测试了%d个单词,答对%d个,正确率为%d%c\n",j,k,l,37);
if(l<60)
printf("本课程单词掌握程度较差,请加强训练\n");
else if(l>60&&l<=99)
printf("本科单词大部分已经掌握,但还是有少许错误,请改正\n");
else
printf("您太棒了!满分\n");
printf("按任意键继续...\n");
getchar();
}
void putwordlist(char *wordlistname)//将单词表输出
{
group g;
if(!(fp=fopen(wordlistname,"r")))
{
printf("打开文件失败,请检查输入文件路径正确性\n");
exit(1);
}
fscanf(fp,"%s%s\n",g.danci->chinese,g.danci->english);
while(!feof(fp))
{
printf("%s %s ",g.danci->chinese,g.danci->english);
fscanf(fp,"%s%s\n",g.danci->chinese,g.danci->english);
}
printf("\n\n\n按任意键退出...\n");
fflush(stdin);
getchar();
fclose(fp);
}
[[i] 本帖最后由 logoslogos 于 2009-11-21 10:22 编辑 [/i]] |
|