Question: Writing a program to represent a college food cabinet. How would i start this Food class. Description: The Food class is the basic container of

Writing a program to represent a college food cabinet.

How would i start this Food class.

Description:

The Food class is the basic container of this assignment. You will need to store the following data: The type of food (such as cereal, fruit, vegetable, frozen etc) The name of the food product (such as Fruity Pebbles, Ramen, Tomato, etc) The expiration year The price How many calories does the food have?

In addition to a constructor which takes in the necessary information, you will also need the following functions defined. If you are using dynamic memory in your class, you will also want to define a destructor, in which you will clean up (delete) any memory which was allocated by the class.

//Print all the information on a single line

void Display() const;

//Return a string in the form of "2019 Vegetable Avacado"

string GetYearTypeName() const;

//How much to buy?

float GetPrice() const;

The main.cpp is this:

void TestOne(Food *v); void TestTwo(Food *v);

int main() { // Initialize some data. It's hard-coded here, but this data could come from a file, database, etc Food foods[] = { Food("Vegetable", "Avocado", 2019, 15, 5), Food("Cheese", "Moldy Cheddar", 1999, 7, 400), Food("Breakfast", "Pop-Tart", 2025, 5, 754), Food("Cereal", "Lucky Charms", 2001, 4, 600), Food("Frozen", "Cheese Pizza", 2021, 10, 1001), Food("Very-Processed", "Ramen", 3005, 1, 9999), Food("Expensive", "Caviar", 2017, 180, 150), };

int testNum; cin >> testNum;

if (testNum == 1) TestOne(foods); else if (testNum == 2) TestTwo(foods);

return 0; }

void TestOne(Food *foods) { // Shelfs to store the foods Shelf shelf("\"Healthy-Food Shelf\"", 3); //calls the constructor with parameters shelf.AddFood(&foods[0]); shelf.AddFood(&foods[1]); shelf.AddFood(&foods[2]);

Shelf secondary("\"Treat Your Shelf\"", 4); secondary.AddFood(&foods[3]); secondary.AddFood(&foods[4]); secondary.AddFood(&foods[5]); secondary.AddFood(&foods[6]);

// A "parent" object to store the Shelfs Cabinet cabinet("COP3503 Dormroom Cabinet", 2); cabinet.AddShelf(&shelf); //adding show rooms is the issue cabinet.AddShelf(&secondary);

cabinet.ShowInventory(); }

void TestTwo(Food *foods) { // Shelfs to store the foods Shelf shelf("\"Healthy-Food Shelf\"", 3); shelf.AddFood(&foods[0]); shelf.AddFood(&foods[1]);

Shelf secondary("\"Treat Your Shelf\"", 4);

secondary.AddFood(&foods[4]); secondary.AddFood(&foods[5]);

Shelf third("\"Treat Your Shelf\"", 4); third.AddFood(&foods[3]); // A "parent" object to store the Shelfs Cabinet cabinet("COP3503 Dormroom Cabinet", 3); cabinet.AddShelf(&shelf); cabinet.AddShelf(&secondary); cabinet.AddShelf(&third);

cout << "Using just the GetAveragePrice() function ";

cout << "Average price of the food in the cabinet: $" << std::fixed << std::setprecision(2); cout << cabinet.GetAveragePrice(); }

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!