1.Graph is a very important data structure in computer science. It is used in many useful problems (e.g., Google maps). You can find the details of graphs here. In this problem, you will write C++ code to implement a simple graph using the following classes:
i.A class called Vertex that has the following: i. A private member called "value" of type char
ii. A default public constructor which sets value to NULL.
iii. Another public constructor that takes a character c as input and sets value to c.
iv. A public function "void printVertex( )" that just prints the character (value).

II.A class called Edge that has the following:
i. A private variable called "weight" of type int.
ii. Two private variables called "start" and "end", each of type Vertex.
iii. A default public constructor that sets "start" and "end" to a vertex created using its default constructor.
iv. Another public constructor that takes two vertices "s" "e" and another int "w" as input that sets "start" to "s", "end" to "e" and weight to "w".
v. A public function called "void printEdge( )" that calls start's printVertex( ), end's printVertex( ) functions and also prints the edge's weight.

III.Another class called "Graph" with the following data and functions:
i. A private variable called "count" of type int that keeps track of the number of edges.
ii. Another private variable called "allEdges" that is an array of edges (Edge[MAXNUM], where MAXNUM is some predefined number).
iii. A default public constructor that sets count to 0.
iv. A public function called "void addEdge(Edge e)" that adds an edge "e" to the graph. It should simply add e to the array of edges of the graph (allEdges) and increment count.
v. A public function called "printGraph( )" that prints all the edges by calling "printEdge( )" of each edge of the graph.

IV. In the main function do the following:
i. Create at least 6 vertices.
ii. Using the vertices, create at least 5 edges.
iii. Define a graph using its default constructor.
iv. And add each of the edges to the graph.
v. Call the printGraph( ) function of the graph.

2. Define an array of integers of at least 10 elements. initialize it with any meaningful values. Without sorting the array in any way, find the third largest element of the array.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include "Vertex.h"
#include <iostream>

using namespace std;


void Vertex::printVertex()
cout << value;
$30.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats