Design and implement a class VertexURL inheriting from the pure
virtual class Vertex:
/*******************************************************
** Name: vertex.h
** Author: Leo Liberti
** Source: GNU C++
** Purpose: www exploring topologizer -
** vertex abstract class (header)
** History: 060820 work started
*******************************************************/
#ifndef _WETVERTEXH
#define _WETVERTEXH
#include<iostream>
#include<string>
class Vertex {
public:
virtual ~Vertex() {
#ifdef DEBUG
std::cerr << "** destroying Vertex " << this << std::endl;
#endif
}
virtual int getID(void) const = 0;
virtual int getNumberOfAdjacentVertices(void) const = 0;
virtual int getAdjacentVertexID(int i) const = 0;
virtual std::string getText(void) = 0;
virtual void addAdjacentVertexID(int ID) = 0;
};
#endif
VertexURL is an encapsulation of a URL object which
conforms to the Vertex interface. This will be used later in the
Digraph class to store the vertices of the graph. This
separation between the Vertex interface and its particular
implementation (for example the VertexURL class) allows the Digraph class to be re-used with other types of vertices, and
therefore makes it very useful. An object conforming to the Vertex interface must know (and be able to set and get): its own
integer ID, the IDs of the vertices adjacent to it, a text label
associated to the vertex. Note that Vertex has a virtual destructor for
the following reason: should any agent attempt a direct deallocation
of a Vertex object, the destructor actually called will be the
destructor of the interface implementation (VertexURL in this
case, but might be different depending on run-time conditions) rather
than the interface destructor.
Test your implementation on the following code:
#include<iostream>
#include "vertexurl.h"
int main(int argc, char** argv) {
using namespace std;
if (argc < 2) {
cerr << "missing arg on cmd line" << endl;
return 1;
}
URL* urlPtr = new URL(argv[1]);
urlPtr->download();
VertexURL* vtxURLPtr = new VertexURL(0, urlPtr);
Vertex* vtxPtr = vtxURLPtr;
vtxPtr->addAdjacentVertexID(1);
vtxPtr->addAdjacentVertexID(2);
int starsize = vtxPtr->getNumberOfAdjacentVertices();
cout << "vertex " << vtxPtr->getID() << ": star";
for(int i = 0; i < starsize; i++) {
cout << " " << vtxPtr->getAdjacentVertexID(i);
}
cout << endl;
delete vtxPtr;
return 0;
}
Run the program