#include #include #include using namespace std; #include "Animal.h" #include "QuestionNode.h" #define DEFAULT_LOAD "animalData" #define DEFAULT_SAVE "cleanData" // For use after a merge, to remove duplicate anwsers. void clean(QuestionNode *&qN, string answersSoFar) { // Complete the code for the bonus } int main(int argc, char *argv[]) { string loadFileName= DEFAULT_LOAD, saveFileName= DEFAULT_SAVE; // Default file names. if (argc >= 2 && string(argv[1]) == "-help") { cout << "clean [" << loadFileName << " [" << saveFileName << "]]" << endl; exit(0); } // Reminder of syntax. if (argc > 3) { cout << "Try clean -help." << endl; exit(1); } if (argc >= 2) loadFileName= argv[1]; // First parameter is load file name, if present. if (argc >= 3) saveFileName= argv[2]; // Second parameter is save file name, if present. QuestionNode *qNS[3]= {NULL, NULL, NULL}; ifstream loadIn(loadFileName.c_str()); if (loadIn) { cout << "Loading tree from textfile '"+loadFileName+ "'" << flush; for (unsigned i= 0; i<3; i++) qNS[i]= QuestionNode::Load(loadIn); for (unsigned i= 0; i<3; i++) { system("sleep 1"); cout << "." << flush; } // 1438: For dramatic effect. cout << " done." << endl; } else { cout << "No file '"+loadFileName+"' found: starting from scratch." << endl; } for (unsigned i= 0; i<2; i++) clean(qNS[i], ""); // Clean all three branches if (0 == getAnswer("Save this run to '"+saveFileName+"'?", "yes,no")) { ofstream saveOut(saveFileName.c_str()); if (saveOut) { cout << "Saving tree to textfile '"+saveFileName+"'" << flush; for (unsigned i= 0; i<3; i++) QuestionNode::Save(saveOut, qNS[i], 0); dots(3); // 1438. cout << " done." << endl; } else { cout << "Could not save to '"+saveFileName+"'." << endl; } } else cout << "Not saved." << endl; }