Shares of industrial and transportation companies rose amid optimism about the outlook for U.S. economic activity.

While consumer sentiment has slumped to an all-time low, demand for artificial-intelligence infrastructure has created a construction boom, buoying fortunes for makers of electrical and industrial equipment.

Shares of Caterpillar, which has seen torrid growth in sales of generators and other electrical gear, rose by more than 2% and is up about 48% for the year to date.

Defense consulting firm Booz Allen Hamilton posted an increase in fiscal fourth-quarter profit as its cost-cutting initiatives helped to offset declines in revenue.

Write to Rob Curran at rob.curran@dowjones.com