Recent observations started revealing the compositions of protostellar disks and planets beyond the solar system. In this paper, we explore how the compositions of terrestrial planets are affected by the dynamical evolution of giant planets. We estimate the initial compositions of the building blocks of these rocky planets by using a simple condensation model, and numerically study the compositions of planets formed in a few different formation models of the solar system. We find that the abundances of refractory and moderately volatile elements are nearly independent of formation models, and that all the models could reproduce the abundances of these elements of the Earth. The abundances of atmophile elements, on the other hand, depend on the scattering rate of icy planetesimals into the inner disk, as well as the mixing rate of the inner planetesimal disk. For the classical formation model, neither of these mechanisms are efficient and the accretion of atmophile elements during the final assembly of terrestrial planets appears to be difficult. For the Grand Tack model, both of these mechanisms are efficient, which leads to a relatively uniform accretion of atmophile elements in the inner disk. It is also possible to have a "hybrid" scenario where the mixing is not very efficient but the scattering is efficient. The abundances of atmophile elements in this case increase with orbital radii. Such a scenario may occur in some of the extrasolar planetary systems, which are not accompanied by giant planets or those without strong perturbations from giants. We also confirm that the Grand Tack scenario leads to the distribution of asteroid analogues where rocky planetesimals tend to exist interior to icy ones, and show that their overall compositions are consistent with S-type and C-type chondrites, respectively.