Make a class named Fruit and Vegetables with a data member to calculate the number of fruits and Vegetables in a basket. Create four other class named Apples, Mangoes , carrot and Potato to calculate the number of Fruits and Vegetables in the basket. Print the number of fruits and Vegetables of each type and the total number of fruits in the basket.
#include <iostream>
using namespace std;
static int mangoes = 0, apples = 0, potatoes = 0, carrots = 0;
class Fruit_and_Vegetables{
public:
Fruit_and_Vegetables(){}
void display(){
cout<<apples<<" apples\n";
cout<<mangoes<<" mangoes\n";
cout<<carrots<<" carrots\n";
cout<<potatoes<<" potatoes\n";
cout<<mangoes + apples<<" fruits\n";
cout<<carrots + potatoes<<" vegetables\n";
}
};
class Apples{
public:
Apples(){
apples++;
}
};
class Mangoes{
public:
Mangoes(){
mangoes++;
}
};
class Carrots{
public:
Carrots(){
carrots++;
}
};
class Potato{
public:
Potato(){
potatoes++;
}
};
int main(){
Potato a, b, c, d;
Carrots e, f, g, h;
Apples i, j, k, l;
Mangoes m, n, o, p;
Fruit_and_Vegetables basket;
basket.display();
return 0;
}
Comments
Leave a comment