Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can somebody please help me finish my code and get it to compile I need help building my main file to get everything together... The

Can somebody please help me finish my code and get it to compile I need help building my main file to get everything together...

The Main File

The main file shall create a Game instance and utilize its methods to implement the game. Separating the logic that displays the menus to the player from the game of Numerical Wagers allows us to reuse the existing Numerical Wagers game in different programs or to change out our current view for a new one if we so choose. Additionally, the main class can be used to handle the number of questions in a game as well as allow a user to select the option to play again. Sample run:

Welcome to Numerical Wagers! Please enter the name of the file containing your questions: questions.txt Round 1 Next Question: Number of years in a score Current Points: 200 Please make a wager:

image text in transcribed image text in transcribed here is my code:

Game.h file

#include "QuestionBank.h" class Game { Question *quentions; int amountWagered; int currentScore; public: Game(void); Game(Question *); int AskQuestion(); void AdjustPoints(bool); void SetWager(int); int GetWager(); int GetCurrentScore(); ~Game(void); };

Game.cpp

#include "Game.h"

Game::Game(void) { }

Game::~Game(void) { }

Game::Game(Question *q) { this->quentions = q; }

int Game::AskQuestion() { return GetCurrentScore(); }

void Game::AdjustPoints(bool correctAnswer) { if(correctAnswer) { this->currentScore += this->amountWagered; } } void Game::SetWager(int amountWagered) { this->amountWagered = amountWagered; } int Game::GetWager() { return this->amountWagered; } int Game::GetCurrentScore() { return this->currentScore; }

Question.h file

#include #include #include using namespace std;

class Question { string text; string answer; public: Question(void); Question(string,string); string GetText(); bool AnswerContainsDigit(char digit); string GetAnswerWithPlaceHolders(vector placholder); bool AllDigitsGuessed(string); ~Question(void); };

Question.cpp file

#include "Question.h"

Question::Question(void) {

}

Question::~Question(void) { }

Question::Question(string text,string answer) { this->text = text; this->answer = answer; } string Question::GetText() { return this->text; } bool Question::AnswerContainsDigit(char digit) { size_t found = this->answer.find(digit); if(found != string::npos) return true; return false; }

string Question::GetAnswerWithPlaceHolders(vector vec) { string newvalue; for(int i=0; i

size_t found; for (int i=0; ianswer.find(vec[i]); if(found == string::npos) newvalue[found] = '_'; } return newvalue; }

bool Question::AllDigitsGuessed(string text) { size_t found; found = text.find('_'); if(found == string::npos) return true; else return false; }

QuestionBank.cpp file

#include #include #include extern ostream cerr; 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 > ans;

//Reading question getline(questionsFile, quest);

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

//Closing file questionsFile.close(); } }

The Game Class C) Game Oquestions: QuestionBank* amountWagered: int o currentScore: int o Game) o Game(QuestionBank*) o AskQuestion ): int o AdjustPoints (boo: void o SetWager (int): void GetWa ger(): int GetCurrentScore (): int This class is used to implement the game itself and is responsible for interacting with the user, updating the score, etc. Game (QuestionBank* qs) o Takes a pointer to a QuestionBank object which holds the questions to be used in the game AskQuestion) o Returns an int, which is the user score after the next question is completed, either successfully, or unsuccessfully o This function should utilize the functions that follow to implement the gameplay AdjustPoints (bool) o Takes a boolean argument indicating whether or not the user correctly guessed the answer. true would indicate that the current amountWagered should be added to the currentScore o Prompts the user for their wager for this question and sets the amountWagered variable appropriately o Returns the current number of points wagered, as an integer o Returns the current score, as an integer. Setwager (int) Gethlager() GetCurrentScore () 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) 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 question's 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. The Game Class C) Game Oquestions: QuestionBank* amountWagered: int o currentScore: int o Game) o Game(QuestionBank*) o AskQuestion ): int o AdjustPoints (boo: void o SetWager (int): void GetWa ger(): int GetCurrentScore (): int This class is used to implement the game itself and is responsible for interacting with the user, updating the score, etc. Game (QuestionBank* qs) o Takes a pointer to a QuestionBank object which holds the questions to be used in the game AskQuestion) o Returns an int, which is the user score after the next question is completed, either successfully, or unsuccessfully o This function should utilize the functions that follow to implement the gameplay AdjustPoints (bool) o Takes a boolean argument indicating whether or not the user correctly guessed the answer. true would indicate that the current amountWagered should be added to the currentScore o Prompts the user for their wager for this question and sets the amountWagered variable appropriately o Returns the current number of points wagered, as an integer o Returns the current score, as an integer. Setwager (int) Gethlager() GetCurrentScore () 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) 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 question's 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

How are sales to customers using Master-Card and VISA recorded?

Answered: 1 week ago