Improve on the following C++ code to do the following. Usea linked list to have all of the meals stored for the user to pickfrom. Implement a Queue for the 21 meals each week. Be able to addand remove and change meal plans for each day. Have an interactableuser interface to select each meal. Must have 10 meals to selectfrom. Have the user be able to select a meal and then be promptedfor which day they would like to have that meal and then what time(breakfast, lunch, or dinner). Be able to view the ENTIRE MEAL PLANfor the week that includes ALL 21 meals! Make sure the code can berun and compiled.
#include <iostream>#include <string>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 = 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;}
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
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am