Answer to Question #231993 in C++ for mahnoor

Question #231993

Make 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 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-09-03T00:10:04-0400
#include <iostream>
using namespace std;


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