1. Engineering
  2. Computer Science
  3. i need help writing this question class and the game...

Question: i need help writing this question class and the game...

Question details

I need help writing this question class and the game class. here is my code so far:

The Question Class C) Question o text: std::string o answer: std::string o Question) o Question(std:string. std::string) o GetText ()std::string o AnswerContainsDigit (char digit): bool GetAnswerWithPlaceholders(std::vector<char) std::string o AllDigitsGuessed (std::string): bool This class is responsible for storing the question and answer for a single question. In addition to a parameterized constructor, this class should have the following methods: GetText o Returns an std string that is the question body. AnswerContainsDigit (char) o Returns a boolean (true or false) if the answer contains the character passed in This function is useful for knowing when to increment the number of incorrect guesses GetAnswerwithPlaceholders (std::vector<char>) o Returns an std:string of the answer but digits in the answer that have not yet been guessed by the user should show an underscore For example, if a vector containing 1, 2, and 3 are passed in and the questions answer is 253, this function returns 2_3 AllDigitsGuessed (std::string) Returns true if no underscore is present in the input string, false otherwise. A simple check that searching an input string for the underscore character. o Use this function on the response from GetAnswerWithPlaceholders.

here is my
questionbank.h:


#include
#include
#include
#include
#include
#include

using namespace std;

class QuestionBank {

private:
vector questions;
vector answers;

public:
void LoadQuestions(string fname) {
string quest;
int ans;
ifstream questionsFile;
questionsFile.open(fname);
if (questionsFile.fail()) {
cerr << "Can't open ";
exit(-1);
}
//Reading questions and answers and adding to vector
while(questionsFile.good()) {
//Reading answer
questionsFile >> ans;

//Reading question
getline(questionsFile, quest);

//Adding to vector
questions.push_back(quest);
answers.push_back(ans);
}

//Closing file
questionsFile.close();
}

//Function that returns the question
string getNextQuestion() {
int qNo;

//Generating a random number
qNo = rand() % (questions.size());

//Return question
return questions.at(qNo);
}
};


here is my main.cpp:

#include "questionbank.h"
#include

using namespace std;

int main() {
    string inputFile;
    cout << "Welcome to to wages ";
    cout << "Enter a filename: ";
    cin >> inputFile;
    QuestionBank questionBank;
    questionBank.LoadQuestions(inputFile);
    return 0;
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution