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.

Create those classes
Create local Grill variable in main
Dynamically create Hotdog and a Person
Give Grill a method that takes a hotdog pointer and sets a cooked flag in the hotdog to true
Give Person a method that takes a hotdog pointer and outputs that flag
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()

{

}

Respuesta :

Answer:

C++.

Explanation:

#include<iostream.h>

class Grill {

public:

   void cookHotDog(Hotdog* hotdog_pointer) {

           hotdog_pointer->setIsCooked(true);

   }

};

///////////////////////////////////////////////////////////

class Hotdog {

private:

   bool is_cooked;

public:

   void setIsCooked(bool is_cooked) {

       self.is_cooked = is_cooked;

   }

 

   bool getIsCooked() {

       return is_cooked;

   }

};

///////////////////////////////////////////////////////////

class Person {

public:

   void printIsCooked(Hotdog* hotdog_pointer) {

       cout<<hotdog_pointer->getIsCooked()<<endl;

   }

};

////////////////////////////////////////////////////////////////////////////////////////////

int main() {

   Grill grill_1;

   Hotdog* hotdog_pointer = new Hotdog();

   Person* person_pointer = new Person();

////////////////////////////////////////////////////////////////////

   grill_1.cookHotDog(hotdog_pointer);

   person_pointer->printIsCooked(hotdog_pointer);

   return 0;

}