Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <cstdlib>
- #include <algorithm>
- using namespace std;
- void menu();
- void english(); // translations functions
- void spanish();
- int main()
- {
- do{
- menu();
- }
- while (1);
- return 0;
- }
- void menu()///////////prompts the user for a menu to decide which translation.
- {
- const string space = " ";
- char resp;
- cout << space << "Translate Spanish-English vice versa\n";
- cout << space << "a:english to spanish\n";
- cout << space << "b:Spanish to english\n";
- cin >> resp;
- switch (resp)
- {
- case 'a':
- english();
- break;
- case 'b':
- spanish();
- break;
- }
- }
- ////---------------------------------------------------------------------------------------------------------
- void english()
- {
- ifstream fin;
- vector <string> eng;
- vector <string> span;
- string words;
- bool FOUND = 0;
- fin.open("dictionary.txt");
- if (fin.fail())
- {
- cout << "Failed";
- exit(1);
- }
- do{
- getline(fin, words, ',');
- eng.push_back(words);
- getline(fin, words);
- span.push_back(words);
- }while (!fin.eof());
- /////////////////////////////////////////////
- cout << "English-SPanish-Now type in a Word you want to translate\n";
- cin >> words;
- for (int i=0; i< words.length(); i++)
- words[i]= toupper(words[i]);
- cout << "you entered " << words << endl;
- for (unsigned int i=0; i<eng.size(); i++)
- {
- if (eng[i]==words)
- {
- cout << "Spanish translation is \n" << span[i] << endl;
- FOUND = 1;
- }
- if (FOUND)
- break;
- }
- ///////////////////////////////////////////
- fin.close();
- }
- ///////
- void spanish()
- {
- ifstream fin;
- vector <string> eng;
- vector <string> span;
- string words,temp;
- bool FOUND = 0;
- fin.open("dictionary.txt");
- if (fin.fail())
- {
- cout << "Failed";
- exit(1);
- }
- do{
- getline(fin, words);
- eng.push_back(words);
- getline(fin, words, ',');
- span.push_back(words);
- }while (!fin.eof());
- /////////////////////////////////////////////
- cout << " Spanish-English Now type in a Word you want to translate\n";
- cin >> words;
- for (int i=0; i < words.length(); i++)
- words[i]= toupper(words[i]);
- cout << "you entered " << words << endl;
- for (unsigned int i=0; i<span.size(); i++)
- {
- if (span[i]==words)
- {
- cout << "Spanish translation is \n" << eng[i] << endl;
- FOUND = 1;
- }
- if (FOUND)
- break;
- }
- ///////////////////////////////////////////
- fin.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement