/*
(1) Edit the Chinese and English thesaurus separately, which can be stored in two arrays;
(2) Select the type of recitation thesaurus;
(3) Ask students to input the English meaning when displaying Chinese, and judge whether the meaning of the word is correct, if it is correct To encourage, if not correct, give a prompt and ask the user to re-enter; ask students to input Chinese meaning when displaying English, and make judgments;
(4) Statistics and output results.
*/
/*
1. Choose English to Chinese
2. Choose Chinese to English
3. Choose to add word
4. Choose to modify word
*/
#include<stdio.h>
#include
#include<Windows.h>
#include<stdlib.h>
#include
#include<graphics.h>
#include<conio.h>
int allcount=0;
#define SIZE 40
//Prepare to pass the victory picture
using namespace std;
struct word{
char Chinese[20];
char English[20];
};
void middledisplay(){
int Count;
int leftSpace;
int length;
int max = 0;
string menu[] = {
"----- 欢迎来到小聂带你学英语-----!",
" ",
" ",
"1、选择英译汉",
"2、选择汉译英",
"3、选择增加词汇",
"4、选择已经会了的词汇删除",
"5、选择替换单词",
"6、退出"
};
Count = sizeof(menu) / sizeof(menu[0]);
for (int i = 0; i < Count; i++){
if (max < menu[i].length()){
max = menu[i].length();
}
}
leftSpace = (80 - max) / 2;
for (int j = 0; j < Count; j++){
for (int i = 0; i < leftSpace; i++){
cout << " ";
}
cout << menu[j] << endl;
}
}
//Welcome interface
void Welcome(){ system("mode con cols=80 lines=25 ");
middledisplay();
};
//The user chooses 1, and gives it in English and speaks its Chinese
void chioce1(struct word Size[20]){ int score = 0; system("cls"); int i = 0; int k = 0;
char ch[20];
while (i < allcount){
cout << "请输入第" << i + 1 << "个单词的中文意思:" << Size[i].English << endl;
scanf_s("%s", &ch, sizeof(ch));
if (!strcmp(ch, Size[i].Chinese)){
cout << "第一次就答对了不错哦!" << endl;
i++;
score += 5;
Sleep(500);
system("cls");
}
else{
while (k < 3){
k++;
cout << "你错了,请重新输入该单词的中文意思:" << Size[i].English << endl;
scanf_s("%s", &ch, sizeof(ch));
if (!strcmp(ch, Size[i].Chinese)){
cout << "经过第" << k + 1 << "次你终于答对了" << endl;
score += 3;
i++;
Sleep(500);
system("cls");
break;
}
else if (k == 2){
k++;
i++;
cout << "对于这个单词你无可救药了,谈下一个单词" << endl;
Sleep(500);
system("cls");
break;
}
}
k = 0;
}
}
if (100 * score / allcount >= 60){
system("cls");
}
system("pause");
}
//Give Chinese and English meaning
void chioce2(struct word Size[20]){
int score = 0;
system("cls");
int i = 0;
int k = 0;
char ch[20];
while (i < allcount){
cout << "请输入第" << i + 1 << "个单词的中文意思:" << Size[i].Chinese << endl;
scanf_s("%s", &ch, sizeof(ch));
if (!strcmp(ch, Size[i].English)){
score += 5;
cout << "第一次就答对了不错哦!" << endl;
i++;
Sleep(500);
system("cls");
}
else{
while (k < 3){
k++;
cout << "你错了,请重新输入该单词的中文意思:" << Size[i].Chinese << endl;
scanf_s("%s", &ch, sizeof(ch));
if (!strcmp(ch, Size[i].English)){
score += 3;
cout << "经过第" << k + 1 << "次你终于答对了" << endl;
i++;
Sleep(500);
system("cls");
break;
}
else if (k == 2){
k++;
i++;
cout << "对于这个单词你无可救药了,谈下一个单词" << endl;
Sleep(500);
system("cls");
break;
}
}
k = 0;
}
}
if (100 * score / allcount >= 60){
system("cls");
}
system("pause");
}
//User add word module
void addword(struct word size[],int count){ int Count; char eng[20]; char chi[20]; while (1){ cout << "Please enter what you want to add Number of words: "<< endl; cin >> Count; if (Count <= 96){ break; } else{ cout << "Input error, the number you entered must be less than 96, please re-enter the number of words" << endl; Sleep(1000); system("cls");
}
}
for (int i = 0; i < Count; i++){
Sleep(100);
system("cls");
cout << "请输入该单词:" << endl;
cin >> eng;
cout << "请输入该单词的中文意思:" << endl;
cin >> chi;
strcpy_s(size[count+i].Chinese, 20, chi);
strcpy_s(size[count+i].English, 20, eng);
}
allcount = count + Count;
}
/*1, let the user enter the number of words to be added
·2, then let the user enter the kiss and Chinese of the word
*/
//Replace word
void change(struct word size[], int count){ char eng[20]; char chi[20];
int x;
//给用户预览单词
for (int i = 0; i < allcount - 1; i=i+6){
cout << i + 1 << ":" << size[i].Chinese << " " << size[i].English << " ";
cout << i + 2 << ":" << size[i+1].Chinese << " " << size[i+1].English << " ";
cout << i + 3 << ":" << size[i+2].Chinese << " " << size[i+2].English << " ";
cout << i + 4 << ":" << size[i+3].Chinese << " " << size[i+3].English << " ";
cout << i + 5 << ":" << size[i+4].Chinese << " " << size[i+4].English << " ";
cout << i + 6 << ":" << size[i+5].Chinese << " " << size[i+5].English << " ";
cout << endl;
}
while (1){
cout << "请输入您要替换的单词的个数:" << endl;
cin >> x;
if (x <=allcount){
break;
}
else{
cout << "输入的个数应该小于等于" << allcount << "个" <<endl<<"请重新输入"<< endl;
}
}
for (int i = 0; i < x;i++){
int which;
char tmpeng[20];
char tmpchi[20];
cout << "请输入您要修改的是哪一个" << endl;
cin >> which;
//输入合法性检查
while (1){
if (which > allcount){
cout << "无效输入,请重新输入" << endl;
}else{
break;
}
}
cout << "请输入修改中文意思:" << endl;
cin >> tmpchi;
cout << "请输入要修改的英文意思:" << endl;
cin >> tmpeng;
strcpy_s(size[which - 1].Chinese, 20, tmpchi);
strcpy_s(size[which - 1].English, 20, tmpeng);
}
system("cls");
for (int i = 0; i < allcount; i=i+6){
cout << i + 1 << ":" << size[i].Chinese << " " << size[i].English << " ";
cout << i + 2 << ":" << size[i + 1].Chinese << " " << size[i + 1].English << " ";
cout << i + 3 << ":" << size[i + 2].Chinese << " " << size[i + 2].English << " ";
cout << i + 4 << ":" << size[i + 3].Chinese << " " << size[i + 3].English << " ";
cout << i + 5 << ":" << size[i + 4].Chinese << " " << size[i + 4].English << " ";
cout << i + 6 << ":" << size[i + 5].Chinese << " " << size[i + 5].English << " ";
cout << endl;
}
}
//Delete word
void deleted(struct word size[], int count){ system("cls"); int x; int inttmp=allcount; int index;
char tmp[20] = { '\0' };
//让用户预览单词
for (int i = 0; i < allcount - 1; i = i + 6){
cout << i + 1 << ":" << size[i].Chinese << " " << size[i].English << " ";
cout << i + 2 << ":" << size[i + 1].Chinese << " " << size[i + 1].English << " ";
cout << i + 3 << ":" << size[i + 2].Chinese << " " << size[i + 2].English << " ";
cout << i + 4 << ":" << size[i + 3].Chinese << " " << size[i + 3].English << " ";
cout << i + 5 << ":" << size[i + 4].Chinese << " " << size[i + 4].English << " ";
cout << i + 6 << ":" << size[i + 5].Chinese << " " << size[i + 5].English << " ";
cout << endl;
}
while (1){
cout << "请输入你要删除的单词的个数:" << endl;
cin >> x;
if (x > allcount || x <= 0){
cout << "输入无效请重新输入:" << endl;
}
else{
break;
}
}
inttmp = allcount;
for (int i = 0; i < x; i++){
int which;
cout << "请输入你要删除哪一个单词:" << endl;
cin >> which;
which = which - (inttmp - allcount);
//which -= 1;
//合法性检查
cout << inttmp << endl;
while (1){
if (which > allcount || which <1){
cout << "输入无效请重新输入:" << endl;
cin >> which;
which = which - (inttmp - allcount);
//which -= 1;
}
else{
break;
}
}
//把第which个后的单词和但与意思往前推进一个,并把第which个的去掉,循环次数为allcount-which
index = allcount - which;
if (index == 0){
strcpy_s(size[allcount - 1].Chinese, 20, tmp);
strcpy_s(size[allcount - 1].English, 20, tmp);
allcount--;
}else {
for (int i = 0; i < index; i++){
strcpy_s(size[which - 1].Chinese, 20, size[which].Chinese);
strcpy_s(size[which - 1].English, 20, size[which].English);
which++;
}
strcpy_s(size[allcount - 1].Chinese, 20, tmp);
strcpy_s(size[allcount - 1].English, 20, tmp);
allcount--;
}
}
system("cls");
for (int i = 0; i < allcount - 1; i = i + 6){
cout << i + 1 << ":" << size[i].Chinese << " " << size[i].English << " ";
cout << i + 2 << ":" << size[i + 1].Chinese << " " << size[i + 1].English << " ";
cout << i + 3 << ":" << size[i + 2].Chinese << " " << size[i + 2].English << " ";
cout << i + 4 << ":" << size[i + 3].Chinese << " " << size[i + 3].English << " ";
cout << i + 5 << ":" << size[i + 4].Chinese << " " << size[i + 4].English << " ";
cout << i + 6 << ":" << size[i + 5].Chinese << " " << size[i + 5].English << " ";
cout << endl;
}
}
//Menu selection module
int menuchioce(){
Welcome();
int n = 0;
cout << "请用户选择功能项:" << endl;
cin >> n;
while (1){
if (n > 6){
cout << "输入无效,请重输入" << endl;
cin >> n;
}
else{
break;
}
}
return n;
}
int main(void){
//定义结构体数组并初始化
int count;
struct word Size[100] = { { "你好", "hello" }, { "随机", "rank" }, { "n狼人", "wolf" }, { "中国", "china" } };
//strcpy_s(Size[1].Chinese,20,"你好");
count = 4;
allcount = count;
//Welcome();
//addword(Size, count);
//cout << Size[4].Chinese<< Size[4].English << endl;
//change(Size, allcount);
//deleted(Size, allcount);
while (1){
int num;
num= menuchioce();
switch (num)
{
case 1:
chioce1(Size);
break;
case 2:
chioce2(Size);
break;
case 3:
addword(Size, allcount);
break;
case 4:
deleted(Size, allcount);
break;
case 5:
change(Size,allcount);
case 6:
return 0;
default:
cout << "输入错误请重输:" << endl;
break;
}
}
system("pause");
return 0;
}