You should include a program description at the top of the main program according to the template. You may simply use this sentence, "This program processes nutrition information with a class."  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. Note that you need to use the proper C++ syntax for the fields. Each field should have a comment documenting what it is for. Place one comment above each field. Add the public default constructor. Read the textbook for the syntax of 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. Add public mutator member functions to set the fields. One mutator member function for each field. Each mutator member function's name 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 bodies of the mutator functions inline. Add public accessor member functions to return the fields. One accessor 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. You must place the keyword const to indicate accessor function (look up the textbook or some other resource for details). Each member function should have a comment above the declaration describing its purpose. Write the bodies of these accessor functions inline. Add a special public accessor member function named getCaloriesPerServing that returns the total calories from carb, protein and fat. Again add the const keyword and place the comment above the declaration of this member function. Write the body outside of the class. Write the definition of getCaloriesPerServing outside of the class declaration. Regarding the block comment for the function, place it inside the class above the member function declaration. Write the declaration of the function named printNutritionData. The function receives two parameters, a pointer to const NutritionData and an int for the number of NutritionData, and returns void. The parameters represent an array of NutritionData objects. Write the main function as follows: The main function gets nutrition data for a list of foods from a file named 'nutri.txt' and store them in an array of NutritionData objects. It then calls printNutritionData to print the nutrition data of the foods. You can download the file from nutri.txt  download and place it in the same folder/directory as your executable program of this lab. The first line of the file contains the number of nutrition data stored in the file. Get that number and use that number to dynamically create an array of NutritionData object. Save the address in a pointer variable. Do not change this pointer until the memory is recycled through the delete operation. For each object in the array, populate the object with data from the input file. The data for each food are stored in the file as a comma delimited string in the file.  They are food name, serving size (an integer), calories from carb, calories from fat, and calories from protein. Here is an example for one food. Bread pita whole wheat, 64, 134, 14, 22.6 Use the mutator functions to set the nutrition data for each object in the array. Print the nutrition data of foods on the screen by calling printNutritionData. Recycle the allocated array using the delete operator. Reset the pointer to nullptr. (Don't use NULL, we have a C++ keyword named nullptr.) Write the block comment and the definition of the function printNutritionData. Use a loop, cout, and the accessor functions to print the nutrition data. Test The Program The output should look exactly as follows:

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

Description 

You should include a program description at the top of the main program according to the template. You may simply use this sentence, "This program processes nutrition information with a class." 

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. Note that you need to use the proper C++ syntax for the fields.

Each field should have a comment documenting what it is for. Place one comment above each field.

Add the public default constructor. Read the textbook for the syntax of 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.

Add public mutator member functions to set the fields. One mutator member function for each field. Each mutator member function's name 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 bodies of the mutator functions inline.

Add public accessor member functions to return the fields. One accessor 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. You must place the keyword const to indicate accessor function (look up the textbook or some other resource for details). Each member function should have a comment above the declaration describing its purpose. Write the bodies of these accessor functions inline.

Add a special public accessor member function named getCaloriesPerServing that returns the total calories from carb, protein and fat. Again add the const keyword and place the comment above the declaration of this member function. Write the body outside of the class.

Write the definition of getCaloriesPerServing outside of the class declaration.

Regarding the block comment for the function, place it inside the class above the member function declaration.

Write the declaration of the function named printNutritionData. The function receives two parameters, a pointer to const NutritionData and an int for the number of NutritionData, and returns void. The parameters represent an array of NutritionData objects.

Write the main function as follows:

The main function gets nutrition data for a list of foods from a file named 'nutri.txt' and store them in an array of NutritionData objects. It then calls printNutritionData to print the nutrition data of the foods. You can download the file from nutri.txt  download and place it in the same folder/directory as your executable program of this lab.

The first line of the file contains the number of nutrition data stored in the file. Get that number and use that number to dynamically create an array of NutritionData object. Save the address in a pointer variable. Do not change this pointer until the memory is recycled through the delete operation.

For each object in the array, populate the object with data from the input file. The data for each food are stored in the file as a comma delimited string in the file.  They are food name, serving size (an integer), calories from carb, calories from fat, and calories from protein. Here is an example for one food.

Bread pita whole wheat, 64, 134, 14, 22.6

Use the mutator functions to set the nutrition data for each object in the array.

Print the nutrition data of foods on the screen by calling printNutritionData.

Recycle the allocated array using the delete operator.

Reset the pointer to nullptr. (Don't use NULL, we have a C++ keyword named nullptr.)

Write the block comment and the definition of the function printNutritionData.

Use a loop, cout, and the accessor functions to print the nutrition data.

Test The Program

The output should look exactly as follows:

The output should look exactly as follows:
Food Name: Apples raw
Serving Size: 110 g
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: 225 g
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: 91 g
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: 128 g
Calories Per Serving: 52.5
Calories From Carb: 46.6
Calories From Fat: 2.6
Calories From Protein: 3.3
Transcribed Image Text:The output should look exactly as follows: Food Name: Apples raw Serving Size: 110 g 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: 225 g 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: 91 g 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: 128 g Calories Per Serving: 52.5 Calories From Carb: 46.6 Calories From Fat: 2.6 Calories From Protein: 3.3
//****
// Program name: Lab3a
//
// Description: <write the program description here.>
//
// What 's on your mind about this lab? <write what you've learned here.>
//
// Author: <write your name here.>
//
// Date: <write the date you start writing the program in mm/dd/yyyy.>
//
// IDE Used: <write the IDE you use here.>
//
// Template Date: 04/06/2021
//*****
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
// write the class and definition of its member functions here
// write the prototype of printNutritionData here
int main() {
// write your code here . .
return 0;
}
//****
//* Print an array of nutrition informatio.
/*
//* Parameters
/*
//*
//* Return
//*
//***
void
// write the definition of printNutritionData here . ..
Transcribed Image Text://**** // Program name: Lab3a // // Description: <write the program description here.> // // What 's on your mind about this lab? <write what you've learned here.> // // Author: <write your name here.> // // Date: <write the date you start writing the program in mm/dd/yyyy.> // // IDE Used: <write the IDE you use here.> // // Template Date: 04/06/2021 //***** #include <iostream> #include <iomanip> #include <string> #include <fstream> using namespace std; // write the class and definition of its member functions here // write the prototype of printNutritionData here int main() { // write your code here . . return 0; } //**** //* Print an array of nutrition informatio. /* //* Parameters /* //* //* Return //* //*** void // write the definition of printNutritionData here . ..
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 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