Question: Could you answer and explain this question? Given main(), complete the Foodltem class (in les Foodltemh and Foodltemcpp) with constructors to initialize each food item.

Could you answer and explain this question?

Could you answer and explain this question? Given main(), complete the Foodltemclass (in les Foodltemh and Foodltemcpp) with constructors to initialize each fooditem. The default constructor should initialize the name to "None" and allother elds to 0.0. The second constructor should have four parameters (food

Given main(), complete the Foodltem class (in les Foodltemh and Foodltemcpp) with constructors to initialize each food item. The default constructor should initialize the name to "None" and all other elds to 0.0. The second constructor should have four parameters (food name, grams of fat, grams of carbohydrates, and grams of protein) and should assign each private eld with the appropriate parameter value Ex: If the input is: M&M's 10.0 34.0 2.0 1.0 where lVl&M's is the food name, 100 is the grams of fat, 34.0 is the grams of carbohydrates, 2.0 is the grams of protein, and 1.0 is the number of servings, the output is: Nutritional information per serving of None: Fat: 0.00 g Carbohydrates: 0.00 g Protein: 0.00 g Number of calories for 1.00 serving(s): 0.00 Nutritional information per serving of M&M's: Fat: 10.00 g Carbohydrates: 34.00 g Protein: 2.00 g Number of calories for 1.00 serving(s): 234.00 The rst Foodltem above is initialized using the default constructor. File is marked as read only Current file: main.cpp - 1 #include "FoodItem.h" 2 #include 3 #include using namespace std; 7 int main(int argc, char* argv) ({ CO FoodItem FoodItem1; 9 10 string itemName; 11 double amountFat, amountCarbs, amountProtein; 12 13 cin > > itemName; 14 cin >> amountFat; 15 cin >> amountCarbs; 16 cin >> amountProtein; 17 18 FoodItem FoodItem2 = FoodItem(itemName, amountFat, amountCarbs, amountProtein); 19 20 double numServings; 21 cin > > numServings; 22 23 FoodItem1 . PrintInfo( ) ; 24 cout using namespace std; 8 class FoodItem { 9 public: 10 // TODO: Declare default constructor 11 12 // TODO: Declare second constructor with arguments 13 // to initialize private data members 14 15 string GetName ( ) ; 16 17 double GetFat(); 18 19 double GetCarbs () ; 20 21 double GetProtein( ); 22 23 double GetCalories (double numServings) ; 24 25 void PrintInfo(); 26 27 private : 28 string name; 29 double fat; 30 double carbs; 31 double protein; 32 1; 33 34 #endifCurrent file: Fooditem.cpp - Load default template... 1 #include "FoodItem.h" 2 #include 3 #include 4 using namespace std; 6 7 // Define default constructor 8 9 // Define second constructor with arguments 10 // to initialize private data members 11 12 string FoodItem: :GetName ( ) { 13 return name; 14 } 15 16 double FoodItem: : GetFat( ) { 17 return fat; 18 } 19 20 double FoodItem: : GetCarbs() { 21 return carbs; 22 } 23 24 double FoodItem: : GetProtein() { 25 return protein; 26 } 27 28 double FoodItem: : GetCalories (double numServings) { 29 // Calorie formula 30 double calories = ((fat * 9) + (carbs * 4) + (protein * 4) ) * numServings; 31 return calories; 32 } 33 34 void FoodItem: :PrintInfo( ) { 35 cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!