John Ternus, head of the company’s hardware division, will succeed Cook, who will become executive chairman.