I've written a program that keeps a linked list of Personnel. The Personnel can be of the type Student(inherited from Personnel) each student has the name and id from Personnel and a Queue of type books. Everything works except it doesn't display the list of books. please offer any help here is my code

struct Book{								//Number 1
	char title[30];
	long dueDate;
	struct Book *next;
	};

	void display(void){								//Display function for part 2.4
	struct Book *temp;
	temp=front;
	while(temp!=0){
		cout<<"The title of the book:\n"<<temp->title<<endl;
		cout<<"The due date of the book is:\n\n"<<temp->dueDate<<endl;
	}

	void display(void){									//Number 3 part 3
		Personnel::display();
		cout<<"Student"<<endl;
		cout<<"Level:\t"<<x<<endl;
		cout<<"Books:\t"<<endl;
		bookQueue->display();
		}

and here's how i'm inserting a book to a particular student

int insert_book(void){							//Number 4 part 2
	Personnel *person=NULL;
	PersonnelNode *node=NULL;
	PersonnelNode *temp, *prev;
	Student *s=new Student();

	temp=head;
	int index=1;
	char name[50], title[30];
	long due;
	cout<<"Enter the name: ";
	cin.ignore();
	cin.getline(name, 50);
	cout<<"Enter the title of the book: ";
	cin.ignore();
	cin.getline(title, 30);
	cout<<"Enter the due date of the book: ";
	cin.ignore();
	cin>>due;
		 while (temp != NULL) {
		 person = temp->getNode();
		 if (stricmp(name,name)==0){
				prev = temp;
				temp = temp->getNext();
				index++;
			}
		 else{
			cout <<"Person to delete is found at index" << index<<endl;
			display_node(person, index);
			s=(Student*)person;							//This changes person from a type personnel pointer to type Student using casting
			s->bookQueue->enqueue(title, due);			//Calls the pointer s to access bookQueue then calls the method enqueue using enqueue
			}
		 
		 }

Dani AI

Generated

A few focused points that explain why the books never show and how to fix the search/enqueue logic.

The most likely causes

  • The book-list display loop never advances its pointer, so it either prints nothing (if front is null) or loops forever. Make sure each iteration moves to the next node.
  • The student-search/enqueue routine has multiple logic problems: input handling (extra ignores), comparing the input to itself instead of the node's name, creating a new Student then throwing it away (memory leak), and using the wrong branch when a match is found. Any one of those will prevent the book from being enqueued into the correct student.

Concrete, safe fixes to try

  • Fix the queue display to iterate correctly and handle an empty queue (example uses safer C++ idioms and a simple traversal):
void BookQueue::display() const {
    Book* cur = front;
    while (cur) {
        std::cout << "Title: " << cur->title << "\nDue: " << cur->dueDate << "\n\n";
        cur = cur->next;
    }
}
  • Search the personnel list correctly, test type before casting, and only enqueue when the student is found. Avoid allocating a temporary Student. Use dynamic_cast<Student*> if Personnel is polymorphic, and handle input with std::getline or a single cin.ignore(...) to clear the leftover newline.

Quick debugging checklist

  • Add temporary prints inside the search loop to confirm you visit each node and what name is compared.
  • Verify bookQueue is initialized for each Student before calling enqueue.
  • Check enqueue actually sets the new node’s next and updates front/rear as needed.
  • Run under a debugger or add assertions to catch null pointers early.

If these changes don’t reveal the problem, post: the Student class constructor, the queue enqueue implementation, and the exact input sequence used; that will make root-cause diagnosis precise.

with such a small amount of code how do you think anyone is going to know the answer to your question? But my guess is that the display() function is never called.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.