Not sure about the Airbus, but the 747 grew out of a design request by the US Air Force for a heavy lift transport. One of the requirements was that the aircraft be loaded from the front as well as the rear. To do this, the cockpit has to be swung out of the way with the door or, as Boeing (and the eventual winner, Lockheed) chose, move the cockpit above the cargo deck.
Boeing took the design to PanAm and kept the freight design figuring that passengers would end up on supersonic aircraft, leaving freight to subsonic craft.
Not the first time the cockpit was above the cargo deck, check out Freddie Laker’s Carvair, it’s like a propeller powered 747!
on preview, ElvisL1ves already covered this. Blast. At least I got to mention the Carvair, one of my favorites.