c++实现计算机辅助教学英语

教学生学习英语

1、功能
1、有管理功能—可以增添、删除、修改、查看词汇的功能
2、能完成回答正确的判断,有等级设计
3、记录成功个数根据正确率确认是否晋级或者降级
4、可以根据单词判断词意 根据词意判断单词

2、代码
1、word.h//类的定义和头文件

#pragma once
#include<iostream>
#include<fstream>
#include<string>
#include<ctime>
#include<conio.h>
#include<Windows.h>
#define FILENAME1 "words.txt"//存储词汇
#define FILENAME2 "grade.txt"//存储等级
#define FILENAME3 "account.txt"//存储密码

#define object1 30//每一关的单词数量
#define object2 0.9//过关率 升级
#define object3 0.5//降级
using namespace std;
class word
{
public:
	//显示单词
	word(string a, string b , string c) {//单词 词意 类别
		Word = a;
		Meaning = b;
		Type = c;
	}
	word();
	word **CE_Words;//存储所有单词、短语

	int Num;//词汇数量(包括 单词 短语)

	~word();
public:
	void Init_Word();//初始化
	void Init_Num();//词汇的数量

private:
	string Word;//单词
	string Meaning;//词义
	string Type;//1  代表单词  2 代表词组  

public:
	//词汇设置
	void Add_Words();//添加

	void Del_Words();//删除

	void Mod_Words();//修改

	void Que_Words();//查找

	void Ope_Words();//操作设置

	void Set_Show();//设置界面

	void Save_Words();//保存

	void Show_Words();//显示

public:
	//学习操作

	void Start_Game();//开始学习

	void Continue_Game();//继续学习

	void Save_Game();//保存学习

	void Ope_Game();//操作

	void Menu_Game();//学习界面

	void Continue_Init();//获取等级

	void random(int a[]);//随机函数

	word **Grade_Words;//按等级存储词汇

	void Init_Grade_Num();//数量
	
	int Grade_Num;//等级词汇数量

	void Init_Game(int);//初始化

	void Show_Game();//显示

	void Start_Game_Words(int a[]);//单词

	void Start_Game_Mean(int a[]);//意思

	int grade;//等级

    bool judge = false;//判断是否是开始之后的继续学习

public:
	//登录

	void Acc_Game();//登录界面
	
	void Acc_Save();//保存

	void Acc_Init();//初始化

	string Password;//密码

	void Mod_Acc();//修改密码 

	string Judge_Acc();//判断密码

	bool Acc_Flag = false;//锁定判断

	int Acc_Num=3;//次数判断

	bool Judge_Pass=false;//判读之前是否登录成功

	void Exp_Game();//使用说明

};

2、word.cpp//具体功能实现

#include"word.h"
//局部颜色变化
void color(unsigned short color_index)
{
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color_index);
}
//初始化总单词
word::word()
{
	Init_Word();
}

word::~word() {}//构造函数

void word::Init_Word()//初始化
{
	fstream f;
	f.open(FILENAME1, ios::in | ios::out);
	if (!f.is_open())
	{
		cout << "文件打开失败..." << endl;
		return;
	}
	Init_Num();
	CE_Words = NULL;
	if (Num == 0)
	{
		cout << "文件为空...." << endl;
		return;
	}
	CE_Words = new word*[Num];//开辟大小为Num的空间
	word *rd;
	string w;
	string m;
	string a;
	int k = 0;
	int flag = 0;
	while (getline(f, w) && getline(f, m)&&getline(f,a))
	{
		//分三行   一行为单词  一行为词意  一行为判断
		rd = new word(w, m, a);//存入rd中
		CE_Words[k] = rd;//把rd中的值存入CE_Words中
		k++;
	}
	f.close();
}
//初始化单词数量
void word::Init_Num()//词汇的数量
{
	fstream f;
	f.open(FILENAME1, ios::in | ios::out);
	if (!f)
	{
		cout << "文件打开失败..." << endl;
		return;
	}
	
	string w;
	string m;
	string a;
	int k = 0;
	while (getline(f, w)&&getline(f, m)&&getline(f,a))
	{
		//分三行   一行为单词  一行为词意  一行为判断
		//	if (!(f >> a[k++]))
		//	break;
		k++;
	}
	Num = k;
	f.close();
}
//添加
void word::Add_Words()//添加
{
	while (1)
	{
		cout << "1、添加单词" << endl;
		cout << "2、添加词组" << endl;
		cout << "0、返回" << endl;
		cout << "输入你的选择:" << endl;
		string type;
		cin >> type;
		if (type == "0")
		{
			return;
		}
		if (type == "1")
		{
			cout << "添加形式如单词:empleeyer " << endl;
			cout << "词意:老板;雇主 (加分号为一个意思)" << endl;
		}
		cout << "输入你想填加的数量:" << endl;
		int number;
		cin >> number;
		word **Add_CE_Words = new word*[Num + number];
		for (int i = 0; i < Num; i++)
		{
			Add_CE_Words[i] = CE_Words[i];
		}
		word *rd;
		string w;
		string m;
		int j;
		for (int i = 0; i < number; i++)
		{
			bool n_flag = true;
			cout << "输入你想添加的第" << i + 1 << "个词汇的单词" << endl;
			if(i==0)
				cin.get();
			getline(cin, w);
			w += ".";
			if (w == ".") {
				cout << "请输入单词..." << endl;
				_getch();
				i--;
				n_flag = false;
			}
			if (n_flag) 
			{
				for ( j = 0; j < Num + i; j++)
				{
					if (Add_CE_Words[j]->Word == w)
					{
						cout << "已经存在此词汇,请重新输入..." << endl;
						_getch();
						system("cls");
						//n_flag = false;
						break;

					}
				}
				if (j != Num + i) {
					i--;
				}
				else 
				{
					cout << "输入你想添加的第" << i + 1 << "个词汇的词意" << endl;
					//	cin.get();
					getline(cin, m);
					m += ";";
					rd = new word(w, m, type);
					Add_CE_Words[Num + i] = rd;
					cout << "添加成功!" << endl << endl;
				}
			}
		}
		//删掉开辟的空间
		delete[]CE_Words;
		//重新赋值
		CE_Words = Add_CE_Words;
		Num += number;
		cout << "是否继续添加....(y/n)" << endl;
		char ch;
		cin >> ch;
		if (ch == 'n')
		{
			Save_Words();
			break;
		}
			
	}

}
//保存
void word::Save_Words()
{
	fstream f;
	f.open(FILENAME1, ios::in | ios::out);
	if (!f.is_open())
	{
		cout << "文件打开失败..." << endl;
		return;
	}
	//存入
	for (int i = 0; i < Num; i++)
	{
		f << CE_Words[i]->Word << endl;
		f << CE_Words[i]->Meaning << endl;
		f << CE_Words[i]->Type << endl;
	}
	f.close();
}
//删除
void word::Del_Words()//删除
{
	while (1)
	{
		string w;
		string m;
		string type;
		int n_t;
		cout << "1、输入你想删除的具体词汇的单词(注意中间空格):" << endl;
		cout << "2、从词汇表中选择删除的词汇:" << endl;
		cout << "0、返回" << endl;
		cin >> n_t;
		if (n_t == 2) {
			while (1)
			{
				system("cls");
				Show_Words();
				int t;
				cout << "输入你想选择删除的序号:" << endl;
				cin >> t;
				if (t > Num || t< 0) {
					cout << "选择超出范围!" << endl;
					cout << "请重新选择!" << endl;
					_getch();
				}
				else
				{
					cout << "原单词:" << CE_Words[t - 1]->Word << endl;
					cout << "原词意:" << CE_Words[t - 1]->Meaning << endl;
					cout << "原编号:" << CE_Words[t - 1]->Type << endl;
					//全部后移
					for (int i = t - 1; i < Num; i++)
					{
						CE_Words[i] = CE_Words[i + 1];
					}
					//数量减一
					Num--;
					cout << "删除成功!" << endl;
					system("pause");
					cout << "是否继续删除....(y/n)" << endl;
					char ch;
					cin >> ch;
					if (ch == 'n')
					{
						Save_Words();
						system("cls");
						break;
					}
				}
			}
		}
		else if (n_t == 1)
		{
			cout << "1、删除单词" << endl;
			cout << "2、删除词组" << endl;
			cout << "输入你的选择:" << endl;
			cin >> type;
			cout << "输入你想要修改的单词:" << endl;
			cin.get();
			getline(cin, w);
			w += ".";
			int j = -1;
			for (int i = 0; i < Num; i++)
			{
				if (CE_Words[i]->Word == w)
				{
					j = i;
				}
			}
			if (j == -1) {
				cout << "无此词汇..." << endl;
				system("pause");
				cout << endl << endl;
				cout << "是否重新删除...(y/n)" << endl;
				char ch;
				cin >> ch;
				if (ch == 'n')
					break;
				else
					system("cls");

			}
			else
			{//全部后移
				for (int i = j; i < Num; i++)
				{
					CE_Words[i] = CE_Words[i + 1];
				}
				//数量减一
				Num--;
				cout << "删除成功!" << endl;
				system("pause");
				cout << "是否继续删除....(y/n)" << endl;
				char ch;
				cin >> ch;
				if (ch == 'n')
				{
					Save_Words();
					break;
				}
			}
		}
		else 
			if (n_t == 0) {
			system("cls");
			return;
		}
			else
		{
			cout << "输入有误..." << endl;
			cout << "请重新输入..." << endl;
			_getch();
			system("cls");
		}
	}
}
//修改
void word::Mod_Words()//修改
{
	while (1)
	{
		string w;
		string m;
		string type;	
		int n_t;
		cout << "1、输入你想修改的具体词汇的单词(注意中间空格):" << endl;
		cout << "2、从词汇表中选择修改的词汇:" << endl;
		cout << "0、返回" << endl;
		cin >> n_t;
		if (n_t == 2) {
			while (1)
			{
				system("cls");
				Show_Words();
				int t;
				cout << "输入你想选择修改的序号:" << endl;
				cin >> t;
				if (t > Num||t< 0) {
					cout << "选择超出范围!" << endl;
					cout << "请重新选择!" << endl;
					_getch();				
				}
				else
				{
					cout << "原单词:" << CE_Words[t-1]->Word << endl;
					cout << "原词意:" << CE_Words[t-1]->Meaning << endl;
					cout << "原编号:" << CE_Words[t - 1]->Type << endl;
					word *rd;
					cout << "输入修改后的词汇单词:" << endl;
					cin.get();
					getline(cin, w);
					w += '.';
					cout << "输入修改后的词汇词意:" << endl;
					//cin.get();
					getline(cin, m);
					m += ';';
					cout << "输入修改后的词汇编号:" << endl;
					cin >> type;
					rd = new word(w, m, type);
					CE_Words[t-1] = rd;
					cout << "修改成功!" << endl;
					system("pause");
					cout << "是否继续修改....(y/n)" << endl;
					char ch;
					cin >> ch;
					if (ch == 'n')
					{
						Save_Words();//保存
						system("cls");
						break;
					}
				}
			}
		}
		else if(n_t==1)
		{
			cout << "1、修改单词" << endl;
			cout << "2、修改词组" << endl;
			cout << "输入你的选择:" << endl;
			cin >> type;
			if (type == "0")
			{
				return;
			}
			cout << "输入你想要修改的单词:" << endl;
			cin.get();
			getline(cin, w);
			w += ".";
			int j = -1;
			for (int i = 0; i < Num; i++)
			{
				if (CE_Words[i]->Word == w)
				{
					j = i;
				}
			}
			if (j == -1) {
				cout << "无此词汇..." << endl;
				system("pause");
				cout << endl << endl;
				cout << "是否重新修改....(y/n)" << endl;
				char ch;
				cin >> ch;
				if (ch == 'n')
					break;
				else
					system("cls");

			}
			else
			{
				cout << "原单词:" << CE_Words[j]->Word << endl;
				cout << "原词意:" << CE_Words[j]->Meaning << endl;
				cout << "原编号:" << CE_Words[j]->Type << endl;
				word *rd;
				cout << "输入修改后的词汇单词:" << endl;
				//cin.get();
				getline(cin, w);
				w += '.';
				cout << "输入修改后的词汇词意:" << endl;
				//cin.get();
				getline(cin, m);
				cout << "输入修改后的词汇编号:" << endl; 
				cin >> type;
				m += ';';
				rd = new word(w, m, type);
				CE_Words[j] = rd;
				cout << "修改成功!" << endl;
				system("pause");
				cout << "是否继续修改....(y/n)" << endl;
				char ch;
				cin >> ch;
				if (ch == 'n')
				{
					Save_Words();
					break;
				}
			}
		}
		else if (n_t == 0) {
			system("cls");
			return;
		}
	}
}
//查找
void word::Que_Words()//查找
{
	while (1)
	{
		cout << "1、按单词查找...." << endl;
		cout << "2、按词意查找...." << endl;
		cout << "0、返回...." << endl;
		int number;
		string wm;
		cin >> number;
		if (number == 0)
		{
			return;
		}
		if (number == 1)
		{
			cout << "输入你想查找的单词..." << endl;
			cin.get();
			getline(cin, wm);
			wm += ".";		
			int j = -1;
			for (int i = 0; i < Num; i++)
			{
				if (CE_Words[i]->Word==wm)
				{
					j = i;
				}
			}
			if (j == -1) {
				cout << "无此词汇..." << endl;
				system("pause");
				system("cls");
				cout << endl << endl;
				cout << "是否继续查找(y/n)..." << endl;
				char ch;
				cin >> ch;
				if (ch == 'n')
					break;
				else
				{
					//system("cls");
				}

			}
			else
			{
				cout << "单词为:" << CE_Words[j]->Word << endl;
				cout << "词意为:" << CE_Words[j]->Meaning << endl;
				system("pause");
				//system("cls");
				cout << "是否继续查找(y/n)..." << endl;
				char ch;
				cin >> ch;
				if (ch == 'n')
					break;
				else
				{
					system("cls");
				}

			}
		}
		else
			if (number == 2)
			{
				cout << "输入你想查找的单词词意..." << endl;
				cin.get();
				getline(cin, wm);
				wm += ";";
				int j = -1;
				int k = 0;
				int a[1024] = { 0 };
				for (int i = 0; i < Num; i++)
				{
					j = CE_Words[i]->Meaning.find(wm);
					if (j!=-1&&wm!=";;")
					{
						a[k++] = i;
					}
				}
				if (k == 0) {
					cout << "无此词汇..." << endl;
					system("pause");
					cout << endl << endl;
					cout << "是否继续查找(y/n)..." << endl;
					char ch;
					cin >> ch;
					if (ch == 'n')
						break;
					else
					{
						system("cls");
					}


				}
				else
				{
					for (int i = 0; i < k; i++)
					{
						cout << "单词为:" << CE_Words[a[i]]->Word << endl;
						cout << "词意为:" << CE_Words[a[i]]->Meaning << endl;
					}
					system("pause");
				//	system("cls");
					cout << "是否继续查找(y/n)..." << endl;
					char ch;
					cin >> ch;
					if (ch == 'n')
						break;
				}
			}
			else
			{
				cout << "输入错误 ..." << endl;
				system("pause");
				system("cls");
			}
	}
}
//显示
void word::Show_Words()//显示
{
	for (int i = 0; i < Num; i++)
	{
		cout << "序号:" << i + 1 << endl;
		cout << "单词:" << CE_Words[i]->Word << endl;
		cout << "词意:" << CE_Words[i]->Meaning << endl;
		cout << "编号:" << CE_Words[i]->Type << endl << endl;
	}
}
//操作词汇
void word::Ope_Words()//操作设置
{
	while (1)
	{
		Set_Show();
		int t;
		cin >> t;
		switch (t)
		{
		case 1:
			Add_Words();
			system("pause");
			system("cls");
			break;
		case 2:
			Mod_Words();
			system("pause");
			system("cls");
			break;
		case 3:
			Que_Words();
			system("pause");
			system("cls");
			break;
		case 4:
			Del_Words();
			system("pause");
			system("cls");
			break;
		case 5:
			Show_Words();
			system("pause");
			system("cls");
			break;
		case 0:
			system("cls");
			return;
		default:
			cout << "无此选项,请重新输入..." << endl;
			system("pause");
			system("cls");
			break;
		}
	}
}

void word::Set_Show()//设置界面
{
	cout << "\t\t------------------------" << endl;
	cout << "\t\t|		设置		  |" << endl;
	cout << "\t\t------------------------" << endl;
	cout << "\t\t|     1、添加词汇      |" << endl;
	cout << "\t\t------------------------" << endl;
	cout << "\t\t|     2、修改词汇      |" << endl;
	cout << "\t\t------------------------" << endl;
	cout << "\t\t|     3、查找词汇      |" << endl;
	cout << "\t\t------------------------" << endl;
	cout << "\t\t|     4、删除词汇      |" << endl;
	cout << "\t\t------------------------" << endl;
	cout << "\t\t|     5、显示词汇      |" << endl;
	cout << "\t\t------------------------" << endl;
	cout << "\t\t|     0、返回          |" << endl;
	cout << "\t\t------------------------" << endl;
	cout << "\t\t输入你的选择操作:" << endl << "\t\t";
}


//第一次继续初始化
void word::Continue_Init()
{
	fstream f;
	f.open(FILENAME2, ios::in | ios::out);
	if (!f.is_open())
	{
		cout << "文件打开失败..." << endl;
		return;
	}
//	judge = true;
	f >> grade;
	f.close();
}
//初始化数量
void word::Init_Grade_Num()//数量
{
	fstream f;
	f.open(FILENAME1, ios::in | ios::out);
	if (!f.is_open())
	{
		cout << "文件打开失败..." << endl;
		return;
	}
	string w;
	string m;
	string a;
	int k = 0;
	while ( getline(f, w) && getline(f, m) && getline(f, a))
	{
		int s = atoi(a.c_str());
		switch (grade)
		{
		case 1:
		case 2:
		case 3:
			if (s == 1)
				k++;
			break;
		case 4:
		case 5:
		case 6:
			if (s == 2)
				k++;
			break;
		case 7:
			k++;
			break;
		}

	}
	Grade_Num = k;
	f.close();
}
//初次初始化
void word::Init_Game(int index)//初始化
{
	fstream f;
	f.open(FILENAME1, ios::in | ios::out);
	if (!f.is_open())
	{
		cout << "文件打开失败..." << endl;
		return;
	}
	Init_Grade_Num();
	if (Grade_Num == 0)
	{
		cout << "文件为空..." << endl;
		return;
	}
	delete[] Grade_Words;
	Grade_Words = new word*[Grade_Num];
	string w;
	string m;
	string a;
	int k = 0;
	while (getline(f, w) && getline(f, m) && getline(f, a))
	{
			word *rd;
			//string转int
			int s = atoi(a.c_str());
			if (index==s||index==3) {
				rd = new word(w, m, a);
				Grade_Words[k] = rd;
				k++;
			}
	}
	f.close();
}
//随机词汇
void word::random(int a[])//随机函数
{
	
	int k = rand() % Grade_Num;
	a[0] = k;
	for (int i = 1; i < object1; )
	{
		int flag = 0;
		int k = rand() % Grade_Num;
		//去掉重复的数
		for (int j = 0; j < i; j++)
		{
			flag = 1;
			if (a[j] == k) {
				flag = 0;
				i--;
				break;
			}
		}
		if (flag) {
			a[i] = k;
		}
		i++;
	}
}

void word::Show_Game()//显示
{
	color(1);
	cout << "\t等级:" << grade << endl;
	switch (grade) {
	case 1:
		cout << "\t随机单词,填写词意(每次只能填一个)!" << endl;
		cout << "\t正确率达到90%或以上晋级....." << endl << endl;
		break;
	case 2:
		cout << "\t随机词意,填写单词(每次只能填一个)" << endl;
		cout << "\t正确率达到90%或以上晋级....." << endl << endl;
		break;
	case 3:
		cout << "\t随机单词或词意,填写单词或词意(每次只能填一个)" << endl;
		cout << "\t正确率达到90%或以上晋级....." << endl << endl;
		break;
	case 4:
		cout <<"\t随机词组,填写词意!(每次只能填一个)" << endl;
		cout << "\t正确率达到90%或以上晋级....." << endl << endl;
		break;
	case 5:
		cout << "\t随机词组词意,填写词组!(每次只能填一个)" << endl;
		cout << "\t正确率达到90%或以上晋级....." << endl << endl;
		break;
	case 6:
		cout << "\t随机词组或词意,填写词组或词意!(每次只能填一个)" << endl;
		cout << "\t正确率达到90%或以上晋级....." << endl << endl;
		break;
	case 7:
		cout << "\t所有词汇随机出现" << endl;
		cout << "\t进行分数记录(一次答对得一分,否则减一分)" << endl << endl;
		break;
	}
	color(6);
}

void word::Start_Game_Words(int a[])//单词
{
	string wm;
	random(a);
	int i;
	int flag = 1;
	float corret = 0;
	for (i = 0; i < object1; i++)
	{
	//背景音乐
		mciSendString(L"open clock.mp3", NULL, 0, 0);
		mciSendString(L"play clock.mp3", NULL, 0, 0);
		bool hint = true;//判断是否需要提示
		color(6);
		Show_Game();
		cout << "\n\n\t\t需要提示输入1(提示后视为回答错误)!" << endl;
		cout << "\t\t单词:" << Grade_Words[a[i]]->Word  << endl << "\t\t词意:";	
		color(7);
		getline(cin, wm);
		wm += ";";
		if (wm == "1;") {
			hint = false;
			cout << "\t\t词意:" << Grade_Words[a[i]]->Meaning << endl;
		}
		if (hint)
		{
			if (Grade_Words[a[i]]->Meaning.find(wm) != -1 && wm != ";;"&&wm != ";")
			{
				corret += flag;
				flag = 1;
				color(2);
				cout << "\t\t正确!" << endl;
				_getch();
				system("cls");
			}
			else
			{
				flag = 0;
				i--;
				color(4);
				cout << "\n\n\t\t错误!请重新输入....\n" << endl;
				_getch();
				system("cls");
			}
		}
		else
		{
			flag = 0;
			i--;
			_getch();
			system("cls");
		}
		//关掉音乐
		mciSendString(L"close clock.mp3", NULL, 0, 0);
	}
		if (float(corret / object1) > object2) {
			mciSendString(L"open 掌声.mp3", NULL, 0, 0);
			mciSendString(L"play 掌声.mp3", NULL, 0, 0);
			grade++;
			color(1);
			float choose = (corret / object1) * 100;
			cout << "\n\n\t\t正确率为:" << choose << "%" << endl;
			cout << "\t\t等级加一..." << endl;
			cout << "\t\t现在等级为:" << grade << "级" << endl << "\t\t";
			_getch();
			//system("cls");
			mciSendString(L"close 掌声.mp3", NULL, 0, 0);
		}
		else
		{
			mciSendString(L"open call.mp3", NULL, 0, 0);
			mciSendString(L"play call.mp3", NULL, 0, 0);
			color(3);
			float choose = (corret/object1);
			if (choose <= object3) {
				cout << "\n\n\t\t正确率为:" << choose * 100 << "%" << endl;
				cout << "\t\t等级减一:" << endl;
				grade--;
				if (grade < 1) {
					grade = 1;
				}
				cout << "\t\t现在等级为:" << grade << "级" << endl << "\t\t";
				_getch();
			}
			else
			{
				cout << "\n\n\t\t正确率为:" << choose * 100 << "%" << endl;
				cout << "\t\t未达到标准!(继续加油)" << endl;
				cout << "\t\t请再接再厉!(等级不变)" << endl << "\t\t";
				//system("pause>nul");
				_getch();
			}
			mciSendString(L"close call.mp3", NULL, 0, 0);
		}
}

void word::Start_Game_Mean(int a[])//意思
{
	string wm;
	random(a);
	int i;
	int flag = 1;
	float corret = 0;	
	for (i = 0; i < object1; i++)
	{
		mciSendString(L"open clock.mp3", NULL, 0, 0);
		mciSendString(L"play clock.mp3", NULL, 0, 0);
		color(6);
		bool hint = true;
		Show_Game();
		cout << "\n\n\t\t需要提示输入1(提示后视为回答错误)!" << endl;
		cout << "\t\t词意:" << Grade_Words[a[i]]->Meaning << endl<<"\t\t单词:";
		color(7);
		getline(cin, wm);
		wm += ".";
		if (wm == "1.") {
			hint = false;
			cout << "\t\t单词:" << Grade_Words[a[i]]->Word << endl;
		}
		if (hint)
		{
			if (wm == Grade_Words[a[i]]->Word) {
				corret += flag;
				flag = 1;
				color(2);
				cout << "\t\t正确!" << endl;
				_getch();
				system("cls");
			}
			else if (wm != Grade_Words[a[i]]->Word)
			{
				int st = 0;
				for (; st < Grade_Num; st++) {
					if (wm == Grade_Words[st]->Word) {
					
						corret += flag;
						flag = 1;
						color(2);
						cout << "\t\t正确!" << endl;
						_getch();
						system("cls");
						break;
					}
				}
				if (st == Grade_Num) {
					flag = 0;
					i--;
					color(4);
					cout << "\t\t错误!请重新输入...." << endl;
					_getch();
					system("cls");
				}
			}
		}
		else
		{
			i--;
			flag = 0;
			_getch();
			system("cls");
		}
		mciSendString(L"close clock.mp3", NULL, 0, 0);
	}
	if (float(corret / object1) > object2) {
		mciSendString(L"open 掌声.mp3", NULL, 0, 0);
		mciSendString(L"play 掌声.mp3", NULL, 0, 0);
		grade++;
		color(1);
		float choose = (corret / object1) * 100;
		cout << "\n\n\t\t正确率为:" << choose << "%" << endl;
		cout << "\t\t等级加一..." << endl;
		cout << "\t\t现在等级为:" << grade << "级" << endl << "\t\t";
		_getch();
		mciSendString(L"close 掌声.mp3", NULL, 0, 0);
	}
	else
	{
		color(3);
		float choose = (corret / object1);
		mciSendString(L"open call.mp3", NULL, 0, 0);
		mciSendString(L"play call.mp3", NULL, 0, 0);
		if (choose <= object3) {
			cout << "\n\n\t\t正确率为:" << choose * 100 << "%" << endl;
			cout << "\t\t等级减一:" << endl;
			grade--;
			if (grade < 1) {
				grade = 1;
			}
			cout << "\t\t现在等级为:" << grade  << "级" << endl << "\t\t";
			_getch();
		}
		else
		{
			cout << "\n\n\t\t正确率为:" << choose * 100 << "%" << endl;
			cout << "\t\t未达到标准!(继续加油)" << endl;
			cout << "\t\t请再接再厉!(等级不变)" << endl << "\t\t";
			_getch();
		}
		mciSendString(L"close call.mp3", NULL, 0, 0);
	}
}

void word::Start_Game()//开始学习
{

	color(6);
	judge = true;
	cout << "\t\t初始等级为:1" << endl;
	cout << "\t\t一级:随机单词,填写词意。" << endl;
	cout << "\t\t正确率达到90%或以上晋级....." << endl;
	cout << "\t\tNow,English Word Study .... " << endl << "\t\t";
	grade = 1;
	Grade_Words = new word*[2];
	string wm;
	cout << "\n\t\t现在是否开始答题...(输入n退出,其他继续)" << endl << "\t\t";
	cin.get();//吸收"\n"
	getline(cin, wm);
	if (wm == "n") {
		system("cls");
		return;
	}
	else
	{
		system("cls");
	}
	int i;
	while (1)
	{
		mciSendString(L"open auther.mp3", NULL, 0, 0);
		mciSendString(L"play auther.mp3", NULL, 0, 0);
		float corret = 0;//第一次正确的个数
		int flag = 1;
		if (grade == 1 ) {
			Init_Game(1);
		}
		else 
			if (grade == 4 ) {
			Init_Game(2);
		}
		else
			if(grade==7)
		{
			Init_Game(3);
		}
		int a[object1];
		random(a);
		switch (grade)
		{
		case 1:
		case 4:	
			Start_Game_Words(a);
			break;
		case 2:
		case 5:	
			Start_Game_Mean(a);
			break;
		case 3:
		case 6:
		case 7:	
			for ( i = 0; i < object1; i++)
			{
				mciSendString(L"open clock.mp3", NULL, 0, 0);
				mciSendString(L"play clock.mp3", NULL, 0, 0);
				color(6);
				Show_Game();
				int j = rand() % 2;
				if (j == 1)
				{
					cout << "\t\t单词:" << Grade_Words[a[i]]->Word << endl<<"\t\t词意:";
					color(7);
					getline(cin, wm);
					wm += ";";
					if (Grade_Words[a[i]]->Meaning.find(wm) != -1 && wm != ";;"&&wm != ";") {
					
						corret += flag;
						flag = 1;
						color(2);
						cout << "\t\t正确!" << endl;
						_getch();
						system("cls");						
					}
					else
					{
						flag = 0;
						i--;
						color(4);
						cout << "\t\t错误!请重新输入...." << endl;
						_getch();
						system("cls");
					}						
				}
				else
				{
					cout << "\t\t词意:" << Grade_Words[a[i]]->Meaning << endl << "\t\t单词:";
					color(7);
					getline(cin, wm);
					wm += ".";
					if (Grade_Words[a[i]]->Word==wm) {						
						corret += flag;
						flag = 1;
						color(2);
						cout << "\t\t正确!" << endl;
						_getch();
						system("cls");						
					}
					else if (wm != Grade_Words[a[i]]->Word)
					{
						int st = 0;
						for (; st < Grade_Num; st++) {
						
							if (wm == Grade_Words[st]->Word) {
								corret += flag;
								flag = 1;
								color(2);
								cout << "\t\t正确!" << endl;
								_getch();
								system("cls");							
								break;
							}
						}
						if (st == Grade_Num) {
							flag = 0;
							i--;
							color(4);
							cout << "\t\t错误!请重新输入...." << endl;
							_getch();
							system("cls");
						}
					}
				}
				mciSendString(L"close clock.mp3", NULL, 0, 0);
			}
			if (float(corret / object1) > object2 && grade<7) {
				mciSendString(L"open 掌声.mp3", NULL, 0, 0);
				mciSendString(L"play 掌声.mp3", NULL, 0, 0);
				grade++;
				color(1);
				float choose = (corret / object1) * 100;
				cout << "\t\t正确率为:" << choose << "%" << endl;
				cout << "\t\t等级加一..." << endl;
				cout << "\t\t现在等级为:" << grade << "级" << endl << "\t\t";
				_getch();
				system("cls");
				//关闭
				mciSendString(L"close 掌声.mp3", NULL, 0, 0);
			}
			else if(grade<7)
			{
				mciSendString(L"open call.mp3", NULL, 0, 0);
				mciSendString(L"play call.mp3", NULL, 0, 0);
				color(3);
				float choose = (corret / object1);
				if (choose <= object3) {
					cout << "\t\t正确率为:" << choose * 100<< "%" << endl;
					cout << "\t\t等级减一:" << endl;
					grade--;
					if (grade < 1) {
						grade = 1;
					}
					cout << "\t\t现在等级为:" << grade << "级" << endl << "\t\t";
					_getch();
				}
				else
				{
					cout << "\t\t正确率为:" << choose * 100<< "%" << endl;
					cout << "\t\t未达到标准!(继续加油)" << endl;
					cout << "\t\t请再接再厉!(等级不变)" << endl << "\t\t";
					_getch();
				}
				mciSendString(L"open call.mp3", NULL, 0, 0);
			}
			else
			{
				color(7);
				cout << "\n\n\t\t恭喜通关....." << endl << "\t\t";
				_getch();
			}
			break;
		}
		color(6);
		cout << "\n\n\t\t现在是否继续答题...(输入n退出,其他继续)" << endl << "\t\t";	
		getline(cin, wm);
		if (wm == "n") {
			cout << "\t\t是否进行保存...(y/n)" << endl << "\t\t";
			getline(cin, wm);
			if (wm == "y")
			{
				Save_Game();
				cout << "\t\t保存成功!" << endl;
				_getch();
			}
			system("cls");
			return;
		}
		else
		{
			system("cls");
		}
		mciSendString(L"close auther.mp3", NULL, 0, 0);
	}

}

void word::Continue_Game()//继续学习
{
	color(6);
	if (!judge)
	{
		Continue_Init();
		Grade_Words = new word*[2];
	}
	judge = true;
	string wm;
	cout << "\n\t\t现在等级为" << grade << "级" << endl;
	cout << "\n\t\t现在是否继续答题...(输入n退出,其他继续)" << endl << "\t\t";
	cin.get();
	getline(cin, wm);
	if (wm == "n") {
		system("cls");
		return;
	}
	else
	{
		system("cls");
	}
	int i;
	if (grade>=1&&grade<=3) {
		Init_Game(1);
	}
	else
		if (grade >= 4 &&grade<=6) {
			Init_Game(2);
		}
		else
			if (grade >= 7)
			{
				Init_Game(3);
			}
	while (1)
	{
		float corret = 0;//第一次正确的个数
		int flag = 1;
		if (grade == 1) {
			Init_Game(1);
		}
		else
			if (grade == 4) {
				Init_Game(2);
			}
			else
				if (grade == 7)
				{
					Init_Game(3);
				}
		int a[object1];
		random(a);
		switch (grade)
		{
		case 1:
		case 4:
			Start_Game_Words(a);
			break;
		case 2:
		case 5:
			Start_Game_Mean(a);
			break;
		case 3:
		case 6:
		case 7:
			for (i = 0; i < object1; i++)
			{
				color(6);
				Show_Game();
				int j = rand() % 2;
				if (j == 1)
				{
					cout << "\t\t单词:" << Grade_Words[a[i]]->Word << endl << "\t\t词意:";
					color(7);
					getline(cin, wm);
					wm += ";";
					if (Grade_Words[a[i]]->Meaning.find(wm) != -1 && wm != ";;"&&wm != ";") {
						corret += flag;
						flag = 1;
						color(2);
						cout << "\t\t正确!" << endl;
						_getch();
						system("cls");
					}
					else
					{
						flag = 0;
						i--;
						color(4);
						cout << "\t\t错误!请重新输入...." << endl;
						_getch();
						system("cls");
					}
				}
				else
				{
					cout << "\t\t词意:" << Grade_Words[a[i]]->Meaning << endl << "\t\t单词:";
					color(7);
					getline(cin, wm);
					wm += ".";
					if (Grade_Words[a[i]]->Word == wm) {
						corret += flag;
						flag = 1;
						color(2);
						cout << "\t\t正确!" << endl;
						_getch();
						system("cls");
					}
					else if (wm != Grade_Words[a[i]]->Word)
					{
						int st = 0;
						for (; st < Grade_Num; st++) {
							if (wm == Grade_Words[st]->Word) {
								corret += flag;
								flag = 1;
								color(2);
								cout << "\t\t正确!" << endl;
								_getch();
								system("cls");
								break;
							}
						}
						if (st == Grade_Num) {
							flag = 0;
							i--;
							color(4);
							cout << "\t\t错误!请重新输入...." << endl << "\t\t";
							_getch();
							system("cls");
						}

					}

				}
			}

			if (float(corret / object1) > object2 && grade<7) {
				grade++;
				color(1);
				float choose = (corret / object1) * 100;
				cout << "\t\t正确率为:" << choose << "%" << endl;
				cout << "\t\t等级加一..." << endl;
				cout << "\t\t现在等级为:" << grade << "级" << endl << "\t\t";
				//system("pause");
				_getch();
				system("cls");
				color(6);
			}
			else if (grade<7)
			{
				color(3);
				float choose = (corret / object1) * 100;
				cout << "\t\t正确率为:" << choose << "%" << endl;
				cout << "\t\t未达到标准!" << endl;
				cout << "\t\t请再接再厉!" << endl << "\t\t";
				//system("pause");
				_getch();
				system("cls");
				color(6);
			}
			else
			{
				color(7);
				cout << "\n\n\t\t恭喜通关....." << endl << "\t\t";
				//system("pause");
				_getch();
				color(6);
			}

			break;
		}
		cout << "\n\n\t\t现在是否继续答题...(输入n退出,其他继续)" << endl << "\t\t";
		getline(cin, wm);
		if (wm == "n") {
			cout << "\n\n\t\t是否进行保存...(y/n)" << endl;
			getline(cin, wm);
			if (wm == "y") {
				Save_Game();
				cout << "\t\t保存成功!" << endl;
				_getch();
			}
			system("cls");
			return;
		}
		else
		{
			system("cls");
		}
	}

}

void word::Save_Game()//保存学习
{
		fstream f;
		f.open(FILENAME2, ios::in | ios::out);
		if (!f.is_open())
		{
			cout << "文件打开失败..." << endl;
			return;
		}
		f << grade;
		f.close();
}

void word::Ope_Game()//操作
{
	Menu_Game();
	int t;
	cin >> t;
	switch (t)
	{
	case 1:
		system("cls");
		Start_Game();
		break;
	case 2:
		system("cls");
		Continue_Game();
		break;
	case 3:
		system("cls");
		return;
	case 0:
		system("cls");
		cout << "\n\n\t\t欢迎下次使用..." << endl << "\t\t";
		system("pause");
		exit(0);
		break;
	}
}

void word::Menu_Game()
{
		cout << "\t\t------------------------" << endl;
		cout << "\t\t|欢迎进入英语学习系统!|" << endl;
		cout << "\t\t------------------------" << endl;
		cout << "\t\t|     1、开始练习      |" << endl;
		cout << "\t\t------------------------" << endl;
		cout << "\t\t|     2、继续练习      |" << endl;
		cout << "\t\t------------------------" << endl;
		cout << "\t\t|     3、返回          |" << endl;
		cout << "\t\t------------------------" << endl;
		cout << "\t\t|     0、退出          |" << endl;
		cout << "\t\t------------------------" << endl;
		cout << "\t\t输入你的选择:" << endl << "\t\t";
}

void word::Acc_Game()
{
	cout << "\t\t----------------" << endl;
	cout << "\t\t|1、管理员登录 |" << endl;
	cout << "\t\t----------------" << endl;
	cout << "\t\t|2、学生端学习 |" << endl;
	cout << "\t\t----------------" << endl;
	cout << "\t\t|3、使用说明   |" << endl;
	cout << "\t\t----------------" << endl;
	cout << "\t\t|0、退出系统   |" << endl;
	cout << "\t\t----------------" << endl;
	cout << "\n\t\t输入你的选择:" << endl<<"\t\t";
	Acc_Init();
	int t;
	int flag = 0;
	cin >> t;
	if (t == 0) {
		cout << "\n\n\t\t谢谢使用" << endl << "\t\t";
		_getch();
		exit(0);
	}
	else if (t == 2) {
		cout << "\n\n\t\t进入学习" << endl << "\t\t";
		_getch();
		system("cls");
		Ope_Game();
	}
	else
		if (t == 1)
		{
			while (1)
			{
				if (!Acc_Flag)
				{
					if (!Judge_Pass)
					{
						cout << "\t\t请输入密码:" << endl;
						if (Judge_Acc() != Password) {
							Acc_Num--;
							if (Acc_Num == 0) {
								Acc_Flag = true;
							}
							cout << "\n\n\t\t密码或账号错误,是否重新输入(y/n)...." << endl << "\t\t";
							char ch;
							cin >> ch;
							if (ch == 'n') {
								system("cls");
								return;
							}
						}
						else
						{
							cout << "\n\n\t\t登录成功!" << endl << "\t\t";
							Judge_Pass = true;
							_getch();
						}
					}
					else
					{
						system("cls");
						int t;
						cout << "\t\t------------------------" << endl;
						cout << "\t\t|欢迎进入管理员操作界面|" << endl;
						cout << "\t\t------------------------" << endl;
						cout << "\t\t|     1、词汇操作      |" << endl;
						cout << "\t\t------------------------" << endl;
						cout << "\t\t|     2、修改密码      |" << endl;
						cout << "\t\t------------------------" << endl;
						cout << "\t\t|     3、返回          |" << endl;
						cout << "\t\t------------------------" << endl;
						cout << "\t\t|     0、退出          |" << endl;
						cout << "\t\t------------------------" << endl;
						cout << "\n\t\t输入你的选择:" << endl << "\t\t";
						cin >> t;
						switch (t)
						{
						case 1:
							system("cls");
							Ope_Words();
							break;
						case 2:
							system("cls");
							Mod_Acc();
							break;
						case 3:
							system("cls");
							return;
							break;
						case 0:
							system("cls");
							cout << "\n\n\t\t谢谢使用" << endl << "\t\t";
							_getch();
							exit(0);
							return;
						}
					}
				}
				else
				{
					cout << "\n\n\t\t三次输入错误,进行账号锁定,无法再次登录...." << endl<<"\t\t";
					_getch();
					system("cls");
					return;
				}
			}
		}
		else
			if (t == 3) {
				system("cls");
				Exp_Game();
				_getch();
				system("cls");
			}
}

void word::Acc_Save()//保存
{
	fstream f;
	f.open(FILENAME3, ios::out);
	if (!f) {
		cout << "文件不存在!" << endl;
		return;
	}
	f << Password;
	f.close();
}

void word::Acc_Init()//初始化
{
	fstream f;
	f.open(FILENAME3, ios::in);
	if (!f) {
		cout << "文件不存在!" << endl;
		return;
	}
	f >> Password;
	f.close();
}

void word::Mod_Acc()//修改密码
{
	cout << "\n\n\t\t输入新密码:" << endl << "\t\t";
	string str;
	cin >> str;
	Password = str;
	Acc_Save();
	cout << "\n\n\t\t修改成功!" << endl << "\t\t";
	_getch();
	system("cls");
}

string word::Judge_Acc()
{
	char buf[1024];
	int index = 0;
	string str;
	cout << "\t\t";
	while (1)
	{
		char ch;
		ch = getch();
		if (ch == 8) {
			if (index > 0)
			{
				index--;
				cout << char(8) << " " << char(8);
			}

		}
		else if (ch == '\r')
		{
			buf[index] = '\0';
			cout << endl;
			break;
		}
		else
		{
			cout << "*";
			buf[index++] = ch;
		}
	}
	for (int i = 0; i < index; i++) {
		str += buf[i];
	}
	return str;
}

void word::Exp_Game()//使用说明
{
	cout << "\t\t      欢迎进入使用说明界面" << endl<<endl;
	cout << "\t\t         管理员操作说明        " << endl;
	cout << "\t\t(1)、添加词汇时,应注意输入词汇的正确。" << endl;
	cout << "\t\t(2)、添加单个单词时,词汇意思由中文分号隔开末尾不能有其他字符 如:老板;雇主" << endl;
	cout << "\t\t(3)、添加短语时,注意中间空格只能有一个末尾不能有其他字符 如: ask to do" << endl<<endl;
	cout << "\t\t         答题操作说明        " << endl;
	cout << "\t\t(1)、回答中文时只允许输入一个中文意思且末尾不允许有任何字符 如: word.       单词" << endl;
	cout << "\t\t(2)、回答单词时只允许输入一个单词且末尾不允许有任何字符     如: 单词;	     word" << endl;
	cout << "\t\t(3)、回答短语时注意中间空格且末尾不允许有任何字符           如: 要求做某事; ask to do sth" << endl;	
}

3、main.cpp//主函数部分

#include"word.h"
//声音的头文件
#include <mmsystem.h>
#pragma comment(lib,"winmm.lib")
int main()
{
	system("color  6");  
	system("title 英语学习");
	//播放
	mciSendString(L"open auther.mp3", NULL, 0, 0);
	mciSendString(L"play auther.mp3", NULL, 0, 0);
	srand(time(NULL));
	word CE;
	while (1)
	{		
		CE.Acc_Game();		
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44922497/article/details/103462601
今日推荐