Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 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] == 'z' || temp[0] == 'Z')
  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. {void zadanie4()
  82.  
  83. vector<string> slownik;
  84. fstream file;
  85.  
  86. file.open("slownik.txt", ios::in);
  87.  
  88. if (temp.lenght())
  89. return;
  90.  
  91. while (!file.eof())
  92. {
  93. string temp;
  94. getline(file, temp);
  95. int pos = temp.length() - 1;
  96. if ( pos>=0 && (temp[pos] == 'a' || temp[pos] == 'A'))
  97. slownik.push_back(temp);
  98. }
  99.  
  100. fstream file2;
  101. file2.open("wynik4.txt", ios::out);
  102.  
  103. if (!file2.good())
  104. return;
  105.  
  106. for(int i = 0; i < slownik.size(); i++)
  107. file2 << slownik[i] << endl;
  108.  
  109. file2.close();
  110. file.close();
  111. }
  112.  
  113.  
  114. int main()
  115. {
  116. srand(time(NULL));
  117. zadanie1();
  118.  
  119. zadanie3();
  120. zadanie2();
  121.  
  122. system("pause");
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement