Question: Please explain step by step: Protected Members You work at a grocery store and want to build an app to manage the products in the
Please explain step by step:
Protected Members You work at a grocery store and want to build an app to manage the products in the store. You make a Product base class and separate classes for each product type. Inherit the Fruit class from Product and make sure the given code works correctly. The code tries to access the private members of Product in the Fruit class. Fix it by applying the correct access specifier.
#include
using namespace std;
class Product
{
private:
double price;
int weight;
public:
void info() {
cout < } }; class Fruit { public: string type; void setInfo(double p, int w) { price = p; weight = w; } }; int main() { Fruit obj; obj.type = "Apple"; obj.setInfo(4.99, 10); obj.info(); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
