Advertisement
Guest User

Untitled

a guest
Dec 14th, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. #include <cstdlib>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. void menu();
  10. void english(); // translations functions
  11. void spanish();
  12.  
  13. int main()
  14. {
  15.  
  16. do{
  17.  
  18. menu();
  19.  
  20. }
  21.  
  22. while (1);
  23.  
  24. return 0;
  25.  
  26. }
  27.  
  28. void menu()///////////prompts the user for a menu to decide which translation.
  29. {
  30. const string space = " ";
  31. char resp;
  32.  
  33. cout << space << "Translate Spanish-English vice versa\n";
  34. cout << space << "a:english to spanish\n";
  35. cout << space << "b:Spanish to english\n";
  36. cin >> resp;
  37.  
  38.  
  39.  
  40.  
  41. switch (resp)
  42. {
  43.  
  44.  
  45. case 'a':
  46. english();
  47. break;
  48.  
  49. case 'b':
  50. spanish();
  51. break;
  52. }
  53. }
  54. ////---------------------------------------------------------------------------------------------------------
  55. void english()
  56. {
  57. ifstream fin;
  58. vector <string> eng;
  59. vector <string> span;
  60. string words;
  61. bool FOUND = 0;
  62.  
  63.  
  64.  
  65.  
  66. fin.open("dictionary.txt");
  67. if (fin.fail())
  68. {
  69. cout << "Failed";
  70. exit(1);
  71. }
  72.  
  73.  
  74. do{
  75. getline(fin, words, ',');
  76. eng.push_back(words);
  77. getline(fin, words);
  78. span.push_back(words);
  79. }while (!fin.eof());
  80. /////////////////////////////////////////////
  81.  
  82. cout << "English-SPanish-Now type in a Word you want to translate\n";
  83. cin >> words;
  84.  
  85. for (int i=0; i< words.length(); i++)
  86. words[i]= toupper(words[i]);
  87.  
  88. cout << "you entered " << words << endl;
  89.  
  90. for (unsigned int i=0; i<eng.size(); i++)
  91. {
  92. if (eng[i]==words)
  93. {
  94. cout << "Spanish translation is \n" << span[i] << endl;
  95. FOUND = 1;
  96. }
  97. if (FOUND)
  98. break;
  99. }
  100.  
  101.  
  102.  
  103. ///////////////////////////////////////////
  104.  
  105. fin.close();
  106.  
  107. }
  108. ///////
  109.  
  110. void spanish()
  111. {
  112. ifstream fin;
  113. vector <string> eng;
  114. vector <string> span;
  115. string words,temp;
  116. bool FOUND = 0;
  117.  
  118.  
  119.  
  120.  
  121. fin.open("dictionary.txt");
  122. if (fin.fail())
  123. {
  124. cout << "Failed";
  125. exit(1);
  126. }
  127.  
  128.  
  129. do{
  130.  
  131. getline(fin, words);
  132. eng.push_back(words);
  133. getline(fin, words, ',');
  134. span.push_back(words);
  135.  
  136. }while (!fin.eof());
  137. /////////////////////////////////////////////
  138.  
  139. cout << " Spanish-English Now type in a Word you want to translate\n";
  140. cin >> words;
  141.  
  142. for (int i=0; i < words.length(); i++)
  143. words[i]= toupper(words[i]);
  144.  
  145. cout << "you entered " << words << endl;
  146.  
  147.  
  148. for (unsigned int i=0; i<span.size(); i++)
  149. {
  150. if (span[i]==words)
  151. {
  152. cout << "Spanish translation is \n" << eng[i] << endl;
  153. FOUND = 1;
  154. }
  155. if (FOUND)
  156. break;
  157. }
  158.  
  159. ///////////////////////////////////////////
  160.  
  161. fin.close();
  162.  
  163.  
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement