Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 3 : Assume the definition of class foodType shown in Question 2 . Answer the following questions. Fill in the underlines below to complete

Question 3:
Assume the definition of class foodType shown in Question 2. Answer the following questions.
Fill in the underlines below to complete the definition of the member function set so that private members are set according to the parameters. The values of the int and double instance variables must be nonnegative. Assign 0 if the variables are negative.
Answer:
void foodType________(string s, int c, double f, int su,
double cr, double p)
{
name = s;
if (_____)
calories =___;
else
calories =___;
if (_____)
fat =___;
else
fat =___;
if (_____)
sugar =___;
else
sugar =___;
if (_____)
carbohydrate =___;
else
carbohydrate =___;
if (_____)
potassium =___;
else
potassium =___;
}
Fill in the underlines below to complete the definition of the member function print that prints the values of the data members.
Answer:
void foodType_______ const
{
_____<< "Name: "<<_____<< endl;
_____<< "Calories: "<<_____<< endl;
_____<< "Fat: "<<_____<< endl;
_____<< "Sugar: "<<_____<< endl;
_____<< "Carbohydrate: "<<_____<< endl;
_____<< "potassium: "<<_____<< endl;
}
Fill in the underlines below to complete the definitions of the member functions getName, getCalories, getFat, getSugar, getCarbohydrate, getPotassium to return the values of the instance variable.
Answer:
string foodType_________ const
{
return _____;
}
int foodType_________ const
{
return _____;
}
double foodType_________ const
{
return _____;
}
int foodType_________ const
{
return _____;
}
double foodType_________ const
{
return _____;
}
double foodType_________ const
{
return _____;
}
Fill in the underlines below to complete the definition of the default constructor of the class foodType so that the private member variables are initialized to "",0,0.0,0,0.0,0.0, respectively.
Answer:
foodType___________
{
set(____________________);
}
Fill in the underlines below to complete the definition of the constructor with parameters of the class foodType so that the private member variables are initialized according to the parameters. The values of the int and double instance variables must be nonnegative.
Answer:
foodType________(string s, int c, double f, int su,
double cr, double p)
{
__________________;
}
Fill in the underlines below to write a C++ statement that prints the value of the object fruit2.
Answer:
fruit2_____________;
Fill in the underlines below to write a C++ statement that declares an object myFruit of type foodType, and initializes the member variables of myFruit to "Apple", 52,0.2,10,13.8, and 148.0, respectively.
Answer:
foodType _____(______________________);

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 Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

=+2. If not, what else do you think it should do?

Answered: 1 week ago

Question

What is the orientation toward time?

Answered: 1 week ago

Question

4. How is culture a contested site?

Answered: 1 week ago