7.24 LAB - Nutritional information (classes/constructors) Given main(), complete the FoodItem class (in files Foodltem.h
Posted: Mon Jul 11, 2022 9:56 am
LAB ACTIVITY 1 #include "FoodIten.h" 2 #include <iostream> 3 #include <iomanip> 4 5 6 using namespace std; 7 // Define default constructor 8 7.24.1: LAB - Nutritional information (classes/constructors) 9 10 // to initialize private data members 11 12 string FoodItem::GetName() { 13 return name; 14 } 17 18 } 15 16 double FoodItem::GetFat() { return fat; Define second constructor with arguments 19 20 double Food Item::GetCarbs() { 21 return carbs; 36 37 38 Current file: Fooditem.cpp 22 } 23 24 double FoodItem::GetProtein() { 25 return protein; 26} 27 28 double FoodItem::GetCalories (double numServings) { 29 // Calorie formula 30 39 40 31 32 } 33 34 void FoodIten::PrintInfo() { 35 cout << fixed <<<setprecision (2); cout << "Nutritional information per serving of " << name << ":" << endl; cout << "Fat: " << fat << "g" << endl; cout << Carbohydrates: double calories = ((fat * 9) + (carbs * 4) + (protein * 4)) * numServings; return calories; << carbs << g" << endl; cout << "Protein: "<<protein << "g" << endl; 11 0/20 Load default template...
LAB ACTIVITY File is marked as read only 1 #include "FoodIten.h" 2 #include <iostream> 3 #include <iomanip> 4 5 using namespace std; 6 7 int main() { 8 9 10 11 12 13 14 15 15 16 17 18 92222222=28===== 19 20 } 21 23 24 25 26 27 30 31 32 33 34 7.24.1: LAB - Nutritional information (classes/constructors) 35 36 37 m string itemName; double amountFat, amountCarbs, amountProtein; double numServings: cout << fixed <<setprecision (2); cin >> itemName; if(itemName == "Water" || itenName == "water") { FoodIten foodItem; foodIten. PrintInfo(); } else { Current file: main.cpp cin >> amountFat; cin >> amountCarbs; cin >> amountProtein; cin >> numServings; cout << fixed <<setprecision (2); cout << "Number of calories for " << 1.0 << " serving (s): "<<foodIten.GetCalories (1.0) << endl; Foodltem.cpp main.cpp Foodltem.h return 0; FoodIten foodItem = FoodItem(itemName, amountFat, amountCarbs, amount Protein); foodIten. PrintInfo(); cout << "Number of calories for " << 1.0 << " serving(s): << foodIten.GetCalories (1.0) << endl; cout << "Number of calories for " << numServings << "serving(s): <<<foodIten.GetCalories (numServings) << endl; 0/20
LAB ACTIVITY 1 #ifndef FOODITEMH 2 #define FOODITEMH 3 4 #include <string> 5 6 using namespace std; 7 8 class FoodIten { 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 7.24.1: LAB -Nutritional information (classes/constructors) 25 26 27 28 public: // TODO: Declare default constructor string GetName(); double GetFat(); I double GetCarbs(); I double GetProtein(); T double GetCalories (double numServings); void PrintInfo(); private: Current file: Foodltem.hâ–¾ Foodltem.cpp TODO: Declare second constructor with arguments to initialize private data members string name: double fat; double carbs; double protein; 30 31 32 3: 33 34 #endif Develop mode Submit mode main.cpp Foodltem.h 0/20 Load default template... Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box.