whatstheface.h

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C头文件 代码 · 共 72 行

H
72
字号
#ifndef _WHATSTHEQUESTION_H
#define _WHATSTHEQUESTION_H

#include <string>
using namespace std;

// see "questface.h" for details on member functions
//
// A class for generating quiz questions like
// "What's the capital of Arkansas"
// "Who wrote Neuromancer"
// "What artist recorded 'Are You Gonna Go My Way'"
//
// A file of questions is read, one is used at random each time Create
// is called.  The file is in the format
//
// question
// answer
// question
// answer
//
// i.e., a question uses two lines, the answer is the second line, the
// question is the first line:
//
// Terrapin Station
// Grateful Dead
// Hoist
// Phish
// It's A Shame About Ray
// Lemonheads
// -------------------
//
// The constructor and method Open take a prompt and a file of questions
// as parameters, e.g.,
// WhatsTheQuestion capitals("What's the capital of", "capitals.dat");

#include "questface.h"
#include "tvector.h"

class WhatsTheQuestion : public Question
{
  public:
    WhatsTheQuestion();
    WhatsTheQuestion(const string& prompt,
                     const string& filename);

    virtual bool   IsCorrect(const string& answer) const;
    virtual string Answer()                        const;
    virtual void   Ask()                           const;
    
    virtual void   Create();
    virtual void   Open(const string& prompt,
                        const string& filename);
    
  protected:
     struct Quest
     {
         string first;
         string second;
         Quest() {}     // need vector of Quests
         Quest(const string& f, const string& s)
           : first(f),
             second(s)
         {}
     };    
     tvector<Quest> myQuestions; // list of questions read
     string         myPrompt;    // prompt the user, "what's the ..."
     int            myQIndex;    // current question (index in myQuestions)
};

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?