Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help c++ not compiling. .cpp file #include #include #include #includeFood.h using namespace std; class Nutrition{ private: string name; double Calories; double Fat; double Sugars;

need help c++ not compiling.

.cpp file

#include #include #include #include"Food.h" using namespace std;

class Nutrition{ private: string name; double Calories; double Fat; double Sugars; double Protein; double Sodium; public: Nutrition(string n, double c, double f, double s, double p, double S) : name(n), Calories(c), Fat(f),Sugars(s), Protein(p),Sodium(S){} Nutrition(string type, double calories, double fat, double sugar,double protein, double sodium){ name = type; Calories = calories; Fat = fat; Sugars = sugar; Protein = protein; Sodium = sodium; } void setName(string type){ name = type; } void setCalories(double calories){ Calories = calories; } void setFat(double fat){ Fat = fat; } void setSugars(double sugar){ Sugars = sugar; } void setProtein(double protein){ Protein = protein; } void setSodium(double sodium){ Sodium = sodium; } string getName(){ return name; } double getCalories(){ return Calories; } double getFat(){ return Fat; } double getSugars(){ return Sugars; } double getProtein(){ return Protein; } double getSodium(){ return Sodium; } };

.h file

#ifndef FOOD_H #define FOOD_H class Nutrition { private: string name; double Calories; double Fat; double Sugars; double Protein; double Sodium; public: Nutrition(string n, double c, double f, double s, double p, double S) : name(n), Calories(c), Fat(f), Sugars(s), Protein(p), Sodium(S) {} Nutrition(string type, double calories, double fat, double sugar, double protein, double sodium) { name = type; Calories = calories; Fat = fat; Sugars = sugar; Protein = protein; Sodium = sodium; } void setName(string type) { name = type; } void setCalories(double calories) { Calories = calories; } void setFat(double fat) { Fat = fat; } void setSugars(double sugar) { Sugars = sugar; } void setProtein(double protein) { Protein = protein; } void setSodium(double sodium) { Sodium = sodium; } string getName() { return name; } double getCalories() { return Calories; } double getFat() { return Fat; } double getSugars() { return Sugars; } double getProtein() { return Protein; } double getSodium() { return Sodium; } Nutrition operator+(Nutrition &F) { Nutrition temp; temp.Calories = Calories + F.getCalories(); temp.Fat = Fat + F.getFat(); temp.Sugars = Sugars + F.getSugars(); temp.Protein = Protein + F.getProtein(); temp.Sodium = Sodium + F.getSodium(); return temp; } }; void display(Nutrition text) { cout << "Your total intake is" << endl; cout << " Calories consumed:" << text.getCalories() << endl; cout << " Total Sugar consumed:" << text.getSugars() << endl; cout << " Protein consumed:" << text.getProtein() << endl; cout << " Sodium consumed:" << text.getSodium() << endl; cout << " Fat consumed:" << text.getFat() << endl; } const int MAX = 11; vector NutritionItems; Nutrition I1("Apple", 14, 5, 7); Nutrition I2("French fries", 2, 5, 6); Nutrition I3("Burger", 3, 50, 60, 4, 5); Nutrition I4("Pizza", 4, 36, 43, 4, 4); Nutrition I5(" Ramen", 5,22,34,5,5); Nutrition I6("Steak", 6,23,27,10,10); Nutrition I7(" Chicken", 7,19,17,7,7); Nutrition I8(" Rice", 8, 16,3,2,2); Nutrition I9(" Pork", 9,17,17,8,8); Nutrition I10(" Carrots",10,17,1,1); Nutrition I11("FInished");

Items.push_back(I1); Items.push_back(I2); Items.push_back(I3); Items.push_back(I4); Items.push_back(I5); Items.push_back(I6); Items.push_back(I7); Items.push_back(I8); Items.push_back(I9); Items.push_back(I10); Items.push_back(I11);

int main() { Nutrition Items[MAX]; int size = 0; int choice = -1; Nutrition selected; int selectedItemCount = 0; while (choice != size + 2) { cout << "Choose a nutrition item to select:" << endl; for (int i = 0; i < size; i++) { cout << i + 1 << ": " << Items[i].getName() << endl; } cout << size + 2 << ": Finished" << endl; cin >> choice; if (choice == size + 1) { size = addItem(Items, size); } else if (choice > 0 && choice < size + 1) { selected = selected + Items[choice - 1]; selectedItemCount++; } else if (choice < 1 || choice > size + 2) { cout << "Invalid input, please try again." << endl; } } if (selectedItemCount > 0) { print(selected); cout << endl; checkExcess(selected); } return 0; }

The program should prompt the user to choose a food item from a list of options. The program should continue looping until the user enters the option to stop. At that time the total nutritional value of all of the food items selected should be combined and displayed.

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

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

=+How should it be delivered?

Answered: 1 week ago

Question

=+4 How does one acquire a global mindset?

Answered: 1 week ago