-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputGraph.cpp
More file actions
102 lines (102 loc) · 2.53 KB
/
Copy pathInputGraph.cpp
File metadata and controls
102 lines (102 loc) · 2.53 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include<bits/stdc++.h>
using namespace std;
int main()
{
string a,b;
int c;
cout<<"Create a graph:-\n";
cout<<"Enter 1 for Un-Directed Un-Weighted Graph\n";
cout<<"Enter 2 for Un-Directed Weighted Graph\n";
cout<<"Enter 3 for Directed Un-Weighted Graph\n";
cout<<"Enter 4 for Directed Weighted Graph\n";
cin>>c;
cout<<"Enter the adjacent nodes(and weights) about which you want the edges. Press -1 to stop entering:-\n";
string dotpath=/*Enter the full address of the dot file*/"\\Dot Files\\InputGraph.dot";
ofstream dotfile(dotpath);
streambuf* original_cout=cout.rdbuf();
cout.rdbuf(dotfile.rdbuf());
if(c==1)
{
cout<<"graph h\n{\n";
while(1)
{
cin>>a;
if(a=="-1")
break;
cin>>b;
if(b=="-1")
break;
cout<<"\t"<<a<<" -- "<<b<<";\n";
}
cout<<"}\n";
}
else if(c==2)
{
cout<<"graph h\n{\n";
while(1)
{
cin>>a;
if(a=="-1")
break;
cin>>b;
if(b=="-1")
break;
cin>>c;
if(c==-1)
break;
cout<<"\t"<<a<<" -- "<<b<<"[label=\""<<c<<"\"];\n";
}
cout<<"}\n";
}
else if(c==3)
{
cout<<"digraph h\n{\n";
while(1)
{
cin>>a;
if(a=="-1")
break;
cin>>b;
if(b=="-1")
break;
cout<<"\t"<<a<<" -> "<<b<<";\n";
}
cout<<"}\n";
}
else if(c==4)
{
cout<<"digraph h\n{\n";
while(1)
{
cin>>a;
if(a=="-1")
break;
cin>>b;
if(b=="-1")
break;
cin>>c;
if(c==-1)
break;
cout<<"\t"<<a<<" -> "<<b<<"[label=\""<<c<<"\"];\n";
}
cout<<"}\n";
}
else
return 0;
cout.rdbuf(original_cout);
dotfile.close();
cout<<"Dot Generation Successful..\n";
cout<<"Generating Image\\\\\n";
string pngpath=/*Enter the full address of the image file*/"\\Images\\InputGraphImage.png";
string command="dot -Tpng \""+dotpath+"\" -o \""+pngpath+"\"";
int result=system(command.c_str());
if(result==0)
{
cout<<"Image Generation Successful..\n";
string openCmd="start \"\" \""+pngpath+"\"";
system(openCmd.c_str());
}
else
cout<<"Error!!";
return 0;
}