⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capquest.cpp

📁 C++&datastructure书籍源码,以前外教提供现在与大家共享
💻 CPP
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -