C语言课设英语记单词本

我的C语言课程设计,记单词系统仅供参考学习


1.设计目的

  1. 巩固和加深学生对C语言课程的基本知识的理解和掌握;
  2. 掌握C语言编程和程序调试的基本技能;
  3. 利用C语言进行基本的软件设计;
  4. 掌握书写程序设计说明文档的能力
  5. 提高运用C语言解决实际问题的能力考

2.功能描述

2.1模块功能

2.1.1增添单词
2.1.2查询单词
2.1.3查看词库
2.1.4默写英文
2.1.5默写中文

2.2流程图

在这里插入图片描述

3.总体设计

3.1主菜单界面

#include<stdio.h>
void caidan();
int main()
{
 return 0;
}
void caidan()//打印菜单
{
    system("cls");
	printf("             ||* * * * * * * * * * * * * * * * * * * * * *《菜单》 * * * * * * * * * * * * * *  * * * * * * * * *||\n             ||                                                                                                  ||\n             ");
	printf("||                   1.添加新单词             2.默写中文            3.默写英文                      ||\n             ||                                                                                                  ||\n ");
	printf("            ||                   4.根据中文选择英文       5.根据英文选择中文    6.查看词库列表                  ||\n             ||                                                                                                  ||\n             ||                   7.查找单词               8.查看帮助            9.退出程序                      ||\n" ) ;
	printf("             ||                                                                                                  ||\n             ||                                                                                                  ||\n" ) ;

	printf("             ######################################################################################################\n\n");
	printf("                                              请选择操作(输入相应序号):");
}

3.2功能框架

代码如下(示例):

#include<stdio.h>
void caidan();//打印菜单
void addWord();//添加新单词
void insertWord();
void writeChinese();//默写中文
void writeEnglish();//默写英文
void chooseEbyC();//根据中文选英文
void chooseCbyE();//根据英文选中文
void lookWord();//查看词库列表
void searchWord();//查找单词
void help();//查看帮助
void goodBey();//退出程序
int main()
{
    int choice;
     readfile(&List);
    //scanf("%d",&choice);
while(1){
    caidan();
    scanf("%d",&choice);
    switch(choice){
    case 1:addWord();//添加新单词
        break;
    case 2:writeChinese();//默写中文
        break;
    case 3:writeEnglish();//默写英文
        break;
    case 4:chooseEbyC();//根据中文选英文
        break;
    case 5:chooseCbyE();//根据英文选中文
        break;
    case 6:lookWord();//查看词库列表
        break;
    case 7:searchWord();//查找单词
        break;
    case 8:help();//查看帮助
        break;
    case 9:goodBey();//退出程序
        break;

    }
    printf("是否继续操作(yes:1/no:0):");
    scanf("%d",&choice);
    if(choice==0)
        break;
}
    return 0;
}
void caidan()//打印菜单
{
system("cls");
	printf("             ||* * * * * * * * * * * * * * * * * * * * * *《菜单》 * * * * * * * * * * * * * *  * * * * * * * * *||\n             ||                                                                                                  ||\n             ");
	printf("||                   1.添加新单词             2.默写中文            3.默写英文                      ||\n             ||                                                                                                  ||\n ");
	printf("            ||                   4.根据中文选择英文       5.根据英文选择中文    6.查看词库列表                  ||\n             ||                                                                                                  ||\n             ||                   7.查找单词               8.查看帮助            9.退出程序                      ||\n" ) ;
	printf("             ||                                                                                                  ||\n             ||                                                                                                  ||\n" ) ;

	printf("             ######################################################################################################\n\n");
	printf("                                              请选择操作(输入相应序号):");
}
void addWord()//添加新单词
{
printf("添加新单词\n");
}
void writeChinese()//默写中文
{
printf("默写中文\n");
}
void writeEnglish()//默写英文
{
printf("默写英文\n");
}
void chooseEbyC()//根据中文选英文
{
printf("根据中文选英文\n");
}
void chooseCbyE()//根据英文选中文
{
printf("根据英文选中文\n");
}
void lookWord()//查看词库列表
{
printf("查看词库列表\n");
}
void searchWord()//查找单词
{
printf("查找单词\n");
}
void help()//查看帮助
{
printf("查看帮助\n");
}
void goodBey()//退出程序
{
printf("退出程序\n");
}


3.3结构体定义

typedef struct Node{
    char english[50];
    char chinese[50];
    struct Node *next;//结构体变量
}node;
node List;//链表

3.4功能函数

3.4.1文件读取函数

int readfile(node *L)//文件读取
{
    FILE *fp=fopen("ciku.txt","r");
    node wr;
    node *s;
    node *t=L;
    int num=0;
    if(fp==NULL){
        return 0;
    }else{
        while(fscanf(fp,"%s %s",wr.english,wr.chinese)!=EOF){
              s=(node*)malloc(sizeof(node));
              //printf("%s %s\n",wr.english,wr.chinese);
              *s=wr;
              t->next=s;
              t=s;
              t->next=NULL;
              num++                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ;
        }
    }
    return num;
}

3.4.2添加单词

void addWord()//添加新单词
{
    system("cls");
    node st;
    printf("请输入新增单词的相关信息\n");
    printf("英文:");
    scanf("%s",st.english);
    printf("中文:");
    scanf("%s",st.chinese);

    insertWord(&List,st);//将单词插入到链表尾部的函数
}
void insertWord(node *L,node e)
{
    node *h=L;
    node *s=(node*)malloc(sizeof(node));
    *s=e;
    s->next=h->next;
    h->next=s;
    saveFile(L);
}
//文件信息保存
int saveFile(node *L)
{
    FILE *fp=fopen("ciku.txt","w");
    if(fp==NULL){
        return 0;
    }
    node *p=L->next;
    while(p!=NULL){
        fprintf(fp,"%s %s\n",p->english,p->chinese);
        p=p->next;
    }
    return 1;

}

3.4.3默写中文

void writeChinese(node *L)//默写中文
{
    char ch[50];
    system("cls");
    node *p=L->next;
    while(p!=NULL){
    printf("请输入单词“%s”的中文:", p->english);
    scanf("%s",ch);
    if(strcmp(ch,p->chinese)==0){
        printf("\n恭喜你答对了!\n");
    }else{
        printf("你答错了!“%s”的中文是:“%s”",p->english,p->chinese);
    }
    p=p->next;
    printf("<回车下一题>");
            getchar();
            getchar();
            system("cls");
    }
    printf("已默写完全部单词!\n");
}

3.4.4默写英文

void writeEnglish(node *L)//默写英文
{
    char en[50];
    system("cls");
    node *p=L->next;
    while(p!=NULL){
    system("cls");
    printf("请输入单词“%s”的英文:", p->chinese);
    scanf("%s",en);
    if(strcmp(en,p->english)==0){
        printf("\n恭喜你答对了!\n");
    }else{
        printf("你答错了!“%s”的英文是:“%s”",p->chinese,p->english);
    }
    p=p->next;
    printf("<回车下一题>");
            getchar();
            getchar();
            system("cls");
    }
    printf("已默写完全部单词!\n");
}

3.4.5查看词库列表

void lookWord(node *L)//查看词库列表
{
    system("cls");
    node *p=L->next;
    while(p!=NULL)
    {
        printf("%s\t%s\t\n",p->english,p->chinese);
        p=p->next;//指针向后移动
    }
}

3.4.6查找单词

void searchWord(node *L)//查找单词
{
    system("cls");
    int choice=0;
    char en[50];
    char ch[50];
    node *st;
    printf("按英文查询--1\n");
    printf("按中文查询--2\n");
    printf("请输入查询方式:");
    scanf("%d",&choice);
    if(choice==1){
        printf("请输入要查询的英文:");
        scanf("%s",en);
        st=searchWordByE(en,L);
        if(st==NULL){
            printf("查无此单词!\n");
        }else{
            st=st->next;
            printf("%s\t%s\t\n",st->english,st->chinese);
        }
    }else if(choice==2){
        printf("请输入要查询的中文:");
        scanf("%s",ch);
        st=searchWordByC(ch,L);
        if(st==NULL){
            printf("查无此单词!\n");
        }else{
            st=st->next;
            printf("%s\t%s\t\n",st->english,st->chinese);
        }
}
//按英文查询
node *searchWordByE(char english[],node *L)
{
    node *p=L;
    while(p->next!=NULL){
        if(strcmp(english,p->next->english)==0){
            return p;
        }
        p=p->next;
    }
    return NULL;
}
//按中文查询
node *searchWordByC(char chinese[],node *L)
{
    node *p=L;
    while(p->next!=NULL){
        if(strcmp(chinese,p->next->chinese)==0){
            return p;
        }
        p=p->next;
    }
    return NULL;
}

3.4.7退出程序

void goodBey()//退出程序
{
    system("cls");
    printf("欢迎下次使用~\n");
    exit(0);
}

4.程序实现

4.1源代码

#include<stdio.h>
#include<windows.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
typedef struct Node{
    char english[50];
    char chinese[50];
    struct Node *next;//结构体变量
}node;
node List;//链表
void caidan();//打印菜单
void addWord();//添加新单词
void insertWord(node *L,node e);
void writeChinese(node *L);//默写中文
void writeEnglish(node *L);//默写英文
void chooseEbyC();//根据中文选英文
void chooseCbyE();//根据英文选中文
//产生随机数
int random(int number);
void lookWord(node *L);//查看词库列表
void searchWord(node *L);//查找单词
//按英文查询
node *searchWordByE(char english[],node *L);
//按中文查询
node *searchWordByC(char chinese[],node *L);
void help();//查看帮助
void goodBey();//退出程序
int readfile(node *L);//文件读取
int saveFile(node *L);//文件保存
int main()
{
    int choice;
     readfile(&List);
    //scanf("%d",&choice);
while(1){
    caidan();
    scanf("%d",&choice);
    switch(choice){
    case 1:addWord();//添加新单词
        break;
    case 2:writeChinese(&List);//默写中文
        break;
    case 3:writeEnglish(&List);//默写英文
        break;
    case 4:chooseEbyC(&List);//根据中文选英文
        break;
    case 5:chooseCbyE(&List);//根据英文选中文
        break;
    case 6:lookWord(&List);//查看词库列表
        break;
    case 7:searchWord(&List);//查找单词
        break;
    case 8:help();//查看帮助
        break;
    case 9:goodBey();//退出程序
        break;

    }
    printf("是否继续操作(yes:1/no:0):");
    scanf("%d",&choice);
    if(choice==0)
        break;
}
    return 0;
}
void caidan()//打印菜单
{
    system("cls");
	printf("             ||* * * * * * * * * * * * * * * * * * * * * *《菜单》 * * * * * * * * * * * * * *  * * * * * * * * *||\n             ||                                                                                                  ||\n             ");
	printf("||                   1.添加新单词             2.默写中文            3.默写英文                      ||\n             ||                                                                                                  ||\n ");
	printf("            ||                   4.根据中文选择英文       5.根据英文选择中文    6.查看词库列表                  ||\n             ||                                                                                                  ||\n             ||                   7.查找单词               8.查看帮助            9.退出程序                      ||\n" ) ;
	printf("             ||                                                                                                  ||\n             ||                                                                                                  ||\n" ) ;

	printf("             ######################################################################################################\n\n");
	printf("                                              请选择操作(输入相应序号):");
}
void addWord()//添加新单词
{
    system("cls");
    node st;
    printf("请输入新增单词的相关信息\n");
    printf("英文:");
    scanf("%s",st.english);
    printf("中文:");
    scanf("%s",st.chinese);

    insertWord(&List,st);//将单词插入到链表尾部的函数
}
void insertWord(node *L,node e)
{
    node *h=L;
    node *s=(node*)malloc(sizeof(node));
    *s=e;
    s->next=h->next;
    h->next=s;
    saveFile(L);
}
void writeChinese(node *L)//默写中文
{
    char ch[50];
    system("cls");
    node *p=L->next;
    while(p!=NULL){
    printf("请输入单词“%s”的中文:", p->english);
    scanf("%s",ch);
    if(strcmp(ch,p->chinese)==0){
        printf("\n恭喜你答对了!\n");
    }else{
        printf("你答错了!“%s”的中文是:“%s”",p->english,p->chinese);
    }
    p=p->next;
    printf("<回车下一题>");
            getchar();
            getchar();
            system("cls");
    }
    printf("已默写完全部单词!\n");
}
void writeEnglish(node *L)//默写英文
{
    char en[50];
    system("cls");
    node *p=L->next;
    while(p!=NULL){
    system("cls");
    printf("请输入单词“%s”的英文:", p->chinese);
    scanf("%s",en);
    if(strcmp(en,p->english)==0){
        printf("\n恭喜你答对了!\n");
    }else{
        printf("你答错了!“%s”的英文是:“%s”",p->chinese,p->english);
    }
    p=p->next;
    printf("<回车下一题>");
            getchar();
            getchar();
            system("cls");
    }
    printf("已默写完全部单词!\n");
}
void chooseEbyC(node *L)//根据中文选英文
{
    printf("根据中文选英文\n");
}
void chooseCbyE(node *L)//根据英文选中文
{
    printf("根据英文选中文\n");
}
void lookWord(node *L)//查看词库列表
{
    system("cls");
    node *p=L->next;
    while(p!=NULL)
    {
        printf("%s\t%s\t\n",p->english,p->chinese);
        p=p->next;//指针向后移动
    }
}
void searchWord(node *L)//查找单词
{
    system("cls");
    int choice=0;
    char en[50];
    char ch[50];
    node *st;
    printf("按英文查询--1\n");
    printf("按中文查询--2\n");
    printf("请输入查询方式:");
    scanf("%d",&choice);
    if(choice==1){
        printf("请输入要查询的英文:");
        scanf("%s",en);
        st=searchWordByE(en,L);
        if(st==NULL){
            printf("查无此单词!\n");
        }else{
            st=st->next;
            printf("%s\t%s\t\n",st->english,st->chinese);
        }
    }else if(choice==2){
        printf("请输入要查询的中文:");
        scanf("%s",ch);
        st=searchWordByC(ch,L);
        if(st==NULL){
            printf("查无此单词!\n");
        }else{
            st=st->next;
            printf("%s\t%s\t\n",st->english,st->chinese);
        }
}
}
void help()//查看帮助
{
    printf("查看帮助\n");
}
void goodBey()//退出程序
{
    system("cls");
    printf("欢迎下次使用~\n");
    exit(0);
}
int readfile(node *L)//文件读取
{
    FILE *fp=fopen("ciku.txt","r");
    node wr;
    node *s;
    node *t=L;
    int num=0;
    if(fp==NULL){
        return 0;
    }else{
        while(fscanf(fp,"%s %s",wr.english,wr.chinese)!=EOF){
              s=(node*)malloc(sizeof(node));
              //printf("%s %s\n",wr.english,wr.chinese);
              *s=wr;
              t->next=s;
              t=s;
              t->next=NULL;
              num++                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ;
        }
    }
    return num;
}
//文件信息保存
int saveFile(node *L)
{
    FILE *fp=fopen("ciku.txt","w");
    if(fp==NULL){
        return 0;
    }
    node *p=L->next;
    while(p!=NULL){
        fprintf(fp,"%s %s\n",p->english,p->chinese);
        p=p->next;
    }
    return 1;

}
//按英文查询
node *searchWordByE(char english[],node *L)
{
    node *p=L;
    while(p->next!=NULL){
        if(strcmp(english,p->next->english)==0){
            return p;
        }
        p=p->next;
    }
    return NULL;
}
//按中文查询
node *searchWordByC(char chinese[],node *L)
{
    node *p=L;
    while(p->next!=NULL){
        if(strcmp(chinese,p->next->chinese)==0){
            return p;
        }
        p=p->next;
    }
    return NULL;
}
//产生随机数
int random(int number)
{
    int magic;
    int num;
    num=readfile(&List);
    srand((unsigned)time(NULL));
    magic=rand()%num;
    return magic;
}

4.2运行结果

1.添加单词
在这里插入图片描述
2.默写中文
在这里插入图片描述
在这里插入图片描述
3.默写英文
在这里插入图片描述
在这里插入图片描述
4.查看词库
在这里插入图片描述
5.查找单词
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

6.退出程序
在这里插入图片描述

总结

大家看完文章会发现我根据中文选英文和根据英文选择的功能函数没有完成,大家可以尝试将其完成,也当作大家的c语言练习!

  • 5
    点赞
  • 73
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值