Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

IN C++ AND MAKE IT FOLLOW THE FORMAT AND MATCH THE OUTPUT IMAGE EXACTLYPLEASE! HAD TO WASTE TWO QUESTIONS FOR THIS AND IT IS URGENT.

IN C++ AND MAKE IT FOLLOW THE FORMAT AND MATCH THE OUTPUT IMAGE EXACTLYPLEASE! HAD TO WASTE TWO QUESTIONS FOR THIS AND IT IS URGENT.

This program processes nutrition information with a class.

Complete the program using the information provided below.

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. You may place it above the field.

Add the default constructor. Read the textbook for the syntax of the default constructor.

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

Add 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. Each member function should have a comment above the declaration describing its purpose. Write the bodies of these accessor functions inline.

Add a special 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 definition of getCaloriesPerServing outside of the class declaration.

Write the definition for the default constructor. 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.

Ignore this if the member function's body has been written in the class already.

Write the definition for every member function. Note, this lab requires that the definition must be written 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 a reference to const NutritionData as a parameter and returns void.

Write the main function as follows:

Define an instance of the class NutritionData named pita.

Use the mutator functions to set the nutrition data for pita.

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

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

Use cout and the accessor functions to print the nutrition data.

Test The Program

The output should look exactly as follows:

GIVEN CODE

#include #include #include

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 the nutrition information of one food item. //* //* Parameter //* data - a const reference to the callers NutritionData variable. //* Return //* void //********************************************************************** // Write the definition of printNutritionData here . . .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Health Care Management

Authors: Sharon B. Buchbinder, Nancy H. Shanks

3rd Edition

128408101X, 9781284081015

More Books

Students explore these related Programming questions