Write a class called Game that contains a video game’s name, genre, and difficultyLevel.  Include a default constructor and destructor for the class.  The constructor should print out the following message:  “Creating a new game”.  The destructor should print out the following message:  “In the Game destructor.”  Include appropriate get/set functions for the class. In main(), prompt the user to enter the number of games he or she has played in the past year.  Dynamically create a built-in array based on this number (not a vector or object of the array class) to hold pointers to Game objects. Construct a loop in main() that executes once for each of the number of games that the user indicated.  Within this loop, ask the user to enter the name and genre of each game.  Using a random number generator, generate a difficultyLevel between 1-10 (inclusive). Seed this random number generator with 100.  Next, dynamically create a Game object (remember that this requires the use of the “new” keyword which returns a pointer to the location in memory where this game object was created.)  Create each object using the default constructor of the class, and call the set functions to store the name, genre, and difficulty level of each game.  Store each Game pointer in the array. After all of the Game objects have been constructed and added to the array, print out the contents of the array. Because the program uses dynamic memory to store the array as well as the objects in the array, be sure to de-allocate all of the memory before exiting. Three separate files are created for the program:  Game.h(header file), Game.cpp (class implementation file), and GameDriver.cpp (driver file) A sample of the program running is shown below:     This is what I have so far : #include "Header.h" #include #include #include #include #include   using namespace std; int main() {     string name;     string genre;     int difficultyLevel;     int numGames;     string i;          cout << "How many games have you played in the last year?\n";     cin>> numGames;     Game **PtrArray= new Game* [numGames];     srand(100);     for(int i=0; i>name;         cout<<"what is the genre of the "<>genre;         difficultyLevel=rand()%(100)+1; // random number generator         Game *game = new Game;         game->getName(name);         game->getGenre(genre);         game->getdifficultyLevel(difficultyLevel);     }     cout<<"there are the ganes you have played tthis year:\n"< #include "Game.cpp" using namespace std;   class Game {     public:     Game();     ~Game();     Game(string n, string g, int d);          string getName();     void setName(const string &n);          string getGenre();     void setGenre(const string &g);          int getdifficultyLevel();     void setdifficultyLevel(const int &d);            private:         string name;         string genre;         int difficultyLevel; };      #endif /* Header_h */     #include "Header.h" #include   Game::Game (string name, string genre, int difficultyLevel);     void Game::setName(string n){     name=n; }   void Game::setGenre(string g){     genre=g; } void Game::setdifficultyLevel(const int &d){     name=d; }          string Game::getName(){         return name;     }     string Game::getGenre(){     return genre;     }     int Game::getdifficultyLevel(){     return difficultyLevel;     }     But I keep getting errors, Would you please let me know what I'm doing wrong? thank you

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

Dynamic Games

Instructions:

Write a class called Game that contains a video game’s name, genre, and difficultyLevel.  Include a default constructor and destructor for the class.  The constructor should print out the following message:  “Creating a new game”.  The destructor should print out the following message:  “In the Game destructor.”  Include appropriate get/set functions for the class.

In main(), prompt the user to enter the number of games he or she has played in the past year.  Dynamically create a built-in array based on this number (not a vector or object of the array class) to hold pointers to Game objects.

Construct a loop in main() that executes once for each of the number of games that the user indicated.  Within this loop, ask the user to enter the name and genre of each game.  Using a random number generator, generate a difficultyLevel between 1-10 (inclusive). Seed this random number generator with 100.  Next, dynamically create a Game object (remember that this requires the use of the “new” keyword which returns a pointer to the location in memory where this game object was created.)  Create each object using the default constructor of the class, and call the set functions to store the name, genre, and difficulty level of each game.  Store each Game pointer in the array.

After all of the Game objects have been constructed and added to the array, print out the contents of the array.

Because the program uses dynamic memory to store the array as well as the objects in the array, be sure to de-allocate all of the memory before exiting.

Three separate files are created for the program:  Game.h(header file), Game.cpp (class implementation file), and GameDriver.cpp (driver file)

A sample of the program running is shown below:

 

 

This is what I have so far :

#include "Header.h"

#include <iostream>

#include <cstring>

#include <cstdlib>

#include <ctime>

#include <iomanip>

 

using namespace std;

int main()

{

    string name;

    string genre;

    int difficultyLevel;

    int numGames;

    string i;

    

    cout << "How many games have you played in the last year?\n";

    cin>> numGames;

    Game **PtrArray= new Game* [numGames];

    srand(100);

    for(int i=0; i<numGames; i++)

    {

        cout<<"What is the name of a game?\n"<< endl;

        cin>>name;

        cout<<"what is the genre of the "<<name<<" ?\n"<<endl;

        cin>>genre;

        difficultyLevel=rand()%(100)+1; // random number generator

        Game *game = new Game;

        game->getName(name);

        game->getGenre(genre);

        game->getdifficultyLevel(difficultyLevel);

    }

    cout<<"there are the ganes you have played tthis year:\n"<<endl;

    for(int i=0; i<numGames; i++)

 

    {

        cout<<setw(25)<<left<<"Game name:" <<name<<endl;

        cout<<setw(25)<<left<<"Game genre:"<<genre<<endl;

        cout<<setw(25)<<left<<"difficultyLevel:" <<difficultyLevel<<endl;

        cout<<endl;

        

    }

    for(int i=0; i<numGames; i++)

    {

        delete [] PtrArray;

           return 0;

    }

}

#ifndef Header_h

#define Header_h

#include <iostream>

#include "Game.cpp"

using namespace std;

 

class Game

{

    public:

    Game();

    ~Game();

    Game(string n, string g, int d);

    

    string getName();

    void setName(const string &n);

    

    string getGenre();

    void setGenre(const string &g);

    

    int getdifficultyLevel();

    void setdifficultyLevel(const int &d);

 

    

    private:

        string name;

        string genre;

        int difficultyLevel;

};

    

#endif /* Header_h */

 

 

#include "Header.h"

#include <iostream>

 

Game::Game (string name, string genre, int difficultyLevel);

 

 

void Game::setName(string n){

    name=n;

}

 

void Game::setGenre(string g){

    genre=g;

}

void Game::setdifficultyLevel(const int &d){

    name=d;

}

    

    string Game::getName(){

        return name;

    }

    string Game::getGenre(){

    return genre;

    }

    int Game::getdifficultyLevel(){

    return difficultyLevel;

    }

 

 

But I keep getting errors, Would you please let me know what I'm doing wrong?

thank you 

 

 

 

 



How many games have you played in the last year?
3
What is the name of a game?
Наlo
What is the genre of the Halo game?
First-Person Shooter
Creating a new game
What is the name of a game?
Splinter Cell
What is the genre of the Splinter Cell game?
Stealth
Creating a new game
What is the name of a game?
Among Us
What is the genre of the Among Us game?
Survival
Creating a new game
These are the games you have played this year:
Game name:
Game genre:
Difficulty Level:
Halo
First-Person Shooter
6
Game name:
Game genre:
Difficulty Level:
Splinter Cell
Stealth
7
Among Us
Survival
Game name:
Game genre:
Difficulty Level:
6
In the Game destructor
In the Game destructor
In the Game destructor
Press any key to continue
* English (United States)
Transcribed Image Text:How many games have you played in the last year? 3 What is the name of a game? Наlo What is the genre of the Halo game? First-Person Shooter Creating a new game What is the name of a game? Splinter Cell What is the genre of the Splinter Cell game? Stealth Creating a new game What is the name of a game? Among Us What is the genre of the Among Us game? Survival Creating a new game These are the games you have played this year: Game name: Game genre: Difficulty Level: Halo First-Person Shooter 6 Game name: Game genre: Difficulty Level: Splinter Cell Stealth 7 Among Us Survival Game name: Game genre: Difficulty Level: 6 In the Game destructor In the Game destructor In the Game destructor Press any key to continue * English (United States)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage