Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that is composed of one source file named Lab3a.cpp . The program defines and uses a class to process nutrition information. The

Write a program that is composed of one source file named Lab3a.cpp. The program defines and uses a class to process nutrition information. The program must be written in accordance to the following plan:

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 named NutritionData that contains these private fields

foodName (string)

servingSize (int)

calFromCarb (double)

calFromFat (double)

calFromProtein (double)

totalCalories (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.

Add mutator member functions to set the fields. One member function for each field except totalCalories. 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.

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.

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 or 0.0.

Write the definition for every member function.

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 using cout and the accessor functions.

Test The Program

The output should look exactly as follows:

Food Name: Bread pita whole wheat Serving Size: 64 grams Calories Per Serving: 170.6 Calories From Carb: 134.0 Calories From Fat: 14.0 Calories From Protein: 22.6

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

What metaphors might describe how we work together?

Answered: 1 week ago

Question

What are some of the possible scenes from our future?

Answered: 1 week ago