capquest.cpp
来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 46 行
CPP
46 行
#include <iostream>
#include <iomanip>
using namespace std;
#include "capquest.h"
#include "randgen.h"
#include "strutils.h"
Question::Question(const string& filename)
: myAnswer("*** error ***"),
myQuestion("*** error ***")
{
myIter.Open(filename.c_str());
}
void Question::Create()
{
RandGen gen;
int toSkip = gen.RandInt(0,49); // skip this many lines
int k;
myIter.Init();
for(k=0; k < toSkip; k++)
{ myIter.Next(); // skip the state
myIter.Next(); // and the capital
}
myQuestion = myIter.Current();
myIter.Next();
myAnswer = myIter.Current();
}
void Question::Ask() const
{
cout << "the capital of " << myQuestion << " is ";
}
bool Question::IsCorrect(const string& answer) const
{
return myAnswer == answer;
}
string Question::Answer() const
{
return myAnswer;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?