I've seen that cakes can turn a comparator on, and the number of slices available corresponds to the signal strength. I was thinking about using an inverter to activate a dispenser and place a new cake after the first one is totally consumed. However, the dispenser will only drop the cake as an item, and not place in on the ground, ready to be eaten. Is it possible to place the cake on the ground automatically?
In Survival? No.
With commands? Yes, you could for example place a pumpkin into the dispenser instead and have a repeating command block somewhere (or ticking function) with
/fill <coordinates> <coordinates> cake replace pumpkin, where both coordinate sets are the same, the one block where the cake should be.