  Prompt D meson and non-prompt J/$\psi$ yields are studied as a function of
the multiplicity of charged particles produced in inelastic proton-proton
collisions at a centre-of-mass energy of $\sqrt{s}=7$ TeV. The results are
reported as a ratio between yields in a given multiplicity interval normalised
to the multiplicity-integrated ones (relative yields). They are shown as a
function of the multiplicity of charged particles normalised to the average
value for inelastic collisions (relative charged-particle multiplicity). D$^0$,
D$^+$ and D$^{*+}$ mesons are measured in five $p_{\rm T}$ intervals from 1 to
20 GeV/$c$ and for $|y|<0.5$ via their hadronic decays. The D-meson relative
yield is found to increase with increasing charged-particle multiplicity. For
events with multiplicity six times higher than the average multiplicity of
inelastic collisions, a yield enhancement of a factor about 15 relative to the
multiplicity-integrated yield in inelastic collisions is observed. The yield
enhancement is independent of transverse momentum within the uncertainties of
the measurement. The D$^0$-meson relative yield is also measured as a function
of the relative multiplicity at forward pseudorapidity. The non-prompt
J/$\psi$, i.e. the B hadron, contribution to the inclusive J/$\psi$ production
is measured in the di-electron decay channel at central rapidity. It is
evaluated for $p_{\rm T}>1.3$ GeV/$c$ and $|y|<0.9$, and extrapolated to
$p_{\rm T}>0$. The fraction of non-prompt J/$\psi$ in the inclusive J/$\psi$
yields shows no dependence on the charged-particle multiplicity at central
rapidity. Charm and beauty hadron relative yields exhibit a similar increase
with increasing charged-particle multiplicity. The measurements are compared to
PYTHIA 8, EPOS 3 and percolation calculations.
