Monte Carlo simulation of elastic and inelastic scattering of electrons in thin films. II. Core electron losses