Question: Error message when I try to complie. Please help me fix it then able to get the output // List342.h #pragma once #include #include #include
Error message when I try to complie. Please help me fix it then able to get the output
// List342.h
#pragma once
#include
#include
#include "Child.h"
using namespace std;
template
class List342
{
template
friend ostream& operator<<(ostream &output, List342
public:
List342();
List342(List342 &passList);
~List342();
bool Insert(ItemType *obj);
void DeleteList();
bool isEmpty() const;
private:
struct Node
{
ItemType *data;
Node *next;
};
Node *head;
};
template
List342
{
this->head = NULL;
};
template
List342
{
this->head = NULL;
*this = passList;
};
template
List342
{
DeleteList();
};
template
bool List342
{
if (obj == NULL)
{
return false;
}
if (head != NULL && *obj == *head->data)
{
return false;
}
Node* temp = new Node;
ItemType *pData = new ItemType;
(*pData) = (*obj);
temp->data = pData;
if (head == NULL || *temp->data < *head->data)
{
temp->next = head;
head = temp;
temp = NULL;
return true;
}
Node* current = head->next;
Node* previous = head;
while (current != NULL && *current->data <= *temp->data)
{
previous = current;
current = current->next;
}
if (*previous->data == *temp->data)
{
delete temp;
temp = NULL;
return false;
}
temp->next = current;
previous->next = temp;
temp = NULL;
current = NULL;
previous = NULL;
return true;
};
template
void List342
{
if (head == NULL)
{
return;
}
while (head != NULL)
{
Node* toDelete = head;
head = head->next;
delete toDelete->data;
toDelete->data = NULL;
delete toDelete;
toDelete = NULL;
}
head = NULL;
};
template
bool List342
{
if (head == NULL)
{
return true;
}
return false;
};
template
ostream &operator <<(ostream &output,List342
{
if (passObj.isEmpty())
{
return output;
}
List342
while (current != NULL)
{
output << *current->data;
current = current->next;
}
current = NULL;
return output;
};
// Child.h
#pragma once
#include
#include
#include "List342.h"
using namespace std;
class Child
{
friend istream& operator>>(istream &input, Child &inChild);
friend ostream& operator<<(ostream &output, const Child &outChild);
public:
Child();
Child(string passFirstName, string passLastName, int passAge);
Child(const Child &passChild);
~Child();
void setAge(int);
int getAge() const;
void setFirstName(string);
string getFirstName() const;
void setLastName(string);
string getLastName() const;
bool operator<(const Child &passChild) const;
bool operator<=(const Child &passChild) const;
bool operator>(const Child &passChild) const;
bool operator>=(const Child &passChild) const;
bool operator==(const Child &passChild) const;
bool operator!=(const Child &passChild) const;
Child& operator=(const Child &passChild);
private:
string firstName;
string lastName;
int age;
};
// Child.cpp
#include "Child.h"
#include "List342.h"
using namespace std;
Child::Child()
{
firstName = "Unknown";
lastName = "Unknown";
age = -1;
};
Child::Child(string passFirstName, string passLastName, int passAge)
{
firstName = passFirstName;
lastName = passLastName;
age = passAge;
};
Child::~Child() {};
Child::Child(const Child &passChild)
{
firstName = passChild.firstName;
lastName = passChild.lastName;
age = passChild.age;
};
void Child::setAge(int passAge)
{
age = passAge;
};
int Child::getAge() const
{
return age;
};
void Child::setFirstName(string passFirstName)
{
firstName = passFirstName;
};
string Child::getFirstName() const
{
return firstName;
};
void Child::setLastName(string passLastName)
{
lastName = passLastName;
};
string Child::getLastName() const
{
return lastName;
};
bool Child::operator<(const Child &passChild) const
{
return (lastName < passChild.lastName);
};
bool Child::operator<=(const Child &passChild) const
{
if ((lastName < passChild.lastName) || (*this == passChild))
{
return true;
}
return false;
};
bool Child::operator>(const Child &passChild) const
{
return (lastName > passChild.lastName);
};
bool Child::operator>=(const Child &passChild) const
{
if ((lastName > passChild.lastName) || (*this == passChild))
{
return true;
}
return false;
};
bool Child::operator==(const Child &passChild) const
{
return ((firstName == passChild.firstName) &&
(lastName == passChild.lastName) &&
(age == passChild.age));
};
bool Child::operator!=(const Child &passChild) const
{
return ((firstName != passChild.firstName) &&
(lastName != passChild.lastName) &&
(age != passChild.age));
};
Child& Child::operator=(const Child &passChild)
{
lastName = passChild.lastName;
firstName = passChild.firstName;
age = passChild.age;
return *this;
};
istream& operator>>(istream &input, Child &inChild)
{
string tempFirst, tempLast;
int tempAge;
input >> tempFirst >> tempLast >> tempAge;
inChild.setAge(tempAge);
inChild.setFirstName(tempFirst);
inChild.setLastName(tempLast);
return input;
}
ostream& operator<<(ostream &output, const Child &outChild)
{
output << outChild.firstName << outChild.lastName << outChild.age;
return output;
}
// main.cpp
#include
#include
#include "List342.h"
#include "Child.h"
using namespace std;
int main()
{
Child c1("Angie", "Ham", 7), c2("Pradnya", "Dhala", 8),
c3("Bill", "Vollmann", 13), c4("Cesar", "Ruiz", 6);
Child c5("Piqi", "Tangi", 7), c6("Pete", "Rose", 13),
c7("Hank", "Aaron", 3), c8("Madison", "Fife", 7);
Child c9("Miles", "Davis", 65), c10("John", "Zorn", 4), c11;
List342
int a = 1, b = -1, c = 13;
class1.Insert(&c1);
class1.Insert(&c2);
class1.Insert(&c3);
class1.Insert(&c4);
class1.Insert(&c5);
class1.Insert(&c6);
class1.Insert(&c5);
cout << endl << "class1: " << class1 << endl;
if (class1.Insert(&c1))
{
cout << endl << "ERROR::: Duplicate" << endl;
}
class2.Insert(&c4);
class2.Insert(&c5);
class2.Insert(&c6);
class2.Insert(&c7);
class2.Insert(&c10);
cout << endl << "Class2: " << class2 << endl;
system("pause");
return 0;
};
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
