Given main(), complete the Food Item class (in files Food Item.h and Foodltem.cpp) with constructors to initialize each food item. The default constructor should initialize the name to "Water" and all other fields 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 class data member with the appropriate parameter value. Ex: If the input is: Water the output is: Nutritional information per serving of Water: Fat: 0.00 g Carbohydrates: 0.00 g Protein: 0.00 g Number of calories for 1.00 serving (s): 0.00 Ex: If the input is: M&M's 10.0 34.0 2.0 3.0 where M&M's is the food name, 10.0 is the grams of fat, 34.0 is the grams of carbohydrates, 2.0 is the grams of protein, and 3.0 is the number of servings, the output is: 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 Number of calories for 3.00 serving (s): 702.00

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

How should I make the solve this problem?

1 #include "FoodItem.h"
2 #include <iostream>
3 #include <iomanip>
4
5 using namespace std;
6
7 // Define default constructor
8
9 // Define second constructor with arguments
10 // to initialize private data members
11
12 string Food Item::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 Food Item::GetProtein() {
25
return protein;
26}
27
28 double Food Item::GetCalories (double numServings) {
29
// Calorie formula
30
31
double calories
return calories;
32}
33
34 void FoodItem: :PrintInfo() {
=
35 cout << fixed <<< setprecision (2);
36
37
38
39
40}
"1
cout << "Nutritional information per serving of << name <<
<< fat <<
cout <<
Fat:
g" << endl;
cout <<
Carbohydrates: << carbs << g" << endl;
cout <<
Protein: << protein <<< g" << endl;
"1
((fat* 9) + (carbs * 4) + (protein * 4)) * numServings;
11
"1
"1
11
"1
"1
"1
<< endl;
Transcribed Image Text:1 #include "FoodItem.h" 2 #include <iostream> 3 #include <iomanip> 4 5 using namespace std; 6 7 // Define default constructor 8 9 // Define second constructor with arguments 10 // to initialize private data members 11 12 string Food Item::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 Food Item::GetProtein() { 25 return protein; 26} 27 28 double Food Item::GetCalories (double numServings) { 29 // Calorie formula 30 31 double calories return calories; 32} 33 34 void FoodItem: :PrintInfo() { = 35 cout << fixed <<< setprecision (2); 36 37 38 39 40} "1 cout << "Nutritional information per serving of << name << << fat << cout << Fat: g" << endl; cout << Carbohydrates: << carbs << g" << endl; cout << Protein: << protein <<< g" << endl; "1 ((fat* 9) + (carbs * 4) + (protein * 4)) * numServings; 11 "1 "1 11 "1 "1 "1 << endl;
Given main(), complete the FoodItem class (in files Foodltem.h and FoodItem.cpp) with constructors to initialize each food item. The
default constructor should initialize the name to "Water" and all other fields 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 class data member with the
appropriate parameter value.
Ex: If the input is:
Water
the output is:
Nutritional information per serving of Water:
Fat: 0.00 g
Carbohydrates: 0.00 g
Protein: 0.00 g
Number of calories for 1.00 serving (s): 0.00
Ex: If the input is:
M&M's
10.0
34.0
2.0
3.0
where M&M's is the food name, 10.0 is the grams of fat, 34.0 is the grams of carbohydrates, 2.0 is the grams of protein, and 3.0 is the
number of servings, the output is:
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
Number of calories for 3.00 serving (s): 702.00
Transcribed Image Text:Given main(), complete the FoodItem class (in files Foodltem.h and FoodItem.cpp) with constructors to initialize each food item. The default constructor should initialize the name to "Water" and all other fields 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 class data member with the appropriate parameter value. Ex: If the input is: Water the output is: Nutritional information per serving of Water: Fat: 0.00 g Carbohydrates: 0.00 g Protein: 0.00 g Number of calories for 1.00 serving (s): 0.00 Ex: If the input is: M&M's 10.0 34.0 2.0 3.0 where M&M's is the food name, 10.0 is the grams of fat, 34.0 is the grams of carbohydrates, 2.0 is the grams of protein, and 3.0 is the number of servings, the output is: 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 Number of calories for 3.00 serving (s): 702.00
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY