C language implements English word helper
- 2020-06-19 11:23:20
- OfStack
English word small assistant steps for your reference, the specific content is as follows
Topic Requirement analysis:
English word assistant is to help students recite the word software, users can choose to recite the word library, and can edit their own word library, but also the word preview learning function. The system can provide Chinese and let the students input the meaning of the English word, or English and let the students input the meaning of the Chinese word, and determine whether the meaning is correct. If it is not correct, the user is prompted and asked to re-enter, if correct, bonus points.
According to the requirements of the topic, the basic functions of the system are as follows.
(1) Thesaurus maintenance: based on the file management, the Chinese and English meanings of words can be added, deleted and modified. Each record should include both English and Chinese meanings.
(2) Word preview: the system will display one record randomly and display the Chinese and English word meanings on the screen.
(3) Chinese-English word recitation: Randomly display Chinese words, users need to input the correct Meaning of English words to score. If the input is wrong, the user will be prompted to continue typing until the correct input.
(4) English and Chinese words recitation: Random Display of English words, users need to input the correct Meaning of Chinese words to score. If the input is wrong, the user will be prompted to continue typing until the correct input.
(5) Result query: display the statistics of English and English reciting learning results.
(6) Help: Understand the function and usage of the system through help.
(7) Exit: Exit the system.
Specific implementation:
/**
* @file chapter.cpp
* @brief English word assistant
* @version 1.0
* @author Jack
* @date 2018 years 9 month 6 day
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_CHAR 20 // The biggest character
#define MAX_NUM 200 // The maximum number of words
/**
* @Description The structure of a word
*/
struct word
{
char en[MAX_CHAR]; // The form in English
char ch[MAX_CHAR]; // Chinese form
} s[MAX_NUM]; // The word array
int num; // The number of words
int select = 1;// select A mark for whether to exit the system
int d = 0, c = 0;
/**
* @Description help
*/
void help()
{
printf("\n This system mainly realizes the Function of English word learning. Users can preview the words in the dictionary file , Adding, deleting, and revising. ");
printf("\n At the same time, the test can also be conducted in China and Britain. This system also provides the test result display function. ");
}
/**
* @Description Read the word information from the file
*/
void readfile()
{
FILE *fp;
int i = 0;
fp=fopen("data.txt", "r");
if(!fp)
{
printf("\n Open the file data.txt failure !");
}
while(fscanf(fp, "%s %s ", s[i].en, s[i].ch) == 2)
{
i++;
}
num = i;
if(0 == i)
printf("\n The file is empty , Please select Dictionary maintenance to add entries !");
else
printf("\n");
fclose(fp);
}
/**
* @Description The information that writes a word to a file
*/
void writefile()
{
FILE *fp;
int i = 0;
fp=fopen("data.txt", "w");
if(!fp)
{
printf("\n Open the file data.txt failure !");
}
for(i=0;i<num;i++)
{
fprintf(fp, "\n%s %s ", s[i].en,s[i].ch);
}
printf("\n");
fclose(fp);
}
/**
* @Description Sort by dictionary
*/
void sort()
{
int i,j;
char temp[MAX_CHAR];
for(i = 0;i < num - 1;i++)
{
for(j = num - 1;j > i;j--)
if(strcmp(s[j-1].en, s[j].en) > 0)
{
strcpy(temp, s[j-1].en);
strcpy(s[j-1].en, s[j].en);
strcpy(s[j].en, temp);
strcpy(temp, s[j-1].ch);
strcpy(s[j-1].ch, s[j].ch);
strcpy(s[j].ch, temp);
}
}
}
/**
* @Description Add word information
*/
void add()
{
int i=num,j,flag=1;
while(flag)
{
flag=0;
printf("\n Please enter the English form of the word :");
scanf("%s", s[i].en);
for(j = 0;j < i;j++)
if(strcmp(s[i].en, s[j].en) == 0)
{
printf(" The word already exists , Please check and retype !\n");
flag = 1;
break; /* Exit the layer loop immediately if there is a repeat , Improve judgment speed */
}
}
printf("\n Please enter the Chinese form of the word :");
scanf("%s", s[i].ch);
num++;
printf("\n The information you entered is : English : %s Chinese : %s ", s[i].en, s[i].ch);
sort();
}
/**
* @Description Delete word information
*/
void del()
{
int i = 0, j = 0;
char en[MAX_CHAR];// The form in English
printf("\n Please enter the English form of the word you want to delete :");
scanf("%s", en);
for(i = 0;i < num;i++)// First, find the sequence number corresponding to the English form
if(strcmp(s[i].en, en) == 0)
{
for(j = i;j < num - 1;j++)
s[j] = s[j+1];
num--;// Decrease in the number 1
return;
}
printf("\n There is no such word !");
}
/**
* @Description Modify word information
*/
void modify()
{
int i = 0, choose = 0, flag = 1;// chooses Represents the option identification, flag Is whether the word was found or not
char en[MAX_CHAR];// The form in English
while(flag||choose)
{
printf("\n Please enter the English form of the word you want to modify :");
scanf("%s", en);
for(i = 0;i < num;i++)// First, find the sequence number corresponding to the English form
if(strcmp(s[i].en, en) == 0)
{
printf("\n Please enter the correct English form of the word :");
scanf("%s", s[i].en);
printf("\n Please enter the correct Chinese form of this word :");
scanf("%s", s[i].ch);
printf("\n Continue to modify please select 1 A return of, 1 Please choose level 0:");
scanf("%d", &choose);
if(choose == 0)
return;
}
flag=0;
}
if(!flag)
printf("\n There is no such word !");
}
/**
* @Description The word preview
*/
void show()
{
int i = 0;
printf("\n Words: English Chinese ");
for(i = 0;i < num;i++)
printf("\n %-12s%-12s", s[i].en, s[i].ch);
}
/**
* @Description The query words
*/
void search()
{
int i = 0, choose = 0, flag = 1,status = 0;
printf(" Please enter the query mode (1. Press Chinese for enquiry 2. Enquiries in English ):");
scanf("%d", &status);
if(status == 1){
char ch[MAX_CHAR];// Chinese form
while(choose || flag)
{
printf("\n Please enter the Chinese form of the word you want to query :");
scanf("%s", ch);
for(i = 0;i < num;i++)// First, find the ordinal number corresponding to the Chinese form
{
while(strcmp(s[i].ch, ch) == 0)
{
printf("\n The form in English Chinese form ");
printf("\n %-12s%12s", s[i].en, s[i].ch);
i++;
}
}
printf("\n Please select to continue the query 1 A return of, 1 Please choose level 0:");
scanf("%d", &choose);
if(choose == 0)
return;
flag = 0;
}
if(!flag){
printf("\n There is no such word !");
}
}else{
char en[MAX_CHAR];// The form in English
while(choose || flag)
{
printf("\n Please enter the English form of the word you want to query :");
scanf("%s", en);
for(i = 0;i < num;i++)// First, find the sequence number corresponding to the English form
if(strcmp(s[i].en, en) == 0)
{
printf("\n The form in English Chinese form ");
printf("\n %-12s%12s", s[i].en, s[i].ch);
printf("\n Please select to continue the query 1 A return of, 1 Please choose level 0:");
scanf("%d", &choose);
if(choose == 0)
return;
}
flag = 0;
}
if(!flag){
printf("\n There is no such word !");
}
}
}
/**
* @Description Recite Chinese and English words
*/
void zytest()
{
char b1[20];
int z;
int choose = 1;
int i;
int t;
while(choose)
{
i = rand() % num;
printf("\n 【 %s Please enter English words :",s[i].ch);
scanf("%s",b1);
for(z = 0;strcmp(b1, s[i].en) != 0;z = z)
{
printf("\n Typo!! Please re-enter :");
scanf("%s", b1);
c = c + 1;
t = 0;
}
printf("\n Congratulations. Correct answer, Plus 10 points !\n\n");
d = d + 1;
if(t == 0){
printf(" The word I just misremembered is :%s, Please remember 1 time !", s[i].en);
}
printf("\n Please select to continue testing 1 A return of, 1 Please choose level 0:");
t = 1;
scanf("%d", &choose);
if(choose == 0)
return;
}
}
/**
* @Description Recite English and Chinese words
*/
void yztest()
{
char b1[20];
int z,x = 41;
int choose = 1;
int i;
i = rand() % num;
while(choose)
{
printf(" 【 %s Please enter the Chinese meaning :", s[i].en);
scanf("%s", b1);
for(z = 0;strcmp(b1, s[i].ch) != 0;z = z)
{
printf(" Typo!! Please re-enter :");
scanf("%s", b1);
c = c + 1;
}
printf("\n Congratulations. Correct answer, Plus 10 points !\n\n");
d = d + 1;
printf("\n Please select to continue testing 1 A return of, 1 Please choose level 0:");
scanf("%d", &choose);
if(choose == 0)
return;
}
}
/**
* @Description Result list
*/
void list()
{
printf("\n Total input error :%d time ** Each button 10 points **\n", c);
printf(" Total input correct :%d time ** Every time add 10 points **\n", d);
printf(" Your total score :%d points \n\n", 10 * d - 10 * c);
}
/**
* @Description Dictionary maintenance
*/
void maintain()
{
int choose;// Maintenance function selection
printf(" ------------------\n");
printf(" 1. Add words \n");
printf(" 2. Modify the word \n");
printf(" 3. Delete the word \n");
printf(" 4. The query words \n");
printf(" 5. Exit this menu \n");
printf(" ------------------\n");
while(1)
{
printf(" \n Please enter the maintenance function number :");
scanf("%d", &choose);
switch(choose)
{
case 1:
add();
writefile();
break;
case 2:
modify();
writefile();
break;
case 3:
del();
writefile();
break;
case 4:
search();
break;
case 5: return;
default:
printf("\n please 1-5 Choose between ");
}
}
}
/**
* @Description The user interface
*/
void menu()
{
int item;
printf("\n");
printf(" *********************************************************\n");
printf(" # #\n");
printf(" # English word assistant #\n");
printf(" # #\n");
printf(" # version : v1.0 #\n");
printf(" # #\n");
printf(" *********************************************************\n");
printf(" # #\n");
printf(" # 0. A thesaurus maintenance 1. The word preview #\n");
printf(" # #\n");
printf(" # 2. Recite the words ( Sino-British ) 3. Recite the words ( In the UK ) #\n");
printf(" # #\n");
printf(" # 4. The query results 5. help #\n");
printf(" # #\n");
printf(" # 6. Log out #\n");
printf(" # #\n");
printf(" *********************************************************\n");
printf("\n");
printf(" Please select the operation number you want (0-5) Press Enter to confirm :");
scanf("%d", &item);
printf("\n");
readfile();
switch(item)
{
case 0:
maintain();
break;
case 1:
show();
break;
case 2:
zytest();
break;
case 3:
yztest();
break;
case 4:
list();
break;
case 5:
help();
break;
case 6:
select = 0;
break;
default:
printf(" please 0-6 Choose between \n");
}
}
int main()
{
while(select)
{
menu();
}
system("pause");
return 0;
}