Question: #include using namespace std; class BookRecord { public: string title = NULL; string author = NULL; int num _ pages = - 1 ; int

#include
using namespace std;
class BookRecord {
public:
string title = "NULL";
string author = "NULL";
int num_pages =-1;
int year_published =-1;
bool is_equiv(BookRecord rhs){
if ((title == rhs.title) && (author == rhs.author) && (num_pages == rhs.num_pages)
&& (year_published == rhs.year_published)){
return true;
}
else {
return false;
}
}
void display(){
cout << "Author Name: "<< author << endl;
cout << "Title: "<< title << endl;
cout << "Pages: "<< num_pages << endl;
cout << "Year Published: "<< year_published << endl;
cout << endl;
}
};
class Node {
public:
BookRecord data;
Node* next = nullptr;
Node* prev = nullptr; // New prev pointer for doubly linked list
};
class DoublyLinkedList {
private:
Node* head = nullptr;
Node* tail = nullptr; // Pointer to the last node for convenience
public:
void display();
void display_reverse();
void insertHead(BookRecord val);
void insertEnd(BookRecord val);
void insertAt(BookRecord val, int pos);
void deleteHead();
void deleteEnd();
void deleteAt(int pos);
int size();
DoublyLinkedList();
DoublyLinkedList(BookRecord vals[], int num_vals);
DoublyLinkedList(const DoublyLinkedList& orig);
~DoublyLinkedList();
};
// Definitions
void DoublyLinkedList::insertHead(BookRecord val){
Node* new_node = new Node();
newNode ->data = val;
if(!head)
head = new Node();
head->data=val;
}
}
void DoublyLinkedList::display(){
Node* temp = head;
while (){
}
}
void DoublyLinkedList::display_reverse(){
}
void DoublyLinkedList::insertEnd(BookRecord val){
}
void DoublyLinkedList::insertAt(BookRecord val, int pos){
}
void DoublyLinkedList::deleteHead(){
}
void DoublyLinkedList::deleteEnd(){
}
void DoublyLinkedList::deleteAt(int pos){
}
int DoublyLinkedList::size(){
return -1;
}
DoublyLinkedList::DoublyLinkedList(){
cout << "Calling default constructor." << endl;
}
DoublyLinkedList::DoublyLinkedList(BookRecord vals[], int num_vals){
cout << "Calling parameterized constructor!" << endl;
}
DoublyLinkedList::DoublyLinkedList(const DoublyLinkedList& orig){
cout << "Executing copy constructor for DoublyLinkedList!" << endl;
}
DoublyLinkedList::~DoublyLinkedList(){
cout << "Executing Destructor for DoublyLinkedList!" << endl;
}
void foo(DoublyLinkedList lst){
lst.display();
cout << endl;
}
int main(){
BookRecord book1, book2, book3, book4;
book1.title = "Digital Design and Computer Architecture";
book1.num_pages =720;
book1.year_published =2012;
book1.author = "David Harris";
book2.title = "A Game of Thrones";
book2.num_pages =496;
book2.year_published =1996;
book2.author = "George R. R. Martin";
book3.title = "Thrawn (Star Wars)";
book3.num_pages =835;
book3.year_published =2018;
book3.author = "Timothy Zahn";
book4.title = "The C++ Programming Language";
book4.num_pages =1376;
book4.year_published =2013;
book4.author = "Bjarne Stroustrup";
DoublyLinkedList list1;
cout <<"=========Testing insertHead()=========="<< endl;
list1.insertHead(book1);
list1.insertHead(book2);
list1.insertHead(book3);
list1.insertHead(book4);
list1.display();
cout <<"=========Testing display_reverse()=========="<< endl;
list1.display_reverse();
cout <<"=========Testing insertEnd()=========="<< endl;
list1.insertEnd(book1);
list1.insertEnd(book2);
list1.insertEnd(book3);
list1.display();
cout <<"=========Testing deleteHead()=========="<< endl;
list1.deleteHead();
list1.display();
cout <<"=========Testing size()=========="<< endl;
list1.display();
cout << "There are "<< list1.size()<<" elements in the linked list." << endl;
cout <<"=========Testing parameterized constructor.=========="<< endl;
BookRecord vals[4]={ book1, book2, book3, book4};
DoublyLinkedList list2(vals,4);
list2.display();
cout <<"=========Testing copy constructor.=========="<< endl;
foo(list2);
cout <<"=========Testing insertAt()=========="<< endl;
list1.insertAt(book3,3);
list1.display();
cout <<"=========Testing deleteEnd()=========="<< endl;
list1.deleteEnd();
list1.display();
cout <<"=========Testing deleteAt()=========="<< endl;
list1.deleteAt(1);
list1.display();
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!