-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
103 lines (89 loc) · 3.03 KB
/
main.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
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
103
// file to run algo for quine mccluskey method
#include <iostream>
#include <fstream>
#include <string>
#include "includes/quine-mccluskey-petrick.h"
using namespace std;
int main(int argc, char **argv)
{
if (argc > 1) // input file present
{
string line, tmp, res, input = "", minterms = "", dontcare = ""; // line read from input file
uint counter;
// string inputfile = argv[1]; //
ifstream file(argv[1]);
if (file.is_open())
{
while (getline(file, line))
{
counter = 0;
tmp = "";
/* read input file */
for (uint i = 0; i <= line.length(); ++i)
{
if (line[i] != ',')
{
tmp += line[i];
}
else
{
switch (counter)
{
case 0:
input = tmp;
break;
case 1:
minterms = tmp;
break;
case 2:
dontcare = tmp;
break;
default:
break;
}
tmp = "";
++counter;
}
}
if (DEBUG)
{
cout << "Testing" << endl;
// cout << "alphabet: " << alphabet << endl;
cout << "Inputs: " << input << endl;
cout << "Minterms: " << minterms << endl;
cout << "Don't Care: " << dontcare << endl;
}
try {
res = quine_mccluskey(input, minterms, dontcare);
cout << "Solution: " << res << endl;
}
catch(...)
{
cout << "Error: Invalid input format" << endl;
cout << "format should be: inputs,minterms,dontcare," << endl;
cout << "e.g.: A-B-C-D,1-3-4-5,0-7,\n" << endl;
}
}
/* finish reading input file */
file.close();
}
else
cout << "Error opening file!" << endl;
}
else // no input file, exec default
{
string input = "A-B-C-D", // inputs to expression, separated by comma
minterms = "0-2-3-4-5-6-7-8-9-10-11-12-13",
dontcare = "";
if (DEBUG)
{
cout << "Testing" << endl;
cout << "Inputs: " << input << endl;
cout << "Minterms: " << minterms << endl;
cout << "Don't Care: " << dontcare << endl;
}
string res = quine_mccluskey(input, minterms, dontcare);
cout << "Solution: " << res << endl;
}
return EXIT_SUCCESS;
}