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.
- 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()
{
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
