Quantum size effects in metal nanofilms: Comparison of an electron-gas model and density functional theory calculations