Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please I need help...I made the code editable rather than taking a photo of it s

ID: 3817747 • Letter: P

Question

please I need help...I made the code editable rather than taking a photo of it so that u won't type everything from sratch. The code is not well indented though.

//the listnode and LList classes code is below

#include <iostream>
using namespace std;
#undef NULL
const int NULL = O;
typedef int element;
const element SENTINEL = -1;
element read_element();
class listnode {
public:
element data;
listnode * next;
} ;
class LList {
private:
listnode * head;
listnode * tail;
public:
} ;
LList();
-LList();
void Print();
void InsertHead(element thing);
void InsertTail(element thing);
element DeleteHead();
void ReadForward();
void ReadBackward();
void Clean();
void Steal(LList & Victim);
void Duplicate(LList & Source);
void Reverse();

//main function code below

int main() {
LList L;
cout <<"object created and constructed, calling Print" << endl;
L.Print();
cout <<"object printed, calling ReadForward" << endl;
L.ReadForward();
cout <<"object read forward, calling Print" << endl;
L.Print();
cout <<"object printed, calling ReadBackward " << endl;
L.ReadBackward();
cout <<"object read backward, calling Print" << endl;
L.Print();
cout <<"object printed, calling Clean " << endl;
L.Clean();
cout <<"object cleaned, calling Print" << endl;
L.Print();
cout <<"object printed" << endl;
}

//the constructor code below
LList:: LList () {
// PRE: none
// POST: the N. 0. LList is valid and empty
head= NULL;
}

//code for the deconstructor
LList: : -LList (){
II PRE: the N. 0. LList is valid
II POST: the N. 0. LList is valid and empty, and its listnodes
II have been deleted
Clean();
}


//the print method code
void LList: :Print() (
II PRE: the N. 0. LList is valid
II POST: the N. 0. LList is unchanged, and its elements have
II been displayed
listnode * temp;
temp = head;
while (temp != NULL)
cout << temp -> data << endl;
temp = temp -> next;
}
}


//ReadForward code
void LList: :ReadForward(){
II PRE: the N. o. LList is
II POST: the N. 0. LList is
II have been deleted,
II containing elements
element userval;
Clean();
valid
valid,
and it
given
all of its previous listnodes
now consists of new listnodes
by the user in forward order
cout << "Enter elements, " << SENTINEL << " to stop: ";
userval = read element();
while (userval != SENTINEL){
InsertTail(userval);
userval read_element();
}
}

//ReadBackward code
void LList: :ReadBackward(){
II PRE: the N. 0. LList is valid
II POST: the N. 0. LList is valid, all of its previous listnodes
II have been deleted, and it now consists of new listnodes
II containing elements given by the user in backward order
element userval;
Clean();
cout << "Enter elements, " << SENTINEL << " to stop: ";
userval = read element();
while (userval != SENTINEL){
InsertHead(userval);
userval = read_element();
}
}


//clean method code
void LList::Clean() {
// PRE: the N. 0. LList is valid
// POST: the N. 0. LList is valid and empty, and all of its
// listnodes have been deleted
while (head!= NULL)
DeleteHead();
}


//InsertHead code
void LList::InsertHead(element thing){
// PRE: the N. 0. LList is valid
// POST: the N. 0. LList is unchanged, except that a new
// listnode containing element thing has been inserted
// at the head end of the list
listnode * temp;
temp = new listnode;
temp -> data = thing;
temp -> next = head;
if (head== NULL)
tail = temp;
else
head
}
temp;


//InsertTail code
void LList: :InsertTail(element thing) {
// PRE: the N. 0. LList is valid
// POST: the N. 0. LList is unchanged, except that a new
// listnode containing element thing has been inserted
// at the tail end of the list
listnode * temp;
temp = new listnode;
temp -> data = thing;
temp -> next = NULL;
if (head == NULL)
head = temp;
else
tail -> next
tail = temp;
}
temp;


//DeleteHead code
element LList: :DeleteHead(){
// PRE: the N. O. LList is valid and not empty
// POST: the N. 0. LList is unchanged, except that the listnode
// at the head end of the list has been deleted, and its
// data element has been returned
listnode * temp;
element thing;
temp = head;
head = head -> next;
thing = temp -> data;
delete temp;
return thing;
}

our prefessor said the setup could look like the pic below

The quiz will consist of you logging in to your District Unix Account, using the vim editor on District Unix to show me your C++ linked list test program, using the c++ command from CSTools on District Unix to compile that program with no errors and no warnings, and using the ./a-out command on District Unix to execute that program on inputs provided by me with no runtime errors and no logic errors Your C++ linked ist test program should consist of the C++ code for linked lists that we have been studying in lecture. This includes the listnode and LList classes, the provided sample main function, the constructor and destructor, and the Print, ReadForward, Read Backward, Clean InsertHead, InsertTail, and DeleteHead methods. The C++ code for all of these are available in the Resources section of the CS215 Blackboard Course shell. For the purposes of this test program, you should assume that elements are ints Your program should perform any and all necessary type-checking and range-checking data validation. Your program should not crash due to any possible inputs.

Explanation / Answer

What does read_element do? It is not defined in the code. I have cleared all the errors in the code besides read_element().

Here is the edited code.

//the listnode and LList classes code is below
#include <iostream>
using namespace std;

//#undef NULL
//const int NULL = O;
typedef int element;
const element SENTINEL = -1;
element read_element();
class listnode {
   public:
   element data;
   listnode * next;
} ;

class LList {
   private:
   listnode * head;
   listnode * tail;
   public:
       LList();
        ~LList();
void Print();
void InsertHead(element thing);
void InsertTail(element thing);
element DeleteHead();
void ReadForward();
void ReadBackward();
void Clean();
void Steal(LList & Victim);
void Duplicate(LList & Source);
void Reverse();

} ;
//main function code below
int main() {
LList L;
cout <<"object created and constructed, calling Print" << endl;
L.Print();
cout <<"object printed, calling ReadForward" << endl;
L.ReadForward();
cout <<"object read forward, calling Print" << endl;
L.Print();
cout <<"object printed, calling ReadBackward " << endl;
L.ReadBackward();
cout <<"object read backward, calling Print" << endl;
L.Print();
cout <<"object printed, calling Clean " << endl;
L.Clean();
cout <<"object cleaned, calling Print" << endl;
L.Print();
cout <<"object printed" << endl;
}

//the constructor code below
LList:: LList () {
// PRE: none
// POST: the N. 0. LList is valid and empty
   this->head= NULL;
}

//code for the deconstructor
LList:: ~LList (){
// PRE: the N. 0. LList is valid
// POST: the N. 0. LList is valid and empty, and its listnodes have been deleted
Clean();
}

//the print method code
void LList::Print(){
// PRE: the N. 0. LList is valid
// POST: the N. 0. LList is unchanged, and its elements have been displayed
   listnode * temp;
   temp = head;
   while (temp != NULL){
   cout << temp -> data << endl;
   temp = temp -> next;
   }
}

//ReadForward code
void LList::ReadForward(){
// PRE: the N. o. LList is
// POST: the N. 0. LList is
// have been deleted,
// containing elements
element userval;
Clean();
/*valid
valid,
and it
given
all of its previous listnodes
now consists of new listnodes
by the user in forward order*/
cout << "Enter elements, " << SENTINEL << " to stop: ";
userval = read_element();
while (userval != SENTINEL){
InsertTail(userval);
userval=read_element();
}
}

//ReadBackward code
void LList::ReadBackward(){
/*II PRE: the N. 0. LList is valid
II POST: the N. 0. LList is valid, all of its previous listnodes
II have been deleted, and it now consists of new listnodes
II containing elements given by the user in backward order*/
element userval;
Clean();
cout << "Enter elements, " << SENTINEL << " to stop: ";
userval = read_element();
while (userval != SENTINEL){
InsertHead(userval);
userval = read_element();
}
}

//clean method code
void LList::Clean() {
// PRE: the N. 0. LList is valid
// POST: the N. 0. LList is valid and empty, and all of its
// listnodes have been deleted
while (head!= NULL)
DeleteHead();
}

//InsertHead code
void LList::InsertHead(element thing){
// PRE: the N. 0. LList is valid
// POST: the N. 0. LList is unchanged, except that a new
// listnode containing element thing has been inserted
// at the head end of the list
listnode * temp;
temp = new listnode;
temp -> data = thing;
temp -> next = head;
if (head== NULL)
tail = temp;
else
head=temp;
}


//InsertTail code
void LList::InsertTail(element thing) {
// PRE: the N. 0. LList is valid
// POST: the N. 0. LList is unchanged, except that a new
// listnode containing element thing has been inserted
// at the tail end of the list
listnode * temp;
temp = new listnode;
temp -> data = thing;
temp -> next = NULL;
if (head == NULL)
head = temp;
else
tail -> next=temp;
tail = temp;
}


//DeleteHead code
element LList::DeleteHead(){
// PRE: the N. O. LList is valid and not empty
// POST: the N. 0. LLit is unchanged, except that the listnode
// at the head end of the list has been deleted, and its
// data element has been returned
listnode * temp;
element thing;
temp = head;
head = head -> next;
thing = temp -> data;
delete temp;
return thing;
}