1.错误代码LINK2019,LINK1120
#include "exam.h"
#include "ui.h"
#include <iostream>
#include <string>
#include "stdlib.h"
#include "time.h"
using namespace std;
static const string exam_ui_prompt =
"\n\n"
"\t|*******************************|\n"
"\t|* 请您选择考试类别 *|\n"
"\t|* 1 看中文写英文 *|\n"
"\t|* 2 看英文写中文 *|\n"
"\t|* 3 看解释写成语 *|\n"
"\t|* 0 返回上级 *|\n"
"\t 请输入(1,2,3或0): ";
void exam_ui() {
void exam_ui_english_for_chinese(); {
//装载词库
dict_load(
&dictionaries[ENGLISH_CHINESE],
DICT_PATH DICT_ENGLISH_CHINESE
);
//生成考试题目
Examination exam;
exam_create(&exam, &dictionaries[ENGLISH_CHINESE]);
for (int i = 0; i < exam.words.size(); i++) {
CLEAR();
cout << "\n\n";
cout << "\t|**************************|\n";
meaning_display(exam.meanings[i]);
cout << "\n";
cout << "\t|*************************|\n";
string word = get_input_string("\t 请输入英文答案(0 退出) : ");
cout << "\t 请输入英文答案 (0 退出):";
std::getline(cin, word);
if (word == exam.words[i]) {
cout << "\t 正确!!!" << endl;
string op = get_input_string("\t 请输入(0 退出, 其他 下一题):");
if (bool op = "0") {
break;
}
}
else if (word == "0") {
break;
}
else {
cout << "\t 错误, 继续加油哦" << endl;
//继续下去还答这道题
i--;
}
}
}
CLEAR();
cout << exam_ui_prompt;
string op;
std::getline(cin, op);
if (op == "1") {
exam_ui_english_for_chinese();
}
else if (op == "2") {
}
else if (op == "0") {
return;
}
exam_ui();
}
/**
生成一个[min,max)之间的随机整数
*/
static int radom_index(int min, int max) {
return (int)(min + (double)rand() / (double)RAND_MAX * (max - min));
}
/*
从字典随机生成一个试卷
*/
void exam_create(Examination* exam, Dictionary* dict) {
srand(time(NULL));
int wordcount = dict->words.size();
int itemcount = wordcount < 10 ? wordcount : 10;
for (int i = 0; i < itemcount; i++) {
int idx = radom_index(0, wordcount);
exam->words.push_back(dict->words[idx]);
exam->meanings.push_back(dict->meanings[idx]);
}
}
void exam_ui_display()
{
return;
}
void exam_ui_chinese_for_english()
{
return;
}
void exam_ui_english_for_chinese()
{
}
3.我看我的头文件里都声明定义了但我还是不知道怎么解决这个错误
#ifndef _EXAM_H
#define _EXAM_H
#include <string>
#include <vector>
#include "dict.h"
using namespace std;
typedef struct {
vector<string>words;
vector< vector < string > >meanings;
}Examination;
void exam_create(Examination* exam, Dictionary* dict);
void exam_ui_display();
void exam_ui_chinese_for_english();
void exam_ui_english_for_chinese();
bool op;
string word;
#endif//!_EXAM_H