capquest.h

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

H
55
字号
#ifndef _STATEQUEST_H
#define _STATEQUEST_H

// ask a question involving state capitals
// This class conforms to the naming conventions
// of quiz questions in "A Computer Science Tapestry" 2e
//
// This question quiz for state capitals requires construction
// with the name of a data file in the format below
//
//   state capital  (one pair per line, use '_' instead of ' 'e.g.)
//
//   New_York   Albany
//   Kentucky   Frankfort
//   Minnesota   Saint_Paul
//
// there should be 50 lines in the data file
//
// this convention requires the following functions:
//
// void Create()
//     -- ask a new question
// void Ask() const
//     -- ask the last question (from Create()) again
//
// bool IsCorrect(const string& answer) const
//     -- return true iff answer is correct to last (Create()) question
// string Answer() const
//     -- return the answer to the last (Create()) question
//

#include <string>
#include "worditer.h"
using namespace std;

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

    bool IsCorrect(const string& answer) const;
    string Answer()                      const;
    void Ask()                           const;
    
    void Create();  // create a new question

  private:

    string myAnswer;             // answer (state capital)
    string myQuestion;           // the state
    WordStreamIterator myIter;   // iterates over file of states/capitals
};

#endif

⌨️ 快捷键说明

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