Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

True/False Answer the following true/false questions. You must correctly state W

ID: 3910970 • Letter: T

Question

True/False
Answer the following true/false questions. You must correctly state WHY your answer is true or false.
#include <iostream>
using namespace std;
class Food{
protected:
float price;
public:
void give_info(float price)
{
this->price=price;
}
float get_price(){
return price;
}
void change_price(float a)
{
price=a;
}
};
class Watermelon: public Food{
bool seedless;
public:
void set_seed(int a)
{
if(a<3)
{
seedless=true;
}
else
{
seedless=false;
}
}
bool get_seedless()
{
return seedless;
}
};
class Apple: protected Food{
};
class Grape: private Food{
string color;
public:
int number;
}
class Employee{
public:
void discount(Food &f1)
{
float amount;
cout <<"How much of a discount? (Enter in decimal form)"<<endl;
cin>>amount;
f1.change_price(f1.get_price()*(1-amount));
}
//true=both, false=not both
bool check_watermelon(Watermelon w1, Watermelon w2)
{
bool ret=false;
if(w1.get_seedless() && w2.get_seedless())
{
ret=true;
}
return ret;
}
};


For the following questions, assume any lines of code given are in the main function. Also assume:
w1 refers to a Watermelon object, a1 refers to an Apple object, f1 refers to a Food object, g1
refers to a Grape object and e1 refers to an Employee object.
1. Watermelon w1; would be a valid line of code, but Apple a1; would not be.
2. e1.discount(w1); would be a valid line of code.
3. e1.discount(f1); would be a valid line of code.
4. The function set_seed() in the Watermelon class is unnecessary since we could just say
w1.seedless=true; .
5. a1.give_info(2.99); would be a valid line of code.
6. f1.number=3; would be a valid line of code, but f1.color=”blue”; would not be.
7. f1.price=2.99; would be a valid line of code, but w1.price=2.99; would not be.
8. e1.check_watermelon(w1, f1); would be a valid line of code since Watermelon is a derived
class from Food.
9. a1.set_seed(); would be a valid line of code since Apple and Watermelon are derived from
the same base class.
10. Because Grape privately inherits from Food, g1.number=4; would not be a valid line
of code.

2/6

Explanation / Answer

1. False, both Watermelon w1; and Apple a1, statements will create objects of the respective classes, and are valid lines of codes, the visualization accessor for the inheritance from the Food class does not effect the syntax for creation of object
2. True, e1.discount(w1); is valid line of code, because the class Watermelon inherites all the properties of Food class publically, thus all the properties are of Food class ae also in the Watermelon class, thus, it is possible to refer to the members of Food class using Watermelon object w1.
3. True, e1.discount(f1); discount function of class Employee takes the argument of Food class, that is represented by the given line of code, hence is valid.
4. False, the function set_seed(), sets the seedless to both true and false, true in the case the input argument a is less than 3, false otherwise, thus the presented statement is False.
5. True, a1.give_info(2.99); would be valid line of code, because the function can be available as protected visual accessor in the Apple class that inherits the function give_info(), from Food class.
6. False, f1.number=3; and f1.color="blue", both are invalid line of code, because number and color are not defined as the data member of Food class.
7. False, f1.price=2.99; w1.price=2.99; would be a invalid line of code, the price is defined as Protected visual accessor, thus making it not to be possible to be accessed outside the class.
8. False, e1.check_watermelon(w1, f1); would not be a valid line of code because properties of Watermelon can not be accessed from Food class.
9. False, as Apple inherites from Food protectedly, it is not possible to call the members of Food class outside the Apple class with the objet of Apple class.
10. False, number is the public member of Grape class, hence can be called from any where from the program with the object of the Grape class g1.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote