Theory of single-electron charging of quantum wells and dots