Course Answers

BUSINESS
COMPUTER SCIENCE
OTHER COURSES
My Profile

Solved: I Need Help Finding The Error In My Code For My Fill In The Blank (Making A Player Class) In C++. Everything Looks Good To Me But It Will Not Run. Please Help... Due In 24 Hr. Problem As You W

By |

I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good to me but it will not run. Please help... due in 24 hr.

Problem As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. Currently, there is a test program that calls a player's class. The program asks the player for a name and then gives options on what happens next. The only option available is to quit. Add an additional option and supporting code in the player header that will allow the player to input a preferred console type. After the player inputs a preferred console type, be sure to redisplay it. here is the .

SLN source code

*Chapter7-TextAdventure.cpp *

//Defines the entry point for the console application.
// Header Files

#include<iostream>
#include "stdafx.h"
#include "Player.h"
#include "GameLoop.h"
#include "PlayerOptions.h"

using namespace std;
//main method

int _tmain(int argc, _TCHAR* argv[])
{
   Game game;   //create game object
   game.RunGame();       // call RunGame method for game object
   system("pause");
   return 0;
}

*GAMELOOP.CPP*

//header files
#include "GameLoop.h"
#include <iostream>

using namespace std;

//intoduce methods
void Game::WelcomePlayer()
{
   cout << "Welcome to Text Adventure!" << endl << endl;
   cout << "What is your name?" << endl << endl;

   string name;
   cin >> name;
   m_player.SetName(name); //call method tos set name

   cout << endl << "Hello " << m_player.GetName() << endl;
}

void Game::GivePlayerOptions() const
{
   cout << "What would you like to do? (Enter a corresponding number)" << endl << endl;
   cout << "1: Quit" << endl << endl;
   cout << "2: Play " << endl;
   cout << "3: Play online " << endl;
   cout << "4: Saved Game " << endl;
   cout << "5: Save Game " << endl;
   cout << "6: None " << endl;
}
//enter method for reading user input
void Game::GetPlayerInput(string& playerInput) const
{
   cin >> playerInput;
}

PlayerOptions Game::EvaluateInput(string& playerInput) const
{
   PlayerOptions chosenOption = PlayerOptions::None;

   if (playerInput.compare("1") == 0)
   {
       cout << "You have chosen to Quit!" << endl << endl;
       chosenOption = PlayerOptions::Quit;
   }
   else if (playerInput.compare("2") == 0)
   {
       cout << "You have selected to Play!" << endl << endl;
   }
   else if (playerInput.compare("3") == 0)
   {
       cout << "You have selected to play online!" << endl << endl;
   }
   else if (playerInput.compare("4") == 0)
   {
       cout << "You have selected to open a Saved Game!" << endl << endl;
   }
   else if (playerInput.compare("5") == 0)
   {
       cout << "You have selected to Save your current game!" << endl << endl;
   }
   else
   {
       cout << "I do not recognise that option, try again!" << endl << endl;
   }

   return chosenOption;
}

void Game::RunGame()   // call methods
{
   WelcomePlayer();

   bool shouldEnd = false; // boolean variable
   while (shouldEnd == false)
   {
       GivePlayerOptions();

       string playerInput;
       GetPlayerInput(playerInput);

       shouldEnd = EvaluateInput(playerInput) == PlayerOptions::Quit;
   }
}

*stdafx.cpp*

// stdafx.cpp : source file that includes just the standard includes
// Chapter7-TextAdventure.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

// Declare Headers
#include "stdafx.h"
#pragma once
#include "Player.h"
#include "PlayerOptions.h"

// Games class

class Game
{
   // Access member
private:
   Player m_player;
   void WelcomePlayer();
   void GivePlayerOptions() const;
   void GetPlayerInput(std::string& playerInput) const;
   PlayerOptions EvaluateInput(std::string& playerInput) const;
   //member functions

public:
   void RunGame();

};

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file


// Player.h
#pragma once
#include <string>

// Declare class
class Player
{
   // Access member
private:
   std::string m_name;

   // Member functions

public:
   Player()
   {
   }
   ~Player()
   {
   }
   // Mutator methods
   void SetName(const std::string& name)
   {
       m_name = name;
   }
   const std::string& GetName() const
   {
       return m_name;
   }
};

// PlayerOptions.h
#pragma once

// Declare enum & Options

enum class Playeroptions
{
   Quit, Play, Myst, PlayOnline, SavedGame, SaveGame, None
};

// Plyaer Options

#pragma once

// Declare class

class PlayerOptions
{

// Member functions

public:      
   PlayerOptions();
   ~PlayerOptions();
};

PlayerOptions::PlayerOptions()
{
}

PlayerOptions::~PlayerOptions()
{
}

VS ERROR i AM GETTING

1>------ Build started: Project: Chapter7-TextAdventure, Configuration: Debug Win32 ------
1>Chapter7-TextAdventure.cpp
1>GameLoop.cpp
1>stdafx.cpp
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\stdafx.cpp(39,1): error C2011: 'Player': 'class' type redefinition
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\Player.h(5): message : see declaration of 'Player'
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\stdafx.cpp(81,1): error C2011: 'PlayerOptions': 'enum' type redefinition
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\PlayerOptions.h(3): message : see declaration of 'PlayerOptions'
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\stdafx.cpp(90,16): error C2027: use of undefined type 'PlayerOptions'
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\PlayerOptions.h(3): message : see declaration of 'PlayerOptions'
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\stdafx.cpp(90,30): error C2059: syntax error: ')'
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\stdafx.cpp(91,1): error C2143: syntax error: missing ';' before '{'
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\stdafx.cpp(91,1): error C2447: '{': missing function header (old-style formal list?)
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\stdafx.cpp(94,30): error C2523: 'PlayerOptions::~PlayerOptions': destructor tag mismatch
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\stdafx.cpp(94,17): error C2027: use of undefined type 'PlayerOptions'
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\PlayerOptions.h(3): message : see declaration of 'PlayerOptions'
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\stdafx.cpp(94,31): error C2059: syntax error: ')'
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\stdafx.cpp(95,1): error C2143: syntax error: missing ';' before '{'
1>Generating Code...
1>C:\Users\JayKo\OneDrive\Desktop\IT 312\IT 312 Code Files\BookCodeFiles\Chapter7-TextAdventure\Chapter7-TextAdventure\stdafx.cpp(95,1): error C2447: '{': missing function header (old-style formal list?)
1>Done building project "Chapter7-TextAdventure.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Answer Preview

Dear student i have figured out what was the errors. Error 1: you were using PlayerOptions instead of playeroptions Error 2: you had definedplayer option constructor in PlayerOptions.h file I'

Get Answer Now


Buy (USD $9.00)

Get Answer Now

Answered
Buy @ USD $9.00
Related Questions

OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES