So I have errors that I need help fixing for c++11. This deals with undirected g
ID: 3883147 • Letter: S
Question
So I have errors that I need help fixing for c++11. This deals with undirected graph in the format of adjacency matrix.
prompt:
Write a C++ 11 function named is_connected() to determine whether an undirected unweighted graph is connected when the graph is stored in the adjacency matrix format.
Write a main program that hard-codes the entries of the adjacency matrix and then passes the matrix to the is_connected function. Every graph has vertices labeled with consecutive unsigned integers starting at 0.
So I have those done already, and I need help with these compiler issues that make no sense. One of them is I already included the packages for them
Errors:
In file included from lin_0912.cpp:7:0:
lin_0912.h: In function ‘bool is_connected(Matrix&)’:
lin_0912.h:129:6: error: ‘vector’ was not declared in this scope
vector< bool >reached(graph.size(),false);
^
lin_0912.h:129:6: note: suggested alternative:
In file included from /usr/include/c++/4.8/vector:64:0,
from lin_0912.cpp:4:
/usr/include/c++/4.8/bits/stl_vector.h:210:11: note: ‘std::vector’
class vector : protected _Vector_base<_Tp, _Alloc>
^
In file included from lin_0912.cpp:7:0:
lin_0912.h:129:14: error: expected primary-expression before ‘bool’
vector< bool >reached(graph.size(),false);
^
lin_0912.h:129:14: error: expected ‘;’ before ‘bool’
lin_0912.h:130:7: error: ‘queue’ was not declared in this scope
queue< uint8_t > to_be_explored;
^
lin_0912.h:130:7: note: suggested alternative:
In file included from /usr/include/c++/4.8/queue:64:0,
from lin_0912.cpp:5:
/usr/include/c++/4.8/bits/stl_queue.h:93:11: note: ‘std::queue’
class queue
^
In file included from lin_0912.cpp:7:0:
lin_0912.h:130:22: error: expected primary-expression before ‘>’ token
queue< uint8_t > to_be_explored;
^
lin_0912.h:130:24: error: ‘to_be_explored’ was not declared in this scope
queue< uint8_t > to_be_explored;
^
lin_0912.h:137:9: error: ‘reached’ was not declared in this scope
reached.at(current_node)=true;
^
lin_0912.h:146:19: error: ‘reached’ was not declared in this scope
return find(reached.begin(), reached.end(), false) == reached.end();
^
lin_0912.h:146:56: error: ‘find’ was not declared in this scope
return find(reached.begin(), reached.end(), false) == reached.end();
^
lin_0912.h:146:56: note: suggested alternative:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from lin_0912.h:9,
from lin_0912.cpp:7:
/usr/include/c++/4.8/bits/stl_algo.h:4432:5: note: ‘std::find’
find(_InputIterator __first, _InputIterator __last,
^
lin_0912.cpp: In function ‘int main()’:
lin_0912.cpp:23:28: error: invalid initialization of reference of type ‘Matrix&’ from expression of type ‘Matrix’
cout< ^
In file included from lin_0912.cpp:7:0:
lin_0912.h:126:9: error: in passing argument 1 of ‘bool is_connected(Matrix&)’
bool is_connected(Matrix & graph)
^
lin_0912.h: In function ‘bool is_connected(Matrix&)’:
lin_0912.h:147:4: warning: control reaches end of non-void function [-Wreturn-type]
}
the matrix class:.h
.cpp:
Explanation / Answer
This snippet is about a generic matrix type. The nice part is that given two matrices with respective entry types, say, of short and float, the result matrix entry type after the multiplication will be float.
matrix.h:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.