/*
(1)分别编辑中文和英文词库,可用两个数组存储;
(2)选择背诵的词库类型;
(3)显示中文时要求学生输入英文意思,并判断词义是否正确,如正确给以鼓励,如不正确给出提示并要求用户重新输入;显示英文时要求学生输入中文意思,并进行判断;
(4)统计并输出成绩。
*/
/*
1、选择英译汉
2、选择汉译英
3、选择添加单词
4、选择修改单词
*/
#include
#include
#include
#include
#include
#include
#include
int allcount=0;
#define SIZE 40
//准备闯关胜利图片
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;
}
}
//欢迎界面
void Welcome(){
system("mode con cols=80 lines=25 ");
middledisplay();
};
//用户选择1,给出英文说出它的中文
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");
}
//给出中文说英文意思
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");
}
//用户添加单词模块
void addword(struct word size[],int count){
int Count;
char eng[20];
char chi[20];
while (1){
cout << “请输入您要添加的单词个数:” << endl;
cin >> Count;
if (Count <= 96){
break;
}
else{
cout << “输入错误,您输入的数字必须小于96,请重输入单词的个数” << 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、让用户输入要添加的单词个数
·2、然后让用户输入单词的拥吻和中文
*/
//替换单词
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 << "个" <> 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;
}
}
//删除单词
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;
}
}
//菜单选择模块
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;
}