Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. using namespace std;
  5.  
  6. struct Osoby {
  7.     string jmeno;
  8.     int vek;
  9.     char pohlavi;
  10.  
  11.     Osoby() {}
  12.  
  13.     Osoby(string _jmeno, int _vek, char _pohlavi) {
  14.         jmeno = _jmeno;
  15.         vek = _vek;
  16.         pohlavi = _pohlavi;
  17.     }
  18.  
  19.  
  20.  
  21. };
  22.  
  23.  
  24. int main() {
  25.     ifstream cteni("osoby.txt");
  26.     if (!cteni) {
  27.         cout << "neco bylo spatne..." << endl;
  28.         system("pause");
  29.         exit(0);
  30.     }
  31.  
  32.     const int N = 100;
  33.     string j; int v; char p;
  34.     int pocet = 0;
  35.  
  36.  
  37.     Osoby lidi[N];
  38.  
  39.     while (cteni >> j >> v >> p) {
  40.  
  41.         lidi[pocet] = Osoby(j, v, p);
  42.         pocet++;
  43.     }
  44.     cteni.close();
  45.  
  46.  
  47.     int pocetM = 0; int pocetZ = 0;
  48.  
  49.    
  50.     ofstream zapisM("muzi.txt");
  51.     ofstream zapisZ("zeny.txt");
  52.    
  53.     for (int i = 0; i < pocet; i++) {
  54.         if (lidi[i].pohlavi == 'm') {
  55.             zapisM << lidi[i].jmeno << " " << lidi[i].vek << endl;
  56.             pocetM++;
  57.         }
  58.         else {
  59.             zapisZ << lidi[i].jmeno << " " << lidi[i].vek << endl;
  60.             pocetZ++;
  61.         }
  62.     }
  63.  
  64.     cout << "Celkovy pocet muzu je: " << pocetM << endl;
  65.     cout << "Celkovy pocet zen je: " << pocetZ << endl;
  66.  
  67.     zapisM << "celkovy pocet muzu je: " << pocetM << endl;
  68.     zapisZ << "celkovy pocet muzu je: " << pocetZ << endl;
  69.     zapisM.close();
  70.     zapisZ.close();
  71.    
  72.  
  73.  
  74.  
  75.  
  76.     system("pause");
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement