/* Astrachan p 307,308 */ #include #include 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; }