Question: For this, you are going to need some classes. Grill, Hotdog, and Person. The goal is to show how two different objects can both do

For this, you are going to need some classes. Grill, Hotdog, and Person. The goal is to show how two different objects can both do something to the same other object.

  1. Create those classes
  2. Create local Grill variable in main
  3. Dynamically create Hotdog and a Person
  4. Give Grill a method that takes a hotdog pointer and sets a cooked flag in the hotdog to true
  5. Give Person a method that takes a hotdog pointer and outputs that flag
  6. Make main call those two methods

PointersAndMemory.cpp

#include "pch.h"

#include

#include "Grill.h"

#include "HotDog.h"

#include "Person.h"

int main()

{

int x = 0;

Grill tMyGrill;

HotDog *tADog = new HotDog ;

Person *tAPerson = new Person ;

tMyGrill.CookHotDog(tADog);

tAPerson->CheckHotDog(tADog);

// (*tAPerson).CheckHotDog(tADog)

delete tADog;

tADog = nullptr;

delete tAPerson;

tAPerson = nullptr;

if (tADog != nullptr)

{

// tADog->

}

}

Grill.cpp

#include "pch.h"

#include "Grill.h"

#include "HotDog.h"

void Grill::CookHotDog(HotDog *tDog)

{

tDog->mCooked = true;

}

Grill::Grill()

{

}

Grill::~Grill()

{

}

HotDog.cpp

#include "pch.h"

#include "HotDog.h"

HotDog::HotDog()

{

mCooked = false;

}

HotDog::~HotDog()

{

}

Person.cpp

#include "pch.h"

#include "Person.h"

#include "HotDog.h"

#include

void Person::CheckHotDog(HotDog *tDog)

{

if (tDog->mCooked)

std::cout << "Yum" << std::endl;

else

std::cout << "You must have gone to the cafeteria" << std::endl;

}

Person::Person()

{

}

Person::~Person()

{

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!