-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo.cpp
62 lines (53 loc) · 1.86 KB
/
Demo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Demo program for Exercise 2.
* Author: Benjamin Saldman.
*/
#include "Graph.hpp"
#include "Algorithms.hpp"
using ariel::Algorithms;
#include <iostream>
#include <stdexcept>
#include <vector>
using namespace std;
int main()
{
ariel::Graph g1;
// 3x3 matrix that represents a connected graph.
vector<vector<int>> graph = {
{0, 1, 0},
{1, 0, 1},
{0, 1, 0}};
g1.loadGraph(graph); // Load the graph to the object.
cout<<g1; // Should print the matrix of the graph: [0, 1, 0], [1, 0, 1], [0, 1, 0]
// 3x3 matrix that represents a weighted connected graph.
vector<vector<int>> weightedGraph = {
{0, 1, 1},
{1, 0, 2},
{1, 2, 0}};
ariel::Graph g2;
g2.loadGraph(weightedGraph); // Load the graph to the object.
ariel::Graph g3 = g1 + g2; // Add the two graphs together.
cout<<g3; // Should print the matrix of the graph: [0, 2, 1], [2, 0, 3], [1, 3, 0]
g1 *= -2; // Multiply the graph by -2.
cout<<g1; // Should print the matrix of the graph: [0, -2, 0], [-2, 0, -2], [0, -2, 0]
g1 /= -2;
ariel::Graph g4 = g1 * g2; // Multiply the two graphs together.
cout<<g4; // Should print the multiplication of the matrices of g1 and g2: [1, 0, 2], [1, 3, 1], [1, 0, 2]
// 5x5 matrix that represents a connected graph.
vector<vector<int>> graph2 = {
{0, 1, 0, 0, 1},
{1, 0, 1, 0, 0},
{0, 1, 0, 1, 0},
{0, 0, 1, 0, 1},
{1, 0, 0, 1, 0}};
ariel::Graph g5;
g5.loadGraph(graph2); // Load the graph to the object.
try
{
ariel::Graph g6 = g5 * g1; // Multiply the two graphs together.
}
catch (const std::invalid_argument &e)
{
cout << e.what() << endl; // Should print "The number of columns in the first matrix must be equal to the number of rows in the second matrix."
}
}