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

Hey there this is my first posting in this forum I have been having a horrible t

ID: 3649420 • Letter: H

Question

Hey there this is my first posting in this forum

I have been having a horrible time doing this c++ assignment well most of the part is done

I have four files : node.h, list.h, list.cpp, and main.cpp

my professor give us already the main.cpp and the function which are in the list.cpp

void insert(int num);
bool find(int query);
bool remove(int target);
void print();


all the program is fine the problem is declaring the find and remove function to a Boolean function which I do not know

Could somebody help me with my assignment? and also with another extra problem which it is at the end


so far here is my code with the four files:


node.h

#include <iostream>

using namespace std;

struct Node
{
Node()
{
next = NULL;
}

~Node()
{
if(next != NULL)
{
delete next;
}

}

int data;
Node *next;

};



//list.h

#include "node.h"

class List
{
public:
List();
~List();
void insert(int);
Node * find(int);
void remove(int);
void print();

private:
Node *head;
};


list.cpp

#include "list.h"

List::List()
{
head = NULL;
}

List::~List()
{
if (head != NULL)
delete head;
}

void List::insert(int num)
{
//initial case
if (head == NULL)
{
head = new Node;
head->data = num;
return;
}

//general case
Node* i;
for (i = head; i->next != NULL; i=i->next);
i->next = new Node;
i->next->data = num;
}

bool List::find(int query)
{
Node* result;
for (result = head; result != NULL; result = result->next)
{
//if query is found
if (result->data = query)
return result;
}
//not found
return NULL;
}

void List::remove(int target)
{
//initial case
if (head == NULL)
return;

//head of the list case
if (head->data == target)
{
Node* victim = head;
head = victim->next;
victim->next = NULL;
delete victim;
return;
}

//general case
for (Node* prev=head; prev->next != NULL; prev = prev->next)
{
//previous guy finds the target
if (prev->next->data == target)
{
Node* victim = prev->next; //locate victim
prev->next = victim->next; //reroute list
victim->next = NULL; //isolate victim
delete victim; //MURDER victim!!!
return; // ... profit!!
}
}
}

void List::print()
{
for (Node* ptr=head; ptr != NULL; ptr = ptr->next)
{
cout << ptr->data << endl;
}
}


the list.cpp need boolean functions




and finally the main.cpp


#include <iostream>
#include "list.h"
using namespace std;
int main()
{
//assuming you are implementing a class called 'list'
List llist;
char option;
int value;
cin >> option;
while (option != 'q')
{
switch(option)
{
case 'i':
cin >> value;
llist.insert(value);
break;
case 'f':
cin >> value;
if (!llist.find(value))
{
cout << "Value not found" << endl;
}
else
{
cout << "Value found" << endl;
}
break;
case 'r':
cin >> value;
if (!llist.remove(value))
{
cout << "Error: Value not in list" << endl;
}
break;
case 'p':
llist.print();
break;
case 'q':
cout << "Exitiing" << endl;
break;
default:
cout << "Error: Command not recognized" << endl;
}
cin >> option;
}
return 0;
}




Here is a brief description of my assignment


Program Description
You will be given startup code (main.cpp) to implement a program that takes in user input to do
one of four things:

Explanation / Answer

#include #include struct node { int data; node * next; }; class LinkedList { public: LinkedList(); void add(int A); bool empty(); // return true if the list is empty, otherwise return false void InsertInOrder(ElementType x);//insert a value x in numerical order in the list void Delete(int x); //if value x is in the list, remove x void Display();// Display the data values in the list private: node * first;//pointer to the first node in the list }; #include #include using namespace std; LinkedList::LinkedList() { first=NULL; } void LinkedList::add(int A) { if (first==NULL) { first=new node; first->data=A; first->next=NULL; } else { node *curr=first; node *prev=NULL; while (curr!=NULL) { prev=curr; curr=curr->next; } curr=new node; curr->data=A; curr->next=NULL; prev->next=curr; } } bool LinkedList::empty() { if (first==NULL) return true; else return false; } void LinkedList::Delete(int A) { node *curr=first; node *prev=NULL; bool flag=true; if (first->data==A) { first=first->next; delete first; flag=false; } else { while (flag && curr!=NULL) { if (curr->data==A) { prev->next=curr->next; delete curr; flag=false; } prev=curr; curr=curr->next; } if (flag==true) cout