Line 11: prev implies that this is a doubly linked list, but you never access this member anywhere in the code. So should this be a doubly or singly linked list?
add() will add at the end of the list, but only because newPerson points there. I suggest that you rename newPerson to be tail, which is much more common.
Consider using a for loop in output:
1 2 3 4 5 6 7
void
output()
{
for (cur = head->next; cur != NULL; cur = cur->next) {
cout << cur->name << endl;
}
}
I think this is much clearer because all of the loop logic is contained within the for() statement and the "what to do each time through the loop" logic is in the body of the loop.
To insert at the nth position, create a local person pointer called prev and advance prev to the n-1th item of the list. Then new item will go right after prev.
// Attempt to insert data at position pos (where pos==0 means the
// head) If pos > list size then insert at end. Returns the actual
// position where it was inserted.
unsigned List::addNth(int data, unsigned pos)
{
Node *newNode = new Node;
newNode->data = data;
Node *prev = nullptr; // previous node
Node *cur; // current node
unsigned p; // position where newNode inserted
// Walk prev and cur down the list until you reach the end or
// the pos'th node
for (cur=head, p=0; p < pos && cur; prev = cur, cur = cur->next) {
++p;
}
if (prev) {
newNode->next = cur;
prev->next = newNode;
} else {
newNode->next = head;
head = newNode;
}
return p;
}