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

Using C++ The general idea is you will have an Oven, a Person, and a Cookie. You

ID: 3913769 • Letter: U

Question

Using C++ The general idea is you will have an Oven, a Person, and a Cookie. You will give the cookie to the oven to cook. You will then give the cookie to the person to eat. The Whole Point of the assignment is to show that when Oven does something to the Cookie, the Person can see the change when the Cookie gets to them. The Main looks like this #include "stdafx.h"

// Here is the file with main in it like normal.  Main is always the starting point of the application.
// If you want to add a class to your project, right click on the project and just pick Add->Class.
// Then you just need to put a name in the very first field and hit ok.  VS will make the h and cpp files
// and put them in the right place.

// Just like how you need to include iostream to use cout, you need to include your new h files if you want to use their class
// HOWEVER.  If you are in an h file and only want to _mention_ a class, then you do a "forward declaration".  Details in Oven.
#include "Cookie.h"
#include "Oven.h"
#include "Person.h"

#include

int main()
{
    // For the love of Chuck follow this outline.  I am grading these steps in the outline.  The outline below.  That you have to use.
    // I'm 100% laying out exactly what you need to do, but I'm making you write the prototypes and methods

    // 1) Make an Oven object

    // 2) Make a Person pointer and assign a dynamically allocated Person object to it

    // 3) Make a Cookie pointer and leave it null

    // 4) Ask the user to enter the flavor of cookie they want.  You need to handle multiple words so use getline, not >>

    // 5) Create a new cookie object.  The cookie's constructor takes a string argument for the flavor

    // 6) Make Oven and Cookie interact.  Oven should have a method that takes a COOKIE POINTER as an argument that cooks the cookie

    // 7) Make Person and Cookie interact.  Person should have a method that takes a COOKIE POINTER as an argument, and checks if the cookie is cooked

    // 8) Delete any objects you created.  One new, one delete.

    return 0;
}

Cookie.h looks like this:

#pragma once
class Cookie
{
    // Cookie needs a property for the flavor string

    // Cookie needs a property for a bool to track if it is cooked or not
public:
    // Cookie needs a constructor that takes a string for the flavor

    // Cookie needs to NOT have a default constructor
    Cookie();
    ~Cookie();

    // Since cookie properties are private, we need methods to set and get them.  BUT, the cookie's flavor can't change after
    // creation, so there should not be a settor for flavor.
};

Oven.h looks like this:

#pragma once

// Oven is going to need to mention the cookie class since it is an argument in its method.  But h files need to be very careful when including h files.
// If A includes B, B includes C, and C includes A, then VS completely freaks out.  "Circular dependency."  It won't compile and it won't be able to figure out a good error message.
// So when a cpp file wants to USE a class, like it wants to make objects and call methods, it includes the h file.
// When an h file wants to MENTION a class, as in it just wants to say the word, it "forward declares" the class.  It tells VS "Trust me, this is a class in another file."

// If you think about it, this looks like a prototype of a function.  A prototype is the definition and then a semicolon instead of {}.
class Cookie;

class Oven
{
public:
    Oven();
    ~Oven();

    // Oven has a method that takes a cookie pointer as an argument.  Cookie has a flag representing if it is cooked if you flip over there.
    // This method should set that flag to true by using its setter.
};

And Person.h looks like this:

#pragma once
class Person
{
public:
    Person();
    ~Person();

    // Person has a method that takes a cookie pointer as an argument.  Cookie has a flag for whether or not it is cooked.
    // This method will check that flag using cookie's getter and cout a message saying if it is cooked or not.
};

Explanation / Answer

//Cookie.h

#pragma once

#include<string>

using namespace std;

class Cookie

{

// Cookie needs a property for the flavor string

string flavor;

// Cookie needs a property for a bool to track if it is cooked or not

bool is_cooked;

public:

// Cookie needs a constructor that takes a string for the flavor

Cookie(string flav);

// Cookie needs to NOT have a default constructor,coomenting default constructor as it is not required , CHEGGEA

//Cookie();

~Cookie();

// Since cookie properties are private, we need methods to set and get them. BUT, the cookie's flavor can't change after

// creation, so there should not be a settor for flavor.

void set_flavor(string str);

string get_flavor();

void set_is_cooked(bool set);

bool get_is_cooked();

};

---------------------------------------------------------------

//Cookie.cpp

#include"Cookie.h"

Cookie::Cookie(string flav)

{

flavor = flav;

is_cooked = false;

}

// Cookie needs to NOT have a default constructor,coomenting default constructor as it is not required , CHEGGEA

//Cookie();

Cookie::~Cookie()

{

}

// Since cookie properties are private, we need methods to set and get them. BUT, the cookie's flavor can't change after

// creation, so there should not be a settor for flavor.

void Cookie::set_flavor(string str)

{

flavor = str;

}

string Cookie::get_flavor()

{

return flavor;

}

void Cookie::set_is_cooked(bool set)

{

is_cooked = set;

}

bool Cookie::get_is_cooked()

{

return is_cooked;

}

-----------------------------------------------------------

//Oven.h

#pragma once

#include"Cookie.h"

class Cookie;

class Oven

{

public:

Oven();

~Oven();

// Oven has a method that takes a cookie pointer as an argument. Cookie has a flag representing if it is cooked if you flip over there.

// This method should set that flag to true by using its setter.

void set_status(Cookie *ptr);

};

------------------------------------------------------------------------

//Oven.cpp

#include"Oven.h"

Oven::Oven()

{

}

Oven::~Oven()

{

}

// Oven has a method that takes a cookie pointer as an argument. Cookie has a flag representing if it is cooked if you flip over there.

// This method should set that flag to true by using its setter.

void Oven::set_status(Cookie *ptr)

{

ptr->set_is_cooked(true);

}

------------------------------------------------------------

//Person.h

#pragma once

#include<iostream>

#include"Cookie.h"

using namespace std;

class Person

{

public:

Person();

~Person();

// Person has a method that takes a cookie pointer as an argument. Cookie has a flag for whether or not it is cooked.

// This method will check that flag using cookie's getter and cout a message saying if it is cooked or not.

void check(Cookie *ptr);

};

---------------------------------------------------------------------

//Person.cpp

#include"Person.h"

Person::Person()

{

}

Person::~Person()

{

}

// Person has a method that takes a cookie pointer as an argument. Cookie has a flag for whether or not it is cooked.

// This method will check that flag using cookie's getter and cout a message saying if it is cooked or not.

void Person::check(Cookie *ptr)

{

if (ptr->get_is_cooked())

{

cout << "Cookie with flavor " <<ptr->get_flavor()<<" is cooked" << endl;

}

else

{

cout << "Cookie with flavor "<<ptr->get_flavor()<<" is not cooked" << endl;

}

}

------------------------------------------------------------------

//Main.cpp

#include<iostream>

using namespace std;

#include "Cookie.h"

#include "Oven.h"

#include "Person.h"

int main()

{

// For the love of Chuck follow this outline. I am grading these steps in the outline. The outline below. That you have to use.

// I'm 100% laying out exactly what you need to do, but I'm making you write the prototypes and methods

// 1) Make an Oven object

Oven obj;

// 2) Make a Person pointer and assign a dynamically allocated Person object to it

Person *ptr;

ptr = new Person();

// 3) Make a Cookie pointer and leave it null

Cookie *cookiePtr=NULL;

// 4) Ask the user to enter the flavor of cookie they want. You need to handle multiple words so use getline, not >>

string flavor;

getline(cin, flavor);

// 5) Create a new cookie object. The cookie's constructor takes a string argument for the flavor

cookiePtr = new Cookie(flavor);

// 6) Make Oven and Cookie interact. Oven should have a method that takes a COOKIE POINTER as an argument that cooks the cookie

obj.set_status(cookiePtr);

// 7) Make Person and Cookie interact. Person should have a method that takes a COOKIE POINTER as an argument, and checks if the cookie is cooked

ptr->check(cookiePtr);

// 8) Delete any objects you created. One new, one delete.

delete ptr, cookiePtr;

return 0;

}

--------------------------------------------

/*output
cream with chocolate
Cookie with flavor cream with chocolate is cooked

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote