Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <ctime>
  7.  
  8. using namespace std;
  9.  
  10. char zero;
  11. vector <pair <string, string> > vect;
  12.  
  13.  
  14. void menu()
  15. {
  16.     system("CLS");
  17.  
  18.     cout << "|------------------------|" << endl;
  19.     cout << "|  DICTIONARY - SLOWNIK  |" << endl;
  20.     cout << "|   BY MACIEJ & KONRAD   |" << endl;
  21.     cout << "|------------------------|" << endl;
  22.     cout << endl;
  23.     cout << "1. TEST" << endl;
  24.     cout << "2. Przeglad slownika" << endl;
  25.     cout << "3. Dodaj wyraz" << endl;
  26.     cout << "4. Usun wyraz" << endl;
  27.     cout << "0. Zakoncz" << endl;
  28. }
  29.  
  30. bool fileRead()
  31. {
  32.     ifstream file;
  33.     file.open("C:\\Users\\macie\\Desktop\\dictionary.txt");
  34.     if( !file.good() )
  35.         return false;
  36.  
  37.     while( true )
  38.     {
  39.         string english, polish;
  40.         file >> english >> polish;
  41.         if( !file.fail() )
  42.         {
  43.             vect.push_back(make_pair(english, polish));
  44.         }
  45.         else
  46.             break;
  47.     }
  48.  
  49.     file.close();
  50.  
  51.     return true;
  52.  
  53. }
  54.  
  55. bool fileSave()
  56. {
  57.     ofstream file;
  58.     file.open("C:\\Users\\macie\\Desktop\\dictionary.txt");
  59.     if( !file.good() )
  60.         return false;
  61.  
  62.     for(int i=0; i<vect.size(); i++)
  63.     {
  64.         file << vect[i].first << " " << vect[i].second << endl;
  65.     }
  66.  
  67.     file.close();
  68.  
  69.     return true;
  70.  
  71. }
  72.  
  73. void test()
  74. {
  75.     system("CLS");
  76.     cout << "Wprowadz 0 by wrocic do menu." << endl << endl;
  77.  
  78.     int a=1, n;
  79.     string str;
  80.     srand(time(NULL));
  81.  
  82.     while(a==1)
  83.     {
  84.         n = rand() %vect.size();
  85.  
  86.         while(str != vect[n].second)
  87.         {
  88.             cout << vect[n].first << " ";
  89.             cin >> str;
  90.  
  91.             if ('0')
  92.                 menu();
  93.         }
  94.  
  95.         cout << "Poprawna odpowiedz!" << endl << endl;
  96.  
  97.     }
  98.  
  99. }
  100.  
  101. void showDictionary()
  102. {
  103.     system("CLS");
  104.  
  105.     cout << "Wprowadz 0 by wrocic do menu." << endl << endl;
  106.  
  107.     for(int i=0; i<vect.size(); i++)
  108.         cout << vect[i].first << " " << vect[i].second << endl;
  109.  
  110.     cin >> zero;
  111.     if (zero=='0')
  112.         menu();
  113. }
  114.  
  115. void addverb()
  116. {
  117.     system("CLS");
  118.  
  119.     string english, polish;
  120.     cout << "Wprowadz 0 by wrocic do menu." << endl;
  121.     cout << "Aby dodac wyraz do slownika wprowadz go najpierw po angielsku a nastepnie po polsku." << endl;
  122.  
  123.     do
  124.     {
  125.         cin >> english;
  126.         cin >> polish;
  127.  
  128.         vect.push_back(make_pair(english, polish));
  129.  
  130.     }while(english != "0");
  131.  
  132.  
  133.     sort(vect.begin(), vect.end());
  134.     fileSave();
  135.     menu();
  136.  
  137.  
  138. }
  139.  
  140. void delverb()
  141. {
  142.  
  143. }
  144.  
  145.  
  146. int main()
  147. {
  148.     fileRead();
  149.     menu();
  150.  
  151.     char option;
  152.  
  153.     cin >> option;
  154.  
  155.  
  156.     switch(option)
  157.     {
  158.     case '1':
  159.         test();
  160.         break;
  161.     case '2':
  162.         showDictionary();
  163.         break;
  164.     case '3':
  165.         addverb();
  166.         break;
  167.     case '4':
  168.         delverb();
  169.         break;
  170.     case '0':
  171.         return 0;
  172.     }
  173.  
  174.  
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement