Question: Need help writing c++ classes based on the main.cpp. Would appreciate any help on how to start these classes, don't necessarily need the answers, I

Need help writing c++ classes based on the main.cpp. Would appreciate any help on how to start these classes, don't necessarily need the answers, I rather have explanations.

Description:

This program will represent a stereotypical college pantry, which consists of shelves that contain various food items. To that end, there are three classes you will be writing: Food Shelf Cabinet

Food:

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.

Shelf:

The Shelf class is a bit more sophisticated. Its purpose is to store an array of Food objects. Each Shelf that you create could have a different number of Food objects, so you will have to use dynamic memory allocation in this case. Your Shelf should contain variables for the following:

The name of the Shelf

A pointer to the array of Food objects, and because pointers dont have any addition info on their own

A maximum capacity of the array

A count of how many Food objects you currently have In addition, you should create the following functions (plus the special functionsa copy constructor, assignment operator, and destructor):

Cabinet:

The Cabinet class in some ways is very similar to the Shelf. It will store a dynamic array, this time of Shelf objects. It will also need a name and ways to keep track of how many Shelves it can store, versus how many it is currently storing. Based on the layout of main.cpp (and the test output), you will also need a way to print everything in its inventory (which consists of Shelves which consist of Food), but also a way to get the average price of each food item. Be sure to define the big three as well.

Tips :

A few tips about this assignment:

Remember the "Big Three" or the Rule of Three o If you define one of the three special functions (copy constructor, assignment operator, or destructor), you should define the other two

You can print out a tab character (the escape sequence '\t' ) to help line up the output.

You can customize the way numbers are displayed in C++ (particularly floating-point numbers). The header file contains this functionality. Look into std::fixed and std::setprecision()

Main.cpp:

#include "Food.h" #include "Cabinet.h" #include "Shelf.h" #include #include #include #include #include

using namespace std;

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(); }

*There is also a leaker.h & leaker.cpp if needed.

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!