Doctors and teachers will be given a 4% pay rise after the government accepted recommendations from independent review bodies.