Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ Write a program that contains a class called VideoGame. The class should

ID: 3834056 • Letter: I

Question

In C++

Write a program that contains a class called VideoGame.
The class should contain the member variables:

Name
price
rating

Must Dynamically allocate all member variables.
Write get/set methods for all member variables.
Write a constructor that takes three parameters and initializes the member variables.
Write a destructor.
Add code to the destructor. In addition to any other code you may put in the destructor you should also add
a cout statement that will print the message “Destructor Called”.
Figure out where to allocate and release memory.
Create an instance of VideoGame in main.
You should set the values on the instance and then print them out on the console.

Modify the previous program. Make the following changes:

Inside of main create a dynamically allocated two element array of VideoGame objects.
Set the values of both elements of the array.
Make sure you release memory allocated to the array.
Write a method on the VideoGame class called Show that will display the values of all member variables.
Write a loop that will iterate through the array and display the contents of each VideoGame object.

Explanation / Answer

#include<iostream.h>

class VideoGame {
   private:
       string *Name;
       int *price;
       string *rating;
   public:
      VideoGame(){
        Name = new string("");
        price = new int;
        rating = new string("");
      }
      ~VideoGame(){
        cout << "Destructor called" << endl;
        delete Name;
        delete price;
        delete rating;
      }
      void setName(string data){
          *Name = data;
      }
      void setPrice(int data){
          *price = data;
      }
      void setRating(string data){
          *rating = data;
      }
      string getName(){
          return *Name;
      }
      int getPrice(){
          return *price;
      }
      string getRating(){
          return *rating;
      }
      void show(){
          cout << *name << " " << *price << " " << *rating << endl;
      }

};