Advertisement
mirekkrul

Marian

Feb 26th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <cstdlib>
  6. #include <ctime>
  7.  
  8. using namespace std;
  9.  
  10. void zadanie1()
  11. {
  12.     vector<string> slownik;
  13.     fstream file;
  14.  
  15.     file.open("slownik.txt", ios::in);
  16.  
  17.     if (!file.good())
  18.         return;
  19.  
  20.     while (!file.eof())
  21.     {
  22.         string temp;
  23.         getline(file, temp);
  24.         if(temp[0] == 'a' || temp[0] == 'A')
  25.             slownik.push_back(temp);
  26.     }
  27.  
  28.     for (int i = 0; i < slownik.size(); i++)
  29.         cout << slownik[i] << endl;
  30.  
  31.     file.close();
  32. }
  33.  
  34. void zadanie2()
  35. {
  36.     vector<string> slownik;
  37.     fstream file;
  38.  
  39.     file.open("slownik.txt", ios::in);
  40.  
  41.     if (!file.good())
  42.         return;
  43.  
  44.     while (!file.eof())
  45.     {
  46.         string temp;
  47.         getline(file, temp);
  48.         int pos = temp.length() - 1;
  49.         if ( pos>=0 && (temp[pos] == 'a' || temp[pos] == 'A'))
  50.             slownik.push_back(temp);
  51.     }
  52.  
  53.     fstream file2;
  54.     file2.open("wynik2.txt", ios::out);
  55.  
  56.     if (!file2.good())
  57.         return;
  58.  
  59.     for(int i = 0; i < slownik.size(); i++)
  60.         file2 << slownik[i] << endl;
  61.  
  62.     file2.close();
  63.     file.close();
  64. }
  65.  
  66. void zadanie3()
  67. {
  68.     fstream file;
  69.  
  70.     file.open("wynik3.txt", ios::out);
  71.  
  72.     if (!file.good())
  73.         return;
  74.  
  75.     for (int i = 0; i < 1000; i++)
  76.         file << (rand() % 6000) + 3000 << endl;
  77.  
  78.     file.close();
  79. }
  80.  
  81. int main()
  82. {
  83.     srand(time(NULL));
  84.     zadanie1();
  85.    
  86.     zadanie3();
  87.     zadanie2();
  88.  
  89.     system("pause");
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement