Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning PostgreSQL On The Cloud Simplifying Database As A Service On Cloud Platforms

Authors: Baji Shaik ,Avinash Vallarapu

1st Edition

1484234464, 978-1484234464

More Books

Students also viewed these Databases questions

Question

Connect with your audience

Answered: 1 week ago