سَافَرَ خَالِدٌ وَصَدِيقًا
Khalid travelled with a friend.
- خَالِدٌ is the doer.
- صَدِيقًا is the accompanying mansub noun.
خَرَجَ الْمُعَلِّمُ وَطَالِبًا
The teacher went out with a student.
- الْمُعَلِّمُ is the doer.
- طَالِبًا is maf'ul ma'ahu.
The nouns differ, but the reasoning is the same: waw means with, and the companion after it is mansub.