Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please I need Help Use c++ and show me your output. this is the output i need this is what i'm getting here is my

Please I need Help

Use c++ and show me your output.

this is the output i need

image text in transcribed

this is what i'm getting

image text in transcribed

here is my code

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);

return 0;

}

DB.cpp

#include

#include "DB.h"

using namespace std; DB::DB() { front=NULL; size=0; }

void DB::push(int item)

{

Node* temp = new Node(); temp->data=item; temp->next=NULL;

if(front==NULL) { front=temp; } else { temp->next = front; front = temp;

} size++; }

void DB::pop()

{

Node* temp;

if (front == NULL) { cout

temp = front;

front = front -> next; size--; free(temp);

}

}

DB::~DB()

{ delete this; } void DB::display(ostream &out) { Node *temp; if (front == NULL) { cout next; } out

DB.h

#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 &);

};

Node.cpp

#include

#include "Node.h"

using namespace std; Node::Node() { data=-1; next=NULL; } Node::Node(int da, Node* nex)

{ data = da; next = nex; }

Node::~Node()

{ delete this; }

Node.h

#include

struct Node

{

int data; //current data

Node* next;

Node(); //constructor -> initialize the data members

Node(int, Node* = NULL); //constructor with arg

~Node(); //destructor

};

$ ./a.exe DB) : 0x7b18cm DB:: push(14) Node(int, Node*) : @x7b18de DB:: push(29) Node(int, Node*) : ex7b18e DB : : push(67) Node(int, Node*) : @x7b18f@ DB:: push(32) Node(int, Node*) : @x7b1900 DB:: push(10) Node(int, Node*) : @x7b1910 -After pushing 5 integers--- 10 32 67 29 14 DB::pop (@x7b18c0) Node() : @x7b1910 DB::pop (@x7b18cm) -Node() : 0x761900 -----After popping 2 integers 67 29 14 -DB) : @x7b18ce -Node() : @x7b18fe -Node() : @x7b18e Node() : @x7b18de -After pushing 5 Integer- 39 73 38 82 60 --After popping 2 Integer----- 38 82 60

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions