The cockpit in earlier planes used to be open air in design. But as the planes developed to fly faster, and more important, higher, the need for an enclosed cockpit became high.
The cockpit essentially contains the pilot and much of his avionics and other requirements. In modern jets, much of the electronic equipment is either in the cockpit (usually around him and under his seat), or in the nose.