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

#include<iostream> #include<cstdlib> #include<vector> using namespace std; class

ID: 3840564 • Letter: #

Question

#include<iostream>
#include<cstdlib>
#include<vector>
using namespace std;

class Student{
char name[45];
int priority;
};
class BinaryHeap
{
private:
vector<Student>heap;
int left(int parent);
int right(int parent);
void heapifup(int index);
void heapifdown(int index);
public:
BinaryHeap()
{}
~BinaryHeap(){}
void Insert(Student element);
void DeleteMin();
int ExtractMin();
void DisplayHeap();
int size();
int Size();
};
int BinaryHeap::Size()
{
return heap.size();
}

void BinaryHeap::insert(Student element)
{
heap.push_back(element);
heapifup(heap.size()-1);
  
}


void BinaryHeap::DeleteMin()
{
if(heap.size()==0)
{
cout<<"Heap is Empty"<<endl;
return;
}
void BinaryHeap::DeleteMin ()
{
if(heap.size()==0)
{
cout<<"Heap is Empty"<<endl;
return;
}
heap[0]=heap.at(heap.size()-1);
heap.pop_back();
heapifydown(0);
cout<<"Student of the top has been Deleted"<<endl;
}

int BinaryHeap::ExtractMin()
{
if(heap.size()==0)
{
return-1;
}
else
return heap.font();
}

void BinaryHeap::print()
{
vector<Student>::iterator pos=heap.begin();
cout<<"Heap —-> ";
while(pos!=heap.end())
{
cout<<"Name of student"<<*pos->name<<"";
cout<<"Priority of student"<<*pos->priority<<"";
pos++;
}
cout<<endl;
}


void BinaryHeap::Peek()
{
vector<Student>::iterator pos = heap.begin();
cout<<"Name of student"<<*pos->name<<" ";
cout<<"Priority of student"<<*pos->priority<<" ";
}

int BinaryHeap::left(int parent)
{
int l=2*parent;
if(l<heap.size())
return l;
else
return-1;
}

int BinaryHeap::right(int parent)
{
int r = 2* parent+1;
if ( r< heap.size())
return r;
else
return-1;
}
int BinaryHeap::parent(int child)
{
int p = (child -1)/2
if (child == 0)
return-1;
else
return p;
}

void BinaryHeap::heapifyup(int n)
{
if (in >= 0 && parent(in) >= 0 && heap[parent(in)] > heap[in])
{
int temp = heap[in];
heap[in] = heap[parent(in)];
heap[parent(in)] = temp;
heapifyup(parent(in));
}
}
void BinaryHeap::heapifdown(int n)
{
int child = left (in);
int child = right (in);
if (child >= 0 && child >= 0 && heap[child] > heap[childl])
{
child = childl;
}
if (child > 0 && heap [in] > heap [child])
int temp = heap[in];
heap[in] = heap[child];
heap[child] = temp;
heapifydown(child);

}
}

int main()
{
BinaryHeap h;
student s;
while (1)
{
cout<<"— - - - - - - -"<<endl;
cout<<"Operations on Heap"<<endl;
cout<<"- - - - - — - - -"<<endl;
cout<<"1.Insert Student Data"<<endl;
cout<<"2.Delete Student"<<endl;
cout<<"3.Viewing top of the element"<<endl;
cout<<"4.Print Heap"<<endl;
cout<<"5.Size of the heap Heap"<<endl;
cout<<6."Exit"<<endl;
int choice, element;
cout <<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1 ;
cout<<"Enter the name of student to be inserted: ";
cin>>element->name;
cout<<"Enter the priority of student to be inserted: ";
cin>> element->priority;
h.Insert(element);
break;
case 2;
h.Delete();
break;
case 3;
cout<<"Viewing top element: ";
cou<<""h.Peek();
break;
case 4:
cout<<"Print Student detail of Heap: ";
h.print();
break;
case 5:
cout<<"Size of the heap: ";
h.print();
break;
case 6:
exit(1);
default:
cout<< "Enter Correct Choice"<< endl;
}

I have few errors:

please fix errors of the program amd also include output of the program.

  

prog.cpp: 34:40 error: no void BinaryHeap::insert (Student) member function declared in class void BinaryHeap: insert (Student element prog.cpp: In member function void BinaryHeap: DeleteMin. prog.cpp:49:28: error: qualified-id in declaration before token void BinaryHeap DeleteMin.

Explanation / Answer

/*All errors are removed from program and tested. Please run and check the output*/

#include<iostream>
#include<cstdlib>
#include<vector>
#include <string.h>
#include <stdio.h>

using namespace std;


class Student{
char name[45];
int priority;
  
public:
char* getName()
{
return name;
}
  
int getPriority()
{
return priority;
}
  
void setStudentData(char* Name, int prio)
{
strcpy(name, Name);
priority = prio;
}
};

class BinaryHeap
{
private:
vector<Student>heap;

public:
BinaryHeap()
{}
~BinaryHeap(){}
void Insert(Student element);
void Delete();
  
int Size();
void peek();
void print();
};

int BinaryHeap::Size()
{
return heap.size();
}

void BinaryHeap::Insert(Student element)
{
heap.push_back(element);
}

void BinaryHeap::Delete ()
{
if(heap.size()==0)
{
cout<<"Heap is Empty"<<endl;
return;
}
  
heap.pop_back();
cout<<"Student of the top has been Deleted"<<endl;
}

void BinaryHeap::print()
{
vector<Student>::iterator pos=heap.begin();
cout<<"Heap —-> ";
while(pos!=heap.end())
{
Student s = *pos;
cout<<"Name of student:"<<s.getName() << " ";
cout<<"Priority of student:"<<s.getPriority() << " ";
pos++;
}
cout<<endl;
}

void BinaryHeap::peek()
{
vector<Student>::iterator pos = heap.begin();
Student s = *pos;
cout<<"Name of student"<<s.getName()<<" ";
cout<<"Priority of student"<<s.getPriority()<<" ";
}

int main()
{
Student s;
BinaryHeap h;
  
//while (1)
{
cout<<"— - - - - - - -"<<endl;
cout<<"Operations on Heap"<<endl;
cout<<"- - - - - — - - -"<<endl;
cout<<"1.Insert Student Data"<<endl;
cout<<"2.Delete Student"<<endl;
cout<<"3.Viewing top of the element"<<endl;
cout<<"4.Print Heap"<<endl;
cout<<"5.Size of the heap Heap"<<endl;
cout<<"6 Exit"<<endl;
int choice = 0;
cout <<"Enter your choice: ";
scanf("%d", &choice);

switch(choice)
{
case 1:
{
char name[45] = {0};
cout<<"Enter the name of student to be inserted: ";
cin >> name;
  
int prio = 0;
cout<<"Enter the priority of student to be inserted: ";
cin >> prio;
s.setStudentData(name, prio);
h.Insert(s);
break;
}
case 2:
{
h.Delete();
break;
}
case 3:
{
cout<<"Viewing top element: ";
h.peek();
break;
}
case 4:
{
cout<<"Print Student detail of Heap: ";
h.print();
break;
}
case 5:
{
cout<<"Size of the heap: ";
h.Size();
break;
}
case 6:
{
exit(1);
}
default:
{
cout<< "Enter Correct Choice"<< endl;
}
  
}
}
}