用C语言编写“背单词 程序”

用C语言编写“背单词 程序”,第1张

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

struct word //定义一个word的结森李构体,里面的两个成员分别放英语单词和相应的汉语翻译

{

char chinese[20]

char english[20]

}

int point=0 //统计分数的

int count1=0 //测试的次数

void tianjia(struct word str[100],int &count) //函数声明,往词库中添加词组

void shuchu(struct word str[100],int &count) //函数声明,输出词库中所有的词组

void fanyi1(struct word str[100],int &count) //函数声明,输入汉语,对英语翻译的考察

void fanyi2(struct word str[100],int &count)

void chaxun(int point,int count1) //函数声明,输出成绩!

void main()

{

int count=0

struct word str[100] //定义一个结构体数组str

int n

char ch,chioch

while(1)

{

printf("*************背单词系统*********************\n")

printf("*************1,添加词库*********************\n")

printf("*************2,汉译英***********************\n")

printf("*************3,英译汉***********************\n")

printf("*************4,输出所有词库*****************\n")

printf("*************5,成绩查询*********************\滚拆n")

printf("*************0,退出*************************\n")

printf("********************************************\n")

printf("请输入你要经行的 *** 作:\n")

scanf("%d",&n)

switch(n)

{

case 1:tianjia(str,count)break //函数调用

case 2:fanyi1(str,count)break //函数调用

case 3:fanyi2(str,count)break //函数调用

case 4:shuchu(str,count)break

case 5:chaxun(point,count1)break //函数调大春枣用

case 0:{printf("你确认要退出吗?y/n!!\n")

scanf("%c%c",&ch,&chioch)

if(ch=='y'||ch=='Y') exit(0)

}

default :printf("你输入了错误的 *** 作,无法执行!!!")

exit(0)

}

}

}

void tianjia(struct word str[100],int &count)//往词库中添加词组

{

char ch

do{

printf("录入词库!!!\n")

printf("请输入词库中的英语单词:\n")

scanf("%s",str[count].english)

printf("\n请输入相应的中文意思:\n")

scanf("%s",str[count].chinese)

count++

printf("是否继续录入?y/n!!!\n")

scanf("%s",&ch)

}while(ch=='y')

printf("%d\n\n",count)

}

void shuchu(struct word str[100],int &count) // 输出词库中所有的词组

{

int i=0

printf("输出词库中所有的单词!!!\n")

if(count<=0) {printf("没有任何单词,无法输出!!!\n")return}

else {

for(i=0i<counti++){

printf("英文单词是:%s",str[i].english)

printf("\n相应的中文意思是:%s",str[i].chinese)

printf("\n\n")

}

printf("词库所有单词输入完毕!!!!\n")

}

}

void fanyi1(struct word str[100],int &count)//输入汉语,对英语翻译的考察

{

int i

char ch[20]

char bh[20]

printf("请输入英语单词:\n")

scanf("%s",ch)

printf("请输入翻译后的中文:\n")

scanf("%s",bh)

for(i=0i<counti++)

{

if(strcmp(ch,str[i].english)==0)

{

if(strcmp(bh,str[i].chinese)==0)

{

point++

count1++

printf("恭喜你!!答对了!!!\n")

}

else

{

count1++

printf("很遗憾,答错了!!!正确的翻译是:%s\n",str[i].chinese)

}

}

}

}

void fanyi2(struct word str[100],int &count) //输入英语,对汉语翻译的考察

{

int i

char ch[20]

char bh[20]

printf("请输入中文:\n")

scanf("%s",ch)

printf("请输入翻译后的英文:\n")

scanf("%s",bh)

for(i=0i<counti++)

{

if(strcmp(ch,str[i].chinese)==0)

{

if(strcmp(bh,str[i].english)==0){

point++

count1++

printf("恭喜你!!答对了!!!\n")

}

else

{

count1++

printf("很遗憾,答错了!!!正确的翻译是:%s\n",str[i].english)

}

}

}

}

void chaxun(int point,int count1)

{

printf("本次测试的成绩是:\n")

printf("总共:%d个\n",count1)

printf("正确:%d个\n",point)

// printf("正确率为:%d\%\n",point*100/count1)

}

这还不简单?

为每个单词设定一个索引值。

假设一共有100个单词吧?

使用rand()%100,就可以得到0-99之间的随机值了。

+1就是1—100之间培誉的随机值。

你先定义一个容量为200或更大的凳神数组,给他们全部用上述方法附上随机值。然后挨个读取就可以了。

至于具体代码要自己研究。注意:

1.要生成配粗段随机种子。srand((unsigned)time(0))否则总是生成同一个。

2.随机种子产生以此即可。

3.你还可以使用队列,挨个读取,还可以设定优先级,让经常错的优先级提高--这就算人工智能吧,呵呵。

http://zhidao.baidu.com/question/38052334.html


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12517106.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2025-08-25
下一篇2025-08-25

发表评论

登录后才能评论

评论列表(0条)

    保存