Question: //Use this C++ code for the following questions class foodInfo { public: void set(string, string, int); void print() const; string getName() const; string getGroup() const;

//Use this C++ code for the following questions

class foodInfo { public: void set(string, string, int); void print() const; string getName() const; string getGroup() const; int getCalories() const; foodInfo(); foodInfo(string, string, int);

private: string name; string group; int calories; };

foodInfo food1;

foodInfo food2 ("Banana", "Fruit", 90);

---------------------------------------------------------------------------------------------

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 foodInfo_______(string s1, string s2, int c)

{

name = ______;

group = ______;

if (______)

calories = ______;

else

calories = ______;

}

Fill in the underlines below to complete the definition of the member function print that prints the values of the data members.

Answer:

void foodInfo::print() const

{

___cout << "Name: " << __ << endl;

___cout << "Group: " << _______ << endl;

___cout << "Calories: " << _______ << endl;

}

Fill in the underlines below to complete the definitions of the member function getName to return the values of the instance variable.

Answer:

string foodInfo_______ const

{

return _______;

}

Fill in the underlines below to complete the definition of the default constructor of the class foodInfo so that the private member variables are initialized to "", ,0, respectively.

Answer:

foodInfo______________ // Default constructor

{

Set_____________;

}

Fill in the underlines below to complete the definition of the constructor with parameters of the class foodInfo 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:

foodInfo________(string s1, string s2, int c)// Constructor

{

set(_________);

}

Fill in the underlines below to write a C++ statement that prints the value of the object food2.

Answer:

____________________________________;

Fill in the underlines below to write a C++ statement that declares an object food3 of type foodInfo, and initializes the member variables of food3 to "Apple", Fruit, 52, respectively.

Answer:

____________________________________;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!