Advertisement
Guest User

Untitled

a guest
May 6th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <fstream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. bool find(const vector<string>& v, string word, int start, int stop){
  9. if (start == stop){
  10. if (v[start] == word)
  11. return true;
  12. else
  13. return false;
  14. }
  15. else if (start > stop)
  16. return false;
  17. else{
  18. int middle = start + ((stop - start) / 2);
  19. if (v[middle] == word)
  20. return true;
  21. if (v[middle] > word)
  22. return find(v, word, start, middle - 1);
  23. if (v[middle] < word)
  24. return find(v, word, middle + 1, stop);
  25. }
  26. }
  27.  
  28. int main(){
  29. string fileName, currentWord, fileName2, testWord;
  30. ifstream input1, input2;
  31. vector<string> fileInput;
  32. ofstream errorFile;
  33.  
  34. cout << "What is the name of the dictionary file? ";
  35. cin >> fileName;
  36. cout << endl;
  37. input1.open(fileName.c_str());
  38.  
  39. if (input1.is_open()){
  40. while (input1 >> currentWord)
  41. fileInput.push_back(currentWord);
  42. }
  43. else
  44. cout << "This file does not exist." << endl;
  45.  
  46. sort(fileInput.begin(), fileInput.end());
  47.  
  48. cout << "What file would you like to spell check? ";
  49. cin >> fileName2;
  50. cout << endl;
  51. input2.open(fileName2.c_str());
  52.  
  53. errorFile.open("errors.txt");
  54.  
  55. while (input2 >> testWord){
  56. string::iterator new_end = remove_if(testWord.begin(), testWord.end(), ::ispunct);
  57. testWord.erase(new_end, testWord.end());
  58. transform(testWord.begin(), testWord.end(), testWord.begin(), tolower);
  59. if (find(fileInput, testWord, 0, fileInput.size() - 1) == false)
  60. errorFile << testWord << endl;
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement