Please help me fix the code in the image for the code below. Errors are in lines 35, 37, 47, and 51. .cpp File: #include #include #include #include "ArrayList.h" using namespace std; // Exception class definition class ArrayListException { private:     string message; public:     ArrayListException(const string& message) : message(message) {}     string getMessage() const { return message; } }; // Node class definition template class ArrayList::Node { public:     T data;     Node* next;     Node(const T& data, Node* next = nullptr) : data(data), next(next) {} }; // ArrayList class definitions template ArrayList::ArrayList() : rear(nullptr), length(0) {} template ArrayList::~ArrayList() {     Node* current = rear->next;     while (current != rear) {         Node* temp = current;         current = current->next;         delete temp;     }     delete rear; } template bool ArrayList::isEmpty() const {     return (rear == nullptr); } template int ArrayList::size() const {     return length; } template void ArrayList::insert(const T& item) {     Node* newNode = new Node(item);     if (rear == nullptr) {         rear = newNode;         rear->next = rear;     } else {         newNode->next = rear->next;         rear->next = newNode;         rear = newNode;     }     length++; } template void ArrayList::remove(const T& item) {     if (rear == nullptr) {         throw ArrayListException("Cannot remove item from empty ArrayList");     }     Node* current = rear->next;     Node* prev = rear;     bool found = false;     do {         if (current->data == item) {             found = true;             break;         }         prev = current;         current = current->next;     } while (current != rear->next);     if (found) {         if (rear->next == rear) {             rear = nullptr;         } else if (current == rear) {             rear = prev;         }         prev->next = current->next;         delete current;         length--;     } else {         throw ArrayListException("Item not found in ArrayList");     } } template void ArrayList::print() const {     if (rear == nullptr) {         cout << "[]";         return;     }     cout << "[";     Node* current = rear->next;     while (current != rear) {         cout << current->data << ", ";         current = current->next;     }     cout << current->data << "]"; } .h File #include #include #ifndef ARRAYLIST_H #define ARRAYLIST_H using namespace std; class ArrayListException : public exception { private:     string msg; public:     ArrayListException(string message) : msg(message) {}     virtual const char* what() const throw() {         return msg.c_str();     } }; template class ArrayList { private:     class Node {     public:         T data;         Node* next;         Node(T item) : data(item), next(nullptr) {}     };     Node* rear;     int length; public:     ArrayList() : rear(nullptr), length(0) {}     ~ArrayList() {         while (rear != nullptr) {             Node* temp = rear->next;             delete rear;             rear = temp;         }     }     void insert(T item) {         Node* newNode = new Node(item);         if (rear == nullptr) {             newNode->next = newNode;         }         else {             newNode->next = rear->next;             rear->next = newNode;         }         rear = newNode;         length++;     }     void remove(T item) {         if (rear == nullptr) {             throw ArrayListException("Error: Cannot remove item from empty list.");         }         Node* current = rear;         Node* previous = nullptr;         bool found = false;         do {             if (current->data == item) {                 found = true;                 break;             }             previous = current;             current = current->next;         } while (current != rear->next);         if (!found) {             throw ArrayListException("Error: Item not found in list.");         }         if (previous == nullptr) {             rear = nullptr;         }         else {             previous->next = current->next;             if (current == rear) {                 rear = previous;             }         }         delete current;         length--;     }     T get(int index) const {         if (index < 0 || index >= length) {             throw ArrayListException("Error: Index out of range.");         }         Node* current = rear->next;         for (int i = 0; i < index; i++) {             current = current->next;         }         return current->data;     }     int size() const {         return length;     } }; #endif

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Please help me fix the code in the image for the code below. Errors are in lines 35, 37, 47, and 51.

.cpp File:

#include <iostream>
#include <cassert>
#include <string>
#include "ArrayList.h"
using namespace std;
// Exception class definition
class ArrayListException {
private:
    string message;
public:
    ArrayListException(const string& message) : message(message) {}
    string getMessage() const { return message; }
};
// Node class definition
template<typename T>
class ArrayList<T>::Node {
public:
    T data;
    Node<T>* next;
    Node<T>(const T& data, Node<T>* next = nullptr) : data(data), next(next) {}
};
// ArrayList class definitions
template<typename T>
ArrayList<T>::ArrayList() : rear(nullptr), length(0) {}
template<typename T>
ArrayList<T>::~ArrayList() {
    Node<T>* current = rear->next;
    while (current != rear) {
        Node<T>* temp = current;
        current = current->next;
        delete temp;
    }
    delete rear;
}
template<typename T>
bool ArrayList<T>::isEmpty() const {
    return (rear == nullptr);
}
template<typename T>
int ArrayList<T>::size() const {
    return length;
}
template<typename T>
void ArrayList<T>::insert(const T& item) {
    Node<T>* newNode = new Node<T>(item);
    if (rear == nullptr) {
        rear = newNode;
        rear->next = rear;
    } else {
        newNode->next = rear->next;
        rear->next = newNode;
        rear = newNode;
    }
    length++;
}
template<typename T>
void ArrayList<T>::remove(const T& item) {
    if (rear == nullptr) {
        throw ArrayListException("Cannot remove item from empty ArrayList");
    }
    Node<T>* current = rear->next;
    Node<T>* prev = rear;
    bool found = false;
    do {
        if (current->data == item) {
            found = true;
            break;
        }
        prev = current;
        current = current->next;
    } while (current != rear->next);
    if (found) {
        if (rear->next == rear) {
            rear = nullptr;
        } else if (current == rear) {
            rear = prev;
        }
        prev->next = current->next;
        delete current;
        length--;
    } else {
        throw ArrayListException("Item not found in ArrayList");
    }
}
template<typename T>
void ArrayList<T>::print() const {
    if (rear == nullptr) {
        cout << "[]";
        return;
    }
    cout << "[";
    Node<T>* current = rear->next;
    while (current != rear) {
        cout << current->data << ", ";
        current = current->next;
    }
    cout << current->data << "]";
}

.h File

#include <string>
#include <iostream>
#ifndef ARRAYLIST_H
#define ARRAYLIST_H
using namespace std;
class ArrayListException : public exception {
private:
    string msg;
public:
    ArrayListException(string message) : msg(message) {}
    virtual const char* what() const throw() {
        return msg.c_str();
    }
};
template <typename T>
class ArrayList {
private:
    class Node {
    public:
        T data;
        Node* next;
        Node(T item) : data(item), next(nullptr) {}
    };
    Node* rear;
    int length;
public:
    ArrayList() : rear(nullptr), length(0) {}
    ~ArrayList() {
        while (rear != nullptr) {
            Node* temp = rear->next;
            delete rear;
            rear = temp;
        }
    }
    void insert(T item) {
        Node* newNode = new Node(item);
        if (rear == nullptr) {
            newNode->next = newNode;
        }
        else {
            newNode->next = rear->next;
            rear->next = newNode;
        }
        rear = newNode;
        length++;
    }
    void remove(T item) {
        if (rear == nullptr) {
            throw ArrayListException("Error: Cannot remove item from empty list.");
        }
        Node* current = rear;
        Node* previous = nullptr;
        bool found = false;
        do {
            if (current->data == item) {
                found = true;
                break;
            }
            previous = current;
            current = current->next;
        } while (current != rear->next);
        if (!found) {
            throw ArrayListException("Error: Item not found in list.");
        }
        if (previous == nullptr) {
            rear = nullptr;
        }
        else {
            previous->next = current->next;
            if (current == rear) {
                rear = previous;
            }
        }
        delete current;
        length--;
    }
    T get(int index) const {
        if (index < 0 || index >= length) {
            throw ArrayListException("Error: Index out of range.");
        }
        Node* current = rear->next;
        for (int i = 0; i < index; i++) {
            current = current->next;
        }
        return current->data;
    }
    int size() const {
        return length;
    }
};
#endif

ArrayList.cpp:35:1: error: redefinition of 'ArrayList::ArrayList()'
35 | ArrayList<T>::ArrayList(): rear(nullptr), length(0) {}
In file included from ArrayListTester.cpp:16:
ArrayList.cpp:37:1: error: redefinition of 'ArrayList::~ArrayList()'
37 | ArrayList<T>::~ArrayList() {
In file included from ArrayListTester.cpp:16:
ArrayList.cpp:47:6: error: no declaration matches 'bool ArrayList::isEmpty() const'
47 | bool ArrayList<T>:: isEmpty() const {
In file included from ArrayList Tester.cpp:16:
ArrayList.cpp:51:5: error: redefinition of 'int ArrayList::size() const'
51 | int ArrayList<T>::size() const {
I
Transcribed Image Text:ArrayList.cpp:35:1: error: redefinition of 'ArrayList::ArrayList()' 35 | ArrayList<T>::ArrayList(): rear(nullptr), length(0) {} In file included from ArrayListTester.cpp:16: ArrayList.cpp:37:1: error: redefinition of 'ArrayList::~ArrayList()' 37 | ArrayList<T>::~ArrayList() { In file included from ArrayListTester.cpp:16: ArrayList.cpp:47:6: error: no declaration matches 'bool ArrayList::isEmpty() const' 47 | bool ArrayList<T>:: isEmpty() const { In file included from ArrayList Tester.cpp:16: ArrayList.cpp:51:5: error: redefinition of 'int ArrayList::size() const' 51 | int ArrayList<T>::size() const { I
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education