-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatebfstest.cpp
58 lines (49 loc) · 1.47 KB
/
createbfstest.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
/**
** createbfstest.cpp
** Comp15 Project 2: Six Degrees of Collaboration
** Written by: Lucas Maley (lmaley01)
** April 28th, 2021
**
** Program to create extensive commandFile to test bfs and dfs
**/
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <vector>
using namespace std;
int main() {
//declares, opens, and checks data file for failure
ifstream dataFile;
dataFile.open("artists.txt");
if (dataFile.fail()) {
cerr << "artists.txt cannot be opened.\n";
exit(EXIT_FAILURE);
}
//declares and opens output file
ofstream outputFile;
outputFile.open("bfstestinput.txt");
string temp;
vector<string> artists;
//iterates through data file, storing artists in an array
getline(dataFile, temp);
artists.push_back(temp);
while (!dataFile.eof()) {
while (temp != "*" and temp != "") {
getline(dataFile, temp);
}
getline(dataFile, temp);
artists.push_back(temp);
}
artists.pop_back(); //accounts for reading final "*"
//outputs every possible combination to output file
for (unsigned long i = 0; i < artists.size(); i++) {
for (unsigned long j = 0; j < artists.size(); j++) {
outputFile << "bfs\n";
outputFile << artists[i] << "\n";
outputFile << artists[j] << "\n";
}
}
//closes data file and output file
outputFile.close();
dataFile.close();
}