From planetesimals to terrestrial planets: N-body simulations including the effects of nebular gas and giant planets