Question: C++ help with this fixing code . cpp file #include #include #include #includeFood.h using namespace std; class Nutrition{ private: string name; double Calories double Fat
C++ help with this fixing code
.cpp file
#include
class Nutrition{
private: string name; double Calories double Fat double Sugars double Protein double Sodium 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){} food[Calories]= food[Fat]=food[Sugars]=food[Protein]=food[Sodium]=0; name = ""; } Nutrition(string type, double calories, double fat, double sugar,double protein, double sodium){ food[Calories]= calories; food[Fat]=fat; food[Sugars]= sugar; food[Protein]=protein; food[Sodium]=sodium; name= type; } void setName(string type){ name = type; } void setCalories(double calories){ food [Calories]= calories; } void setFat(double fat){ food [Fat]= fat; } void setSugars(double sugar){ food [Sugars]= sugar; } void setProtein(double protein){ food [Protein]= protein; } void setSodium(double sodium){ food [Sodium]= sodium; } string getName(){ return name; } double setCalories(){ return food[Calories]; } double getFat(){ return food[Fat]; } double getSugars(){ return food[Sugars]; }
double getProtein(){ return food [Protein]; } double getSodium(){ return food[Sodium]; }
.h file
#ifndef FOOD_H #define FOOD_H Nutrition operator + (Nutrition & F){ Nutrition temp; temp.food[Calories]= food[Calories + F.getCalories()]; temp.food[Fat] = food[Fat] + f.getFat(); temp.food[Sugars]= food[Sugars] + F.getSugars(); temp.food[Protein]= food[Protein]+ F.getProtein(); temp.food[Sodium] = food[Sodium] + F.getSodium(); return temp; } }
void display (Food text){ cout<< "Your total intake is"<
void excess(Nutrition text){ if (text.getCalories() > averageFood[Calories]){ cout<<" You exceeded the suggested amount"<< endl; } if (text.getFat() > averageFood[Fat]){ cout<<" You exceeded the suggested amount"<< endl; } if (text.getSugars() > averageFood[Sugars]){ cout<<" You exceeded the suggested amount"<< endl; } if (text.getProtein() > averageFood[Protein]){ cout<<" You exceeded the suggested amount"<< endl; } if (text.getSodium() > averageFood[Sodium]){ cout<<" You exceeded the suggested amount"<< endl; } } int main(){ Nutrition Items[MAX]; int size; int choice =-1; Nutrition selected; int selected Item = 0; while ( choice != size +2){ for (int i = 0; i < size; i++){ cout << i + 1 << ":"<< list[i].get Nmaw()<
create a class to contain a "Food Item". This food item class should track the name of the food, calories, total fat, total sugars, protein, and sodium. The class's member variables should only be accessible via public accessors or mutators, if necessary. It should contain no public member variables.
Override the addition operator to allow food items to be added together. The result of the addition should populate a class containing the combined nutritional value of the two items. Use this operator to sum up the nutritional value of all the food items selected by the user.
The program should display at least 10 pre-populated items for the user to choose from.
After all food entries have been entered into the console and the total nutritional value has been computed, display to the user if they have exceeded any of the recommended intakes for an average adult:
The addition operation is properly overloaded. The resulting class will contain the combined values of each nutrient member variable.
Class files are stored in separate files
The class is separated into .cpp and .h files properly.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
