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
==========
Dear student i have figured out what was the errors.
Error 1: you were using PlayerOptions instead of playeroptions
Error 2: you had defined player option constructor in PlayerOptions.h file
I'm unable to use stdafx.h Header file. as i dont have it in my visual studio.
So i have exclude it from code and it works fine
Please find the below code
Main.cpp
#include<iostream>
#include "GameLoop.h"
using namespace std;
//main method
int main(int argc, char* argv[])
{
Game game; //create game object
game.RunGame(); // call RunGame method for game object
system("pause");
return 0;
}
GameLoop.cpp
#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;
}
}
GameLoop.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();
};
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();
};
SCREENSHOT OF WORKING PROGRAM

If you have any doubt please comment below also don't forget to hit the thumbs up button Thank you :)
I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good...
In need of some help with a LCR C++ game. The code will run, but I need it to cycle through the turns automatically so that the only input from the user is the number of players. It's also showing the winner as the person with 0 chips which is incorrect and I can't figure out why. Any help is greatly appreciated as this is already late. Game rules: Develop a program that follows the rules of Left Center Right...
This is c++ programming and here is my code. I am getting an exception thrown on the destructor for permanentworker. Can you tell me why I am getting this exception? #include <iostream> #pragma warning(disable:4996) class PermanentWorker { private: char *name; int salary; public: PermanentWorker(const char* nam, int money) : salary(money) { name = new char[strlen(nam) + 1]; strcpy(name, nam); } int getPay() const { return salary; ...
Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public: static string weekDays[7]; void print() const; string nextDay() const; string prevDay() const; void addDay(int nDays); void setDay(string d); string getDay() const; dayType(); dayType(string d); private: string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...
Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...
I need help with the code below. It is a C program, NOT C++. It can only include '.h' libraries. I believe the program is in C++, but it must be a C program. Please help. // // main.c // float_stack_class_c_9_29 // // /* Given the API for a (fixed size), floating point stack class, write the code to create a stack class (in C). */ #include #include #include #include header file to read and print the output on console...
Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...
Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string; class Account { public: Account(); Account(string, double); void deposit(double); bool withdraw(double); string getName() const; double getBalance() const; private: string name; double balance; }; #endif ////////////////////////////////////////////// //AccountManager.hpp #ifndef _ACCOUNT_MANAGER_HPP_ #define _ACCOUNT_MANAGER_HPP_ #include "Account.hpp" #include <string> using std::string; class AccountManager { public: AccountManager(); AccountManager(const AccountManager&); //copy constructor void open(string); void close(string); void depositByName(string,double); bool withdrawByName(string,double); double getBalanceByName(string); Account getAccountByName(string); void openSuperVipAccount(Account&); void closeSuperVipAccount(); bool getBalanceOfSuperVipAccount(double&) const;...
I need help modifying this code please ASAP using C++
Here is what I missed on this code below
Here are the instructions
Here is the code
Produce correct70 pts O pts Full Marks No Marks results and statisfy requirements view longer Comments 1. Your display amount is not readable 2. I withdraw more than my balance, but I didn't see any error message description Documentations10 pts 0 pts Full Marks No Marks : comment i code and block comment...
previous assignment code /*C++ test program to test the classes, Animal, Mammal and Cat and print the results on console window.*/ //Main.cpp //include header files #include<iostream> //include Animal, Mammal and Cat header files #include "Animal.h" #include "Mammal.h" #include "Cat.h" using namespace std; int main() { //create Animal object Animal animal("Dog","Mammal",4); cout<<"Animal object details"<<endl; cout<<"Name: "<<animal.getName()<<endl; cout<<"Type: "<<animal.getType()<<endl; cout<<"# of Legs: "<<animal.getLegs()<<endl; cout<<endl<<endl; //create Cat object Cat cat("byssinian cat","carnivorous mammal",4,"short...