Question
please help me fix this code please use c++ please show your output PLEASE HELP sample output main.cpp #include #include #include DB.h using namespace std;
please help me fix this code
please use c++
please show your output
PLEASE HELP
sample output
main.cpp
#include
#include
#include "DB.h"
using namespace std;
int main()
{
srand(time(0));
DB* db =new DB;
for (int i=0; i
int value =rand() % 90 +10;
db->push(value);
}
cout
db->display(cout);
for(int i=0; i
db->pop();
}
cout
db->display(cout);
delete db;
return 0;
}
Node.cpp
#include
#include "Node.h"
using namespace std;
Node::Node(int da, Node* nex)
{
data = da;
next = nex;
}
Node::~Node()
{
delete this;
}
Node.h
#include
struct Node
{
int data; //current student
Node* next;
Node(); //constructor -> initialize the data members
Node(int, Node* = nullptr); //constructor with arg
~Node(); //destructor
};
DB.h
#ifndef DB_H
#define DB_H
#include
#include "Node.h"
using namespace std; //for ostream
class DB{
private:
Node* front;
int size;
public:
DB();
~DB();
void push(int);
void pop();
void display(ostream&);
};
#endif
DB.cpp
#include
#include "DB.h"
using namespace std;
void DB::push(int item)
{
Node* temp = new Node();
if (!temp)
{
cout
exit(1);
}
else
{
temp->data = item;
temp->next = front;
front = temp;
}
}
void DB::pop()
{
Node* temp;
if (front == NULL)
{
cout
}
else
{
temp = front;
front = front -> next;
temp->next = NULL;
free(temp);
}
}
DB::~DB()
{
delete this;
}
GDB.CPP C Node.h C DB.h Node* temp main.cpp Node.cpp E DB.cpp >... 1 #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started