Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<tchar.h>
- #include<urlmon.h>
- #include<iostream>
- #include<conio.h>
- #include<string>
- #include<fstream>
- #include<vector>
- #include<iosfwd>
- #include<algorithm>
- #include"bass.h"
- #include<ctime>
- #include<set>
- #pragma comment(lib, "bass.lib")
- #pragma comment(lib, "urlmon.lib")
- std::vector<std::string> WordsEng;
- std::vector<std::string> WordsPol;
- unsigned nIlosc;
- #ifndef __DEBUG
- std::wstring s2ws(const std::string& s)
- {
- int len;
- int slength = (int)s.length() + 1;
- len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
- std::wstring r(len, L'\0');
- MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, &r[0], len);
- return r;
- }
- #endif
- void DownloadS(std::string& sWord)
- {
- std::string sUrl = "http://www.diki.pl/images/en/mp3/"+ sWord + ".mp3";
- std::string sDest = "C:/Vocabulary/Sounds/"+ sWord + ".mp3";
- //URLDownloadToFile(NULL, s2ws(sUrl).c_str(), s2ws(sDest).c_str(), 0, NULL );
- URLDownloadToFile(NULL, sUrl.c_str(), sDest.c_str(), 0, NULL );
- }
- void PlayS(std::string& sWord)
- {
- std::string sPath = "C:/Vocabulary/Sounds/"+ sWord + ".mp3";
- HSTREAM stream = BASS_StreamCreateFile(FALSE, sPath.c_str(), 0, 0, 0);
- BASS_ChannelPlay(stream, FALSE);
- Sleep(1500);
- BASS_StreamFree(stream);
- }
- void AddW(std::string& sWordEng, std::string& sWordPol, void (*pfDownloadS)(std::string&))
- {
- std::fstream file;
- file.open("vocabulary.txt", std::ios::app);
- ++nIlosc;
- WordsEng.push_back(sWordEng);
- WordsPol.push_back(sWordPol);
- pfDownloadS(sWordEng);
- file<<sWordEng<<std::endl<<sWordPol<<std::endl;
- file.close();
- }
- void LoadW()
- {
- std::fstream file("vocabulary.txt");
- std::string sWord = "";
- WordsEng.clear();
- WordsPol.clear();
- nIlosc = 0;
- while (!file.eof())
- {
- std::getline(file, sWord);
- ++nIlosc;
- if (!(nIlosc%2==0)) WordsEng.push_back(sWord);
- else WordsPol.push_back(sWord);
- }
- nIlosc /= 2;
- file.close();
- }
- void Test (unsigned nIloscSlowek, void (*pfPlayS)(std::string&), char& cMode)
- {
- std::string sWord;
- unsigned nMode = 0, nGood = 0, nCount = 0;
- std::vector<unsigned> vuIndeks;
- if (nIloscSlowek>nIlosc)
- {
- std::cout<<"Bledna ilosc!"<<std::endl;
- return;
- }
- if (nIloscSlowek == 0 ) nCount = WordsEng.size();
- else nCount = nIloscSlowek;
- for (unsigned i = 0; i<nIlosc; ++i) vuIndeks.push_back(i);
- std::random_shuffle(vuIndeks.begin(), vuIndeks.end());
- for (unsigned i = 0; i<nCount; i++)
- {
- switch (cMode)
- {
- case '1':
- std::cout<<"Co oznacza: "<<WordsEng[vuIndeks[i]]<<"?"<<std::endl;
- std::cin>>sWord;
- if (sWord == WordsPol[vuIndeks[i]]) { std::cout<<"Bardzo dobrze!"<<std::endl; ++nGood; }
- else std::cout<<"Zle! To slowko oznacza: "<<WordsPol[vuIndeks[i]]<<std::endl;
- break;
- case '2':
- std::cout<<"Podaj angielskie slowko oznaczajace: "<<WordsPol[vuIndeks[i]]<<"!"<<std::endl;
- std::cin>>sWord;
- if (sWord == WordsEng[vuIndeks[i]]) { std::cout<<"Bardzo dobrze!"<<std::endl; ++nGood; }
- else std::cout<<"Zle! Chodzilo mi o slowko: "<<WordsEng[vuIndeks[i]]<<std::endl;
- break;
- case '3':
- nMode = rand()%2;
- switch (nMode)
- {
- case 0:
- std::cout<<"Co oznacza: "<<WordsEng[vuIndeks[i]]<<"?"<<std::endl;
- std::cin>>sWord;
- if (sWord == WordsPol[vuIndeks[i]]){ std::cout<<"Bardzo dobrze!"<<std::endl; ++nGood; }
- else std::cout<<"Zle! To slowko oznacza: "<<WordsPol[vuIndeks[i]]<<std::endl;
- break;
- case 1:
- std::cout<<"Podaj angielskie slowko oznaczajace: "<<WordsPol[vuIndeks[i]]<<"!"<<std::endl;
- std::cin>>sWord;
- if (sWord == WordsEng[vuIndeks[i]]) { std::cout<<"Bardzo dobrze!"<<std::endl; ++nGood; }
- else std::cout<<"Zle! Chodzilo mi o slowko: "<<WordsEng[vuIndeks[i]]<<std::endl;
- break;
- }
- break;
- }
- pfPlayS(WordsEng[vuIndeks[i]]);
- }
- std::cout<<"Wynik testu: "<<nGood<<"/"<<nIloscSlowek<<" - "<<((float)nGood/nIloscSlowek)*100<<"%"<<std::endl;
- }
- int main()
- {
- srand(static_cast<unsigned>(time(NULL)));
- nIlosc = 0;
- BASS_Init(-1, 44100, 0, GetConsoleWindow(), NULL);
- LoadW();
- char cChoice;
- std::string sWordEng, sWordPol;
- int nIloscSlowek;
- for (;;)
- {
- std::cout <<"=============================="<<std::endl
- <<"| |"<<std::endl
- <<"| 1.Dodaj nowe slowka |"<<std::endl
- <<"| 2.Posluchaj |"<<std::endl
- <<"| 3.Test |"<<std::endl
- <<"| 4.Wypisz wszystkie slowka |"<<std::endl
- <<"| |"<<std::endl
- <<"=============================="<<std::endl;
- std::cin>>cChoice;
- switch (cChoice)
- {
- case '1':
- std::cout<<"Wpisz x aby przerwac!"<<std::endl<<"=============================="<<std::endl;
- for(;;)
- {
- std::cout<<"angielski: ";
- std::cin>>sWordEng;
- if (sWordEng == "x") break;
- std::cout<<"polski: ";
- std::cin>>sWordPol;
- if (sWordPol == "x") break;
- std::cout<<"=============================="<<std::endl;
- AddW(sWordEng, sWordPol, DownloadS);
- }
- LoadW();
- break;
- case '2':
- std::cout<<"Wpisz slowko: ";
- std::cin>>sWordEng;
- DownloadS(sWordEng);
- PlayS(sWordEng);
- break;
- case '3':
- std::cout<<"Ilosc slowek: ";
- std::cin>>nIloscSlowek;
- std::cout <<"Wybierz forme testu:"<<std::endl
- <<"1. ang -> pol"<<std::endl
- <<"2. pol -> ang"<<std::endl
- <<"3. losowo"<<std::endl;
- std::cin>>cChoice;
- Test(nIloscSlowek, PlayS, cChoice);
- break;
- case '4':
- for (unsigned i = 0; i<nIlosc;++i)
- {
- std::cout<<WordsEng[i]<<" - "<<WordsPol[i]<<std::endl;
- }
- break;
- default:
- BASS_Free();
- exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement