Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Lab #3 - Classes Follow the lab requirements. Do not prompt the user for input during the execution of your program. Do not pause

C++ Lab #3 - Classes

Follow the lab requirements.

Do not prompt the user for input during the execution of your program. Do not pause at the end of the execution waiting for the user's input.

Split statements and comments longer than 80 characters into multiple lines and use proper indentations for the split portions.

Read the entire instructions before writing code. In order to get 100%, the entire instructions must be followed.

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

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions

Question

=+from: a) a MNEs perspective? and b) the HRM managers perspective?

Answered: 1 week ago