PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/Lab10/Driver.cpp

https://github.com/amarshall/CS240
C++ | 59 lines | 45 code | 7 blank | 7 comment | 6 complexity | f9c489cc4f5b6fda036901e12e57d6fb MD5 | raw file
  1. /**
  2. * CS240 Lab 10
  3. * Driver.cpp
  4. * @author J. Andrew Marshall (jmarsha6)
  5. * @author Aaron Shipper (ashippe1)
  6. * @author Kenneth Louie (klouie1)
  7. */
  8. #include <stdlib.h>
  9. #include <string>
  10. #include <iostream>
  11. #include <fstream>
  12. #include <sstream>
  13. #include "BinarySearchTree.h"
  14. using namespace std;
  15. int main(int argc, char *argv[]) {
  16. if(argc <= 1) {
  17. cerr << "No input file specified." << endl;
  18. exit(1);
  19. }
  20. ifstream in;
  21. string inputFile = (string(argv[1]));
  22. in.open(inputFile.data());
  23. if(!in.is_open()) {
  24. cerr << "Error opening inputfile: " << inputFile << endl;
  25. exit(1);
  26. }
  27. BinarySearchTree* bst = new BinarySearchTree();
  28. while(!in.eof()) {
  29. string cur;
  30. getline(in, cur);
  31. istringstream iss(cur);
  32. do {
  33. string sub;
  34. iss >> sub;
  35. if((int)sub[0] != 0) {
  36. bst->insert(sub);
  37. }
  38. } while (iss);
  39. }
  40. bst->printFrequency();
  41. bst->uniqueWordCount();
  42. bst->totalCharCount();
  43. string input;
  44. do {
  45. cout << "Enter word to search for or type \"ExitSpring10\" to finish: ";
  46. cin >> input;
  47. bst->printWordFrequency(input);
  48. } while(input != "ExitSpring10");
  49. delete bst;
  50. in.close();
  51. return 0;
  52. }