Advertisement
Guest User

zad1g2.cpp

a guest
Jan 28th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. void wczytaj(vector<int> &data, char x)
  9. {
  10.     fstream plik("dane.txt");
  11.  
  12.     if (plik.is_open())
  13.     {
  14.         while (!plik.eof())
  15.         {
  16.             string line;
  17.             getline(plik, line);
  18.  
  19.             int a = 0;
  20.  
  21.             for (int i = 0; i < line.size(); i++)
  22.             {
  23.                 char znak = line.at(i);
  24.  
  25.                 if (znak == x)
  26.                     a++;
  27.             }
  28.  
  29.             data.push_back(a);
  30.         }
  31.     }
  32. }
  33.  
  34. void wypisz(vector<int> tab, char x)
  35. {
  36.     cout << "W pliku dane.txt znak " << x << " wystapil: " << endl;
  37.     for (int i = 0; i < tab.size(); i++)
  38.     {
  39.         cout << "Wiersz nr " << i + 1 << " : " << tab.at(i) << endl;
  40.     }
  41. }
  42.  
  43. void czytajZnak(char& x)
  44. {
  45.     cout << "Podaj znak do szukania: ";
  46.     x = getchar();
  47.     cout << endl << endl;
  48. }
  49.  
  50. int main()
  51. {
  52.     vector<int> tab;
  53.     char x;
  54.  
  55.     czytajZnak(x);
  56.     wczytaj(tab,x);
  57.     wypisz(tab, x);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement