Devam Ediyor

474809 Graph counter for C++ project

Write a new member function "degree" for the Wtgraph C++ class given. The "degree" function should determine and output how many even degree vertices and how many odd degree vertices a weighted, undirected graph has. The .cpp source code has a marker where you are to insert your code.

An idea is if you think of the edge matrix above as a weighted adjacency matrix where

M(i,j) = the number of edges joining v(i) & v(j), with the exception that for M(i,i) count each loop twice.

this will guarantee that the sum of row i is the degree of v(i).

Some general notes:

You will only add code to the

void WtGraph:: degree()

portion of the .cpp file. That will be the only portion of the program where you will do modifications.

For each row you want to:

(i) add up all its entries.

e.g., row 0 in up above is

0 10 0 5 0 0 1 0 0

Add them: 0 +10+ 0+ 5 + 0 + 0 + 1 + 0 + 0 = 16

(Thus, vertex 0 has degree 16)

(ii) determine if that sum is odd or even

e.g., for row 0 it is even, since 16 is even <----row 0 has even degree


16%2 =0 <-----------------------------------16/2 has remainder 0

Then determine how many rows have an even sum and how many have an odd sum. This will involve keeping track and counting the number of even sums and the number of odd sums.

The variable declared as

int size;

in the .cpp program is the number of vertices and thus it is the number of rows (and columns, too).

The variable declared as

int& edge ( int row, int col );

in the .cpp program is the actual matrix that you see in the iLab itself.

Thus, edge(0,6) would represent the 0,6 element of the matrix.

Note this command in the .cpp file

infiniteEdgeWt = 9999;

A use for infiniteEdgeWT is that blank, in this case 0, entries are preset to infiniteEdgeWT. Hence, in the matrix up above we have:

edge(0,2)= 9999

Thus, you will need a condition so that blank entries are not added to the sum. Here is one idea for what can be inserted inside the innermost nested for loop:

if (edge(i,j) < infiniteEdgeWt) // this is needed because blank entries are preset to 9999 and not 0 in this program, do not want to add 9999 to the sum

then add edge(i,j) to the sum.

Beceriler: Her şey Kabul, C Programlama, Web Sitesi Yönetimi

Daha fazlasını görün: write member function degree wtgraph class given, what is a variable in programming, what is a loop in programming, what is a graph, what is a class in programming, what graph, variable programming, variable in programming, use of graph, use graph, use a graph, the graph, programming with cpp, programming variable, programming loop, programming graph, programming degree, matrix programming, loop programming, int v, int size c, inside track, graph programming, graph program in c, graph in c programming

İşveren Hakkında:
( 0 değerlendirme )

Proje NO: #2220714