《单词本考试系统(c语言版).doc》由会员分享,可在线阅读,更多相关《单词本考试系统(c语言版).doc(8页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、 单词管理考试系统(链表、结构体、文本读取与保存)注意:请使用的同学替换程序中本人的姓名! 本程序仅供大家参考,亦可应付大学作业检查,谢谢 -陆鑫使用到的函数及其功能说明:(1)void initial(SLNode * head);初始化链表,从文本读取数据并且添加到链表。(2)void printallwords(SLNode * head);遍历链表并且打印。(3)void addnewwords(SLNode * head);添加新单词到链表并且写入到文本。(4)void deleteoldwords(SLNode * head)从链表中删除指定元素,并从文本中删除。(5)void e
2、nglishtest(SLNode * head)根据中文翻译英文测试,最后能计算出结果及正确率。(6)void chinesetest(SLNode * head)根据英文翻译中文测试,最后能计算出结果及正确率。(7)void rewrite(SLNode * head)在对文本进行修改时,通过调用此函数实现对文本的修改。2、源代码recite.c#include#include#include#includerecite.hvoid main()SLNode * head=NULL;int choice;init(&head);printf(+-欢迎使用-+n|n|n);printf(|t
3、 1.浏览全部单词 2.添加新单词3.删除已存在单词n);printf(|t 4.英文测试 5.中文测试6.退出程序n);printf(|ttttttt 制作者:陆鑫n);printf(|n+-欢迎使用-+nnn);while(1)scanf(%d,&choice);switch (choice)case 1:printallwords(head);break;case 2:addnewwords(head);break;case 3:deleteoldwords(head);break;case 4:englishtest(head);break;case 5:chinesetest(hea
4、d);break;case 6:exit6();return; break;default:printf(输入错误!n);break;printf(nt |n);printf(t | 1.浏览全部单词 2.添加新单词 3.删除已存在单词 |n);printf(t | 4.英文测试 5.中文测试 6.退出程序 |n);printf(t n);recite.htypedef struct nodechar english20;char chinese20;struct node * next;SLNode;int count=0;int flag=0;void rewrite(SLNode * h
5、ead)FILE * fp;SLNode * L=head;if (fp=fopen(English_vocabulary.txt,w)=NULL)putchar(7);printf(文件打开失败!n);exit(0);L=L-next-next;while(L!=NULL)fputs(L-english,fp);fputc(n,fp);fputs(L-chinese,fp);fputc(n,fp);L=L-next;void init (SLNode * head)FILE * fp;double nr_word=1,nr_explain=1;SLNode * L;(*head)=(SLNo
6、de*)malloc(sizeof(SLNode);(*head)-next=NULL;if (fp=fopen(English_vocabulary.txt,a+)=NULL)putchar(7);printf(文件打开失败!n);exit(0);while (nr_word0&nr_explain0)L=(SLNode*)malloc(sizeof(SLNode);nr_word=fscanf(fp,%s,&(L-english);nr_explain=fscanf(fp,%s,&(L-chinese);L-next=(*head)-next;(*head)-next=L;count+;i
7、f (count=1)flag=-1;fclose(fp);void printallwords(SLNode * head)SLNode * L=head;L=L-next-next;if (flag=-1)putchar(7);printf(tttt当前单词本为空!nn);return;while(L!=NULL)printf(tt%-10s:tt,L-english);printf(t%-10sn,L-chinese);L=L-next;printf(nn);void addnewwords(SLNode * head)FILE * fp;char eng20,chi20;SLNode
8、* L;flag=0;L=(SLNode*)malloc(sizeof(SLNode);if (fp=fopen(English_vocabulary.txt,a+)=NULL)putchar(7);printf(文件打开失败!n);return;printf(请输入需要添加的单词:);scanf(%s,eng);printf(请输入需要添加单词的中文:);scanf(%s,chi);strcpy(L-english,eng);strcpy(L-chinese,chi);fputs(eng,fp);fputc(n,fp);fputs(chi,fp);fputc(n,fp);L-next=hea
9、d-next-next;head-next-next=L;fclose(fp);void deleteoldwords(SLNode *head)SLNode * L=head;SLNode * P;char del_wor20;if (flag=-1)putchar(7);printf(ttt单词本为空!nn);return;L=L-next;printf(请输入您想要删除的单词:tt);scanf(%s,del_wor);while(L-next!=NULL)if (strncmp(del_wor,L-next-english,15)=0)P=L-next;L-next=L-next-ne
10、xt;free(P);printf(ttt删除成功!nn);rewrite(head);return;L=L-next;putchar(7);printf(nnttt无此单词!nnn);void englishtest( SLNode*head )SLNode * L=head;int error=0,total=0;char rule20,input20;L=L-next-next;if (flag=-1)putchar(7);printf(tttt当前单词本为空!nn);return;while(L!=NULL)total+;printf(t%10s:tt,L-chinese);strcp
11、y(rule,L-english);scanf(%s,input);if (strncmp(input,rule,15)!=0)putchar(7);error+;printf(ttttttt错误.n);L=L-next;printf(本次共测%d个单词,您错误%d个,准确率%.2f%nn,total,error,(float)(total-error)/total)*100);void chinesetest(SLNode * head)SLNode * L=head;int error=0,total=0;char rule20,input20;L=L-next-next;if (flag
12、=-1)putchar(7);printf(tttt当前单词本为空!nn);return;while(L!=NULL)total+;printf(t%10s:tt,L-english);strcpy(rule,L-chinese);scanf(%s,input);if (strncmp(input,rule,15)!=0)putchar(7);error+;printf(ttttttt错误.n);L=L-next;printf(本次共测%d个单词,您错误%d个,准确率%.2f%nn,total,error,(float)(total-error)/total)*100);void exit6()printf(tttt感谢您的使用!ttttn);截图