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

Please i need help on this programming assingment....we are coding in C++ Below

ID: 3828225 • Letter: P

Question

Please i need help on this programming assingment....we are coding in C++

Below is a link to the assignment i had earlier posted......have also provided LList codes given to us by our professor(thought it might be useful).

https://www.chegg.com/homework-help/questions-and-answers/please-need-help-coding-c-using-district-unix-alos-llist-codes-could-send-would-helpfultha-q21032647

I also have a code for the program at the bottom, but the code doesn't do what its supposed to do.....i guess it needs more editing.

//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 method
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;
}


//Duplicate method
void LList::Duplicate(LList & Source)
// PRE: the N. 0. and Source LLists are valid
// POST: the Source LList is unchanged
// the N. 0. LList is valid, all of its previous listnodes
// have been deleted, and it now consists of listnodes
// containing the same elements and in the same order
// as on the Source LList
listnode * temp;
Clean();
temp = Source.head;
while (temp != NULL)
InsertTail(temp -> data);
temp = temp -> next;
}
}

//Global section and class declarations code

#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();
};


//Revserse method
void LList: :Reverse(){
// PRE: the N. 0. LList is valid
// POST: the N. 0. LList is unchanged, except its elements are
// in reverse order
listnode * temp;
LList Helper;
temp = head;
while (temp != NULL){
Helper.InsertHead(temp -> data);
temp = temp -> next;
}
Steal(Helper);
}


//Steal method
void LList: :Steal(LList & Victim) {
// PRE: the N. 0. and Victim LLists are valid
// POST: the Victim LList is valid and empty
// the N. 0. LList is valid, all of its previous listnodes
// have been deleted, and it now consists of the listnodes
// originally on the Victim LList
Clean();
head = Victim.head;
tail = Victim.tail;
Victim.head = NULL;
}

Here's a partially correct code for the program

#include <iostream>
using namespace std;

#undef NULL //undefines anything from a class that already has
//the same name


typedef int element;
const int NULL=0;
const char SENTINEL ='#' ;

class listnode{
public:
element data;
listnode* next;
listnode();   
~listnode();

}; // no private data

class LList{
private:
listnode* head;
listnode* tail;
  
public:
LList();
~LList();
void ReadBackwards();
void Clean();   
void Menu();
char Read_element();
void Vigesimalinput();
void AddVigesimal();
void MultiplyVigesimal();
void HelpMenu();
void Print();   
  
};

int main(){
//main function, everthing will be executed from top to bottom
LList A;
  
cout<<" ""Vigesimal Calculator, Version 1.0" <<endl;
cout<<"(c) 2017, Silas Ken"<<endl;
cout<<endl;

A.Menu();
  
}
  
LList::LList(){
//This is the constructor, LList will live!
//Pre:None
//Post: The N.O is valid
head=NULL;
}
  
LList::~LList(){
//This is the destructor, it will give LList a clean death
//Pre: The N.O. is valid
//Post: The N.O. is valid and empty and all borrowed system
// resources have been given back
Clean();
}

listnode::listnode(){
//This is the constructor, Listnode will live
//I hope to make listnode more intelligent so it starts with a
// zero value
//
// Pre: none
//Post: The N.O. is valid!
data=0;
}

listnode::~listnode(){
//This is the destructor, it will clean and kill the listnode
//Pre: The N.O. is valid
//Post: the N.O. is valid and empty and all borrowed system
// resources have been give back
delete next;
}

void LList::Clean(){
//This will basically "proprley" delete objects LList
//Pre: the N.O. LList is valid
//Post: The N.O. is now empty, and all of it's previous listnodes
// have been given to the system memory pool ("heap")
listnode* temp;
while(head != NULL){
temp=head;
head=head -> next;
delete temp;
}
}

void LList::ReadBackwards(){
//This will put the user input into a linked list backwards
//Pre: The N.O LList is valid
//Post: the N.O. LList is now valid, filled with data provided
// by the user in backwards order
  
char userval;
listnode* temp;
  
Clean();
cout<<"Enter elements, "<<SENTINEL<<" to stop";
userval=Read_element();
while(userval != SENTINEL){
temp= new listnode;
temp -> data=userval;
temp -> next = head;
if (head == NULL)
tail=temp;
else
;
head=temp;
userval=Read_element();
}   
}

char LList::Read_element(){
//Perfors my data type checking validation like a true player
char val;
cin >> val;
while(!cin.good()){
cout<<"Invalid response, should be a number 0-9 or a";
cout<<" letter A-J, try again: ";
cin.clear();
cin.ignore(80, ' ');
cin >>val;
}
return val;
}

void LList::Menu(){
//This displays the vigesimal number that is current. then ask
//for a user input.

char useranswer;
int answer;
  
answer=0;
  
  
cout<<"Current vigesmial number is: "<<endl;
       Print();
cout<<endl;
cout<<"Command (h for help) : ";
useranswer=Read_element();
answer=useranswer;
  
  
if ((answer == 101) || (answer == 69))
Vigesimalinput();
else if ((answer == 97) || (answer == 65 ))
AddVigesimal();
else if ((answer == 109) || (answer == 77 ))
MultiplyVigesimal();
else if ((answer == 104) || (answer == 72))
HelpMenu();
else if ((answer == 113) || (answer == 81))
Menu();
else
cout<<"Invalid menu option (h for help)"" "<<endl;
Menu();
}

void LList::Vigesimalinput(){
ReadBackwards();
  
}

void LList::AddVigesimal(){
}

void LList::MultiplyVigesimal(){
}
  
void LList::HelpMenu(){
//This will display the commands for the user! power to the user!
  
cout<<" "<<"Valid commands are:"<<endl;
cout<<" e enter enter the current vigesimal number"
<<"from the keyboard"<<endl;
cout<<" a add add a new vigesimal number to the"
<<"current vig. number"<<endl;
cout<<" m multiply multiply a new vigesimal number by"
<<"the current vig. number"<<endl;
cout<<" h help show the help menu"<<endl;
cout<<" q quit quit the program"" "<<endl;

Menu();
}

void LList::Print(){
//Pre; The N.O LList is valid
//Post: the N.O LList is unchaged and its elements have been
// displayed

listnode* temp;
temp=head;
  
while(temp != NULL){
cout<<temp -> data<< endl;
temp=temp -> next; //pointer increament
}   
}

Explanation / Answer

Ans: The program is error free and working perfectly.I explained with comments and you can remove them for the clear code.Thank you.

program:

#include <iostream>

using namespace std;

//undefines

#undef NULL

// int element

typedef int element;

const int NULL=0; // null = 0

const char SENTINEL ='#' ; // sentinel

// listnode

class listnode{

public:

element data;

listnode* next;

listnode();

~listnode();

};

// class LList

class LList{

// private

private:

listnode* head; // head

listnode* tail; // tail

//public , LList

public:

LList();

~LList();

void ReadBackwards();

void Clean();

void Menu();

char Read_element();

void Vigesimalinput();

void AddVigesimal();

void MultiplyVigesimal();

void HelpMenu();

void Print();

};

// main

int main(){

// LList A

LList A;

// cout veg-- calculator v1.0

cout<<" ""Vigesimal Calculator, Version 1.0" <<endl;

cout<<"c) 2017, Silas Ken"<<endl;

cout<<endl;

// menu

A.Menu();

}

// LList()

LList::LList(){

// cconstructor, LList will live!,,Pre:None,,Post: The N.O is valid

head=NULL;

}

// ~LList()

LList::~LList(){

//Destructor, gives LList clean_death,,Pre: The N.O. is valid

//Post: The N..O. is valid & empty & al borrowd_system

Clean();

}

// listnode

listnode::listnode(){

data=0;

}

// ~listnode()

listnode::~listnode(){

delete next; // deletes next

}

// clean()

void LList::Clean(){

listnode* temp; // listnode*temp

// while head not equal to null

while(head != NULL){   

temp=head; // temp = head

head=head -> next;

delete temp; // delete

}

}

// ReadBackwards()

void LList::ReadBackwards(){

char userval; // userval

listnode* temp; // listnode*temp

// clean

Clean();

// coutenter elements

cout<<"Enter elements, "<<SENTINEL<<" to stop";

// userval

userval=Read_element();

// while cond

while(userval != SENTINEL){

// ne listnode

temp= new listnode;

// userval = data

temp -> data=userval;

// next = head

temp -> next = head;

//head == null

if (head == NULL)

// tail = temp

tail=temp;

else

;

head=temp;

// reads element

userval=Read_element();

}

}

// read__element

char LList::Read_element(){

// val

char val;

// cin

cin >> val;

//while()

while(!cin.good()){

// invalid respons

cout<<"Invalid_response, it should be number 0-9 or a";

// A-J,, try again

cout<<" letter A-J, try again: ";

cin.clear(); // clear

// ignore

cin.ignore(80, ' ');

cin >>val;

}

// return

return val;

}

// Menu()

void LList::Menu(){

// user answer

char useranswer;

// int ans

int answer;

// =0

answer=0;

// current vegismial numb is

cout<<"The Current vigesmial number is: "<<endl;

// print

Print();

// cout

cout<<endl;

// help--h

cout<<"Command (h for help) : ";

// read element

useranswer=Read_element();

// answer

answer=useranswer;

// ans=='101' || ans=='69'

if ((answer == 101) || (answer == 69))

Vigesimalinput();

// ans=='97'||ans=='65'

else if ((answer == 97) || (answer == 65 ))

AddVigesimal();

// ans=='109'||ans=='77'

else if ((answer == 109) || (answer == 77 ))

MultiplyVigesimal();

//ans=='104'||ans=='72'

else if ((answer == 104) || (answer == 72))

HelpMenu();

// ans=='113'||ans=='81'

else if ((answer == 113) || (answer == 81))

Menu();

else

// invalid option and h for help

cout<<"Invalid menu option (h for help)"" "<<endl;

// menu()

Menu();

}

// vigesimalinput()

void LList::Vigesimalinput(){

// read backwards

ReadBackwards();

}

// addvigesimal

void LList::AddVigesimal(){

}

// multiplyVigesimal

void LList::MultiplyVigesimal(){

}

// HelpMenu

void LList::HelpMenu(){

// cout current vigesimal number q-quit, m-multiply, h-help,e-enter,a-add

cout<<" "<<"Valid commands are:"<<endl;

cout<<" e enter enter the current vigesimal_number"

<<"from the keyboard"<<endl;

cout<<" a add add new_vigesiimal numbr to the"

<<"current vig. number"<<endl;

cout<<" m multiply multiply a new_vigesimal numbr by"

<<"the current vig. number"<<endl;

cout<<" h help show the help menuu"<<endl;

cout<<" q quit quit the programm"" "<<endl;

Menu();

}

//Print()

void LList::Print(){

// listnode*temp

listnode* temp;

// temp=head

temp=head;

// while()

while(temp != NULL){

// cout

cout<<temp -> data<< endl;

// temp->next

temp=temp -> next; //pointer increament

}

}