Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Improve on the following C++ code to do the following. Use a linked list to have all of the meals stored for the user to

Improve on the following C++ code to do the following. Use a linked list to have all of the meals stored for the user to pick from. Implement a Queue for the 21 meals each week. Be able to add and remove and change meal plans for each day. Have an interactable user interface to select each meal. Must have 10 meals to select from. Have the user be able to select a meal and then be prompted for which day they would like to have that meal and then what time (breakfast, lunch, or dinner). Be able to view the ENTIRE MEAL PLAN for the week that includes ALL 21 meals! Make sure the code can be run and compiled.

#include #include using namespace std;

class Meal { public: Meal(string n, string t) { name = n; time = t; }

void setName(string n) { name = n; }

string getName() { return name; }

void setTime(string t) { time = t; }

string getTime() { return time; }

private: string name; string time; };

class User { public: User(string n) { name = n; }

void setName(string n) { name = n; }

string getName() { return name; }

private: string name; };

class Week { public: Week() { for(int i = 0; i < 21; i++) { meals[i] = NULL; } }

void setMeal(Meal* m, int day, int meal) { meals[(day - 1) * 3 + meal - 1] = m; }

Meal* getMeal(int day, int meal) { return meals[(day - 1) * 3 + meal - 1]; }

private: Meal* meals[21]; };

int main() { User* user = new User("Dave"); Week* week = new Week();

Meal* meal1 = new Meal("Pizza", "Dinner"); Meal* meal2 = new Meal("Hamburger", "Lunch"); Meal* meal3 = new Meal("Cereal", "Breakfast");

week->setMeal(meal1, 1, 3); week->setMeal(meal2, 2, 2); week->setMeal(meal3, 3, 1);

for(int i = 1; i <= 3; i++) { for(int j = 1; j <= 3; j++) { Meal* meal = week->getMeal(i, j); if(meal != NULL) { cout << user->getName() << "'s " << meal->getTime() << " meal on day " << i << " is " << meal->getName() << endl; } } }

return 0; }

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_2

Step: 3

blur-text-image_3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions