Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <algorithm>
- #include <vector>
- #include <ctime>
- using namespace std;
- char zero;
- vector <pair <string, string> > vect;
- void menu()
- {
- system("CLS");
- cout << "|------------------------|" << endl;
- cout << "| DICTIONARY - SLOWNIK |" << endl;
- cout << "| BY MACIEJ & KONRAD |" << endl;
- cout << "|------------------------|" << endl;
- cout << endl;
- cout << "1. TEST" << endl;
- cout << "2. Przeglad slownika" << endl;
- cout << "3. Dodaj wyraz" << endl;
- cout << "4. Usun wyraz" << endl;
- cout << "0. Zakoncz" << endl;
- }
- bool fileRead()
- {
- ifstream file;
- file.open("C:\\Users\\macie\\Desktop\\dictionary.txt");
- if( !file.good() )
- return false;
- while( true )
- {
- string english, polish;
- file >> english >> polish;
- if( !file.fail() )
- {
- vect.push_back(make_pair(english, polish));
- }
- else
- break;
- }
- file.close();
- return true;
- }
- bool fileSave()
- {
- ofstream file;
- file.open("C:\\Users\\macie\\Desktop\\dictionary.txt");
- if( !file.good() )
- return false;
- for(int i=0; i<vect.size(); i++)
- {
- file << vect[i].first << " " << vect[i].second << endl;
- }
- file.close();
- return true;
- }
- void test()
- {
- system("CLS");
- cout << "Wprowadz 0 by wrocic do menu." << endl << endl;
- int a=1, n;
- string str;
- srand(time(NULL));
- while(a==1)
- {
- n = rand() %vect.size();
- while(str != vect[n].second)
- {
- cout << vect[n].first << " ";
- cin >> str;
- if ('0')
- menu();
- }
- cout << "Poprawna odpowiedz!" << endl << endl;
- }
- }
- void showDictionary()
- {
- system("CLS");
- cout << "Wprowadz 0 by wrocic do menu." << endl << endl;
- for(int i=0; i<vect.size(); i++)
- cout << vect[i].first << " " << vect[i].second << endl;
- cin >> zero;
- if (zero=='0')
- menu();
- }
- void addverb()
- {
- system("CLS");
- string english, polish;
- cout << "Wprowadz 0 by wrocic do menu." << endl;
- cout << "Aby dodac wyraz do slownika wprowadz go najpierw po angielsku a nastepnie po polsku." << endl;
- do
- {
- cin >> english;
- cin >> polish;
- vect.push_back(make_pair(english, polish));
- }while(english != "0");
- sort(vect.begin(), vect.end());
- fileSave();
- menu();
- }
- void delverb()
- {
- }
- int main()
- {
- fileRead();
- menu();
- char option;
- cin >> option;
- switch(option)
- {
- case '1':
- test();
- break;
- case '2':
- showDictionary();
- break;
- case '3':
- addverb();
- break;
- case '4':
- delverb();
- break;
- case '0':
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement