Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help writing one of the c++ classes based on the main.cpp. Description: This program will represent a stereotypical college pantry, which consists of shelves

Need help writing one of the c++ classes based on the main.cpp.

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

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):

Main.cpp:

#include "Food.h" #include "Cabinet.h" #include "Shelf.h" #include iostream #include limits #include memory #include iomanip #include string.h

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

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

What is behavioral persuasion in advertising designed to do?

Answered: 1 week ago