I want the visual studio C programming code for the followin

I want the visual studio C++ programming code for the following task. Please code in simple C++ language so it can be understandable. Thanks in advance.

Q1. a)You must implement an adjacency matrix class.

The basic operations provided by this adjacency matrix G includes:

isAdjacent(G, x, y): tests whether there is an edge from the vertices x to y;

neighbors(G, x): lists all vertices y such that there is an edge from the vertices x to

y;

add_edge(G, x, y): adds the edge from the vertices x to y, if it is not there;

remove_edge(G, x, y): removes the edge from the vertices x to y, if it is there;

b) Implement the bucket algorithm using your implementation of the adjacency matrix. You

will read off the Graph from a text file holding vertex associations in every line of the graph

and populate or fill up your adjacency matrix before running the bucket algorithm on the

garph.

File contents can be like: (every line shows the the vertices with which edges are shared)

a has-edge g h d c e

b has-edge c f g e

c has-edge e f

d has-edge g c e

e has-edge a b c

f has-edge d e

g has-edge b c a

h has-edge d f e

First you will read this file and populate your adjacency matrix then run bucket algorithm

over it.

Solution

Q1) Program for creating Adjacent Matrix:

#include <iostream>
#include <cstdlib>
using namespace std;
#define MAX 30

class adjacencymatrix
{
    private:
         int n;
         int **adj;
         bool *visited;

    public:
        adjacencymatrix(int n)
        {
            this->n = n;
            visited = new bool [n];
            adj = new int* [n];
            for (int i = 0; i < n; i++)
            {
                adj[i] = new int [n];
                for(int j = 0; j < n; j++)
                {
                    adj[i][j] = 0;
                }
            }
        }

        void add_edge(int x, int y)
        {
            if( x > n || y > n || x < 0 || y < 0)
            {
                cout<<\"Invalid edge!\ \";
            }
            else
            {
                adj[x - 1][y - 1] = 1;
            }
        }

        void display()
        {
            int i,j;
            for(i = 0;i < n;i++)
            {
                for(j = 0; j < n; j++)
                    cout<<adj[i][j]<<\" \";
                cout<<endl;
            }
        }
};

int main()
{
    int ele, max_edges, x, y;
    cout<<\"Enter number of elements: \";
    cin>>ele;
    adjacencymatrix am(ele);
    max_edges = ele * (ele - 1);
    for (int i = 0; i < max_edges; i++)
    {
        cout<<\"Enter edge (-1 -1 to exit): \";
        cin>>x>>y;
        if((x == -1) && (y == -1))
            break;
        am.add_edge(x, y);
    }
    am.display();
    return 0;
}

I want the visual studio C++ programming code for the following task. Please code in simple C++ language so it can be understandable. Thanks in advance. Q1. a)Y
I want the visual studio C++ programming code for the following task. Please code in simple C++ language so it can be understandable. Thanks in advance. Q1. a)Y

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site