Answer to Question #186597 in C++ for Ravi kumar pandey

Question #186597

Create a class named Fruit with a data member to calculate the number of fruits in a basket. Create two other class named Apples and Mangoes derived from class Fruit to calculate the number of apples and mangoes in the basket. Print the number of fruits of each type and the total number of fruits in the basket


1
Expert's answer
2021-04-28T09:50:56-0400
#include <iostream>
using std::cout;
using std::cin;
using std::endl;


class Fruit
{
public:
	void set_amount(int n) 
	{
		amount_fruit = n;
	}
	int get_amount() 
	{
		return amount_fruit;
	}
protected:
	int amount_fruit{ 0 };


};


class Apples :public Fruit
{
public:
};
class Mangoes :public Fruit
{
public:
};


int main()
{
	Apples apple;
	Mangoes mango;
	int numb_fruit;
	cout << "Enter the number of apples: ";
	cin >> numb_fruit;
	apple.set_amount(numb_fruit);
	cout << "Enter the number of mangoes: ";
	cin >> numb_fruit;
	mango.set_amount(numb_fruit);
	cout << "Quanity of apples in the basket " << apple.get_amount() << endl;
	cout << "Quanity mangoes in the basket " << mango.get_amount() << endl;
	cout << "The total number of fruits in the basket " << apple.get_amount() + mango.get_amount() << endl;
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS