Question: In C++ Please More Classes The program instantiates and uses instances of a class with non-default constructors. Write the program in accordance to the following
In C++ Please








More Classes The program instantiates and uses instances of a class with non-default constructors. Write the program in accordance to the following plan: Description This program instantiates and uses instances of a class with non-default constructors. Write A Class Declare a class/struct named NutritionData that contains these private fields foodName (string) servingSize (int) calFromCarb (double) calFromFat (double) calFromProtein (double) Use the data types in parentheses for the fields. Each field should have a comment documenting what it is for. Add the default constructor. Write the body of the default constructor inline. The default constructor initializes the fields so that the food name is an empty string and all other fields are 0 for int and 0.0 for double. The initialization should be done using the member initialization list syntax. Add a constructor that accepts these data: food name (string), serving size (int), cal from carb (double), cal from fat (double) and cal from protein (double). Write the body of this constructor which sets all the fields based on the parameters received. The initialization should be done using the member initialization list syntax. Add mutator member functions to set the fields. One member function for each field. Each member function should begin with the word 'set' followed by the field name with the first letter changed to uppercase. Each member function should have a comment above the declaration describing its purpose. Write the body of each mutator member function inline. Add accessor member functions to return the fields. One member function for each field. Each member function should begin with the word 'get' followed by the field name with the first letter changed to uppercase. Each member function should have a comment above the declaration describing its purpose. Note, per the definition of an accessor function, all accessor functions should be marked with the const attribute. Write the body of each accessor member function inline. Add a const member function named getCaloriesPerServing that returns the total calories from carb, protein and fat. Again, don't forget to mark this function as a const member function. Define this function outside of the class with a comment above the definition. Write the definitions of any member functions not defined inline. Write the declaration of the function named printNutritionData which takes a pointer to const NutritionData parameter and an int parameter for the count of NutritionData. The function prints the list of nutrition data it receives. Write the main function as follows: Read nutrition data from the user. The first line from the user indicates the count of nutrition data that follow. Use the new operator to create an array of NutritionData objects based on the user's first line. Then read the rest of the user input into the array. Each line of the user input contains the complete information for one nutrition data. For example, Apples raw, 110, 50.6, 1.2, 1.0 indicates Food name: apples raw Serving size: 110g Cal from carb: 50.6Cal from fat: 1.2 Cal from protein: 1.0 Print the nutrition data for all foods to the screen by calling the printNutritionData function. Delete the allocated array of NutritionData objects. Write the definition of the function named printNutritionData which takes a pointer to const NutritionData parameter and an int parameter for the count of NutritionData. The function prints the list of nutrition data it receives. Test The Program Use the following input: 5 Apples raw, 110,50.6,1.2,1.0 Bananas, 225, 186,6.2,8.2 Bread pita whole wheat, 64,134,14,22.6 Broccoli raw, 91,21.9,2.8,6.3 Carrots raw, 128,46.6,2.6,3.3 The output should look exactly as follows: Food Name: Apples raw Serving Size: 110g Calories Per Serving: 52.8 Calories From Carb: 50.6 Calories From Fat: 1.2 Calories From Protein: 1.0 Food Name: Bananas Serving Size: 225g Calories Per Serving: 200.4 Calories From Carb: 186.0 Calories From Fat: 6.2 Calories From Protein: 8.2 Food Name: Bread pita whole wheat Serving Size: 64 g Calories Per Serving: 170.6 Calories From Carb: 134.0 Calories From Fat: 14.0 Calories From Protein: 22.6 Food Name: Broccoli raw Serving Size: 91g Calories Per Serving: 31.0 Calories From Carb: 21.9 Calories From Fat: 2.8 Calories From Protein: 6.3 Food Name: Carrots raw Serving Size: 128g Calories Per Serving: 52.5 Calories From Carb: 46.6 Calories From Fat: 2.6 Calories From Protein: 3.3 Parameterized constructor I/ Mutators I/ Accessors I/ Get total calories I/ Write the member function definition here I/ Function prototype void printNutritionData(const NutritionData *nptr, int count); void printNutritionData(const NutritionData *nptr, int count); 3 int main() \{ Write your code here... 3} return 0 ; 41/ 1/ Print the nutrition information of an array of food items. 1/ Parameter 1/ nptr - a pointer to const referencing the first nutrition data. 1/ count - number of nutrition data in the array 1/ Return 46// Print the nutrition information of an array of food items. 1/ //* Parameter //* nptr - a pointer to const referencing the first nutrition data. 1/ count - number of nutrition data in the array 1/ Return 1/ void 1/ void printNutritionData(const NutritionData *nptr, int count) \{ Il Write your code here... \}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
