Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++, Write A Class Declare a class named NutritionData that contains these private fields foodN (string) servingS (int) calCarb (double) calFat (double) calProtein (double)

In C++, Write A Class

Declare a class named NutritionData that contains these private fields

foodN (string)

servingS (int)

calCarb (double)

calFat (double)

calProtein (double)

totalCalories (double)

Add the default constructor.

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).

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.0.

Write the definition for the other constructor which sets all the fields based on the parameters received. It sets the total calories field based on the given three calories.

Write the definition for every member function. When one of the mutator functions for the calories is set, it should also update the totalCalories.

Write the main function as follows:

Define and initialize an array named nutritionData using the following data:

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

Use a range-based for loop to print the nutrition data for all foods to the screen using the accessor functions.

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

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions

Question

=+How will this affect the recruiting process?

Answered: 1 week ago