You have different fruits, but the fruits all share things in common: they have a weight, a purchase price and a retail price.
All 3 of these are different for each fruit, but the formula for purchase price and retail price is the same.
purchase = weight * fruitPurchaseMultiplier;
retail = purchase * fruitRetailMultipler;
You can have a class that handles this:
#include <cstdint>
class Fruit
{
public:
Fruit(double w, double weightMultiplyForPurchase, uint32_t priceMultiplyForRetail)
: weight{w}
{
purchasePrice = weight * weightMultiplyForPurchase;
retailPrice = purchasePrice * priceMultiplyForRetail;
}
private:
double weight;
double purchasePrice;
double retailPrice;
};
Here we have a Fruit
which has the 3 traits mentioned, and you can see in its constructor it takes a weight, a purchase modifier and a retail modifier. You could just as easily take the ACTUAL value, but since it appears common for each fruit, you can let your constructor do the hard work for you.
Constructing fruits is now done like this:
int main()
{
Fruit apple{ 0.69, 0.9, 3 };
Fruit banana{ 0.55, 0.75, 5 };
}
Here you can see we have an apple which has a weight of 0.69, the modifier for its purchase price is 0.9 and the sell price is 3x. Again, you could have just supplied the actual values which might be fine for these 2 fruits, but if you have 30 fruits that won't be fun to do.
You don't need inheritance or polymorphism for this problem.