Advertisement
Guest User

new_a_delete_nacteni_ze_soubouru

a guest
Jan 20th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<fstream>
  4. using namespace std;
  5.  
  6. class lidi {
  7. private:
  8.     string jmeno;
  9.     int vek;
  10.     char pohlavi;
  11.  
  12. public:
  13.     lidi(){}
  14.     lidi(string _jmeno, int _vek, char _pohlavi) {
  15.         jmeno = _jmeno; vek = _vek; pohlavi = _pohlavi;
  16.     }
  17.  
  18.     string DejJ(){ return jmeno; }
  19.     int DejV(){ return vek; }
  20.     char DejPohlavi() { return pohlavi; }
  21.  
  22. };
  23.  
  24.  
  25. int main() {
  26.     ifstream cteni("soubor.txt");
  27.     int pocet = 0;
  28.     string s;
  29.     while (getline(cteni, s)) {
  30.        
  31.         pocet++;
  32.     }
  33.     cteni.clear();
  34.     cteni.seekg(0);
  35.     lidi *osoby = new lidi[pocet];
  36.  
  37.  
  38.     int i = 0; string j; int v; char p;
  39.     while (cteni >> j >> v >> p) {
  40.         *(osoby+i) = lidi(j, v, p);
  41.         i++;
  42.     }
  43.     cteni.close();
  44.    
  45.  
  46.     for (int i = 0; i < pocet; i++){
  47.         cout << i + 1 << ". Osoba: " << " Jmeno: " << (osoby+i)->DejJ() << ", Vek: " << (osoby + i)->DejV() << ", Pohlavi: " << (osoby + i)->DejPohlavi() << endl;
  48.        
  49.     }
  50.    
  51.    
  52.     ofstream muzi("muzi.txt");
  53.     ofstream zeny("zeny.txt");
  54.  
  55.     muzi << "Tabulka muzu: " << endl;
  56.     zeny << "Tabulka zen: " << endl;
  57.     for (int i = 0; i < pocet; i++) {
  58.         if ((osoby + i)->DejPohlavi() == 'm') {
  59.             muzi << "Jmeno: " << (osoby + i)->DejJ() << ",Vek: " << (osoby + i)->DejV() << ",Pohlavi: " << (osoby + i)->DejPohlavi() << endl;
  60.         }
  61.         else {
  62.             zeny << (osoby + i)->DejJ() << ", Vek: " << (osoby + i)->DejV() << ", Pohlavi: " << (osoby + i)->DejPohlavi() << endl;
  63.         }
  64.     }
  65.     muzi.close();
  66.     zeny.close();
  67.  
  68.  
  69.  
  70.    
  71.    
  72.  
  73.  
  74.  
  75.  
  76.  
  77.     system("pause");
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement