Formation of galaxies and large-scale structure with cold dark matter