I got this question in the exam and i failed to solve it.

At my exam my first task was:

Write a header for the following main() so it can count the edges of a graph.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <iostream>
  #include <string>
  #include "wgraph.h"

  int main()
  {
  int yourMark = 1;

  WGraph<char, double, true> dirgraph;
  WGraph<std::string, int, false> undirgraph;

  dirgraph.add('A');
  dirgraph.add('B');
  dirgraph.add('C');

  dirgraph.add('A', 'B', 4.54);
  dirgraph.add('C','A', 6.32);

  undirgraph.add("AA", "BB", 3);

  const WGraph<std::string, int, false> c = undirgraph;
  yourMark += (c.is_directed() + dirgraph.is_directed());

  std::cout << "Your mark is " << yourMark << std::endl;



1. I guess I should use template<class T1, class T2 bool directed> class WGraph; which has a vector, but I dont know how to define it.

2. How should this vector store edges since it only contains one vertex?

3. Lastly i faild to understand the function of the bool parameter.



Thank you very much for any advice and help.



Last edited on
Why does it look like that you fail on the same question every year?
http://www.cplusplus.com/forum/general/218704/

A graph has vertices and edges. That is not "a vector"; there must be the vertices and the edges somehow.

Directed and undirected graphs have different properties.


Which is more of a problem for you: graphs or C++?
Understanding the problem that the program is made to solve or knowing how to implement a solution with particular language?
Topic archived. No new replies allowed.