Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<fstream>
- using namespace std;
- class lidi {
- private:
- string jmeno;
- int vek;
- char pohlavi;
- public:
- lidi(){}
- lidi(string _jmeno, int _vek, char _pohlavi) {
- jmeno = _jmeno; vek = _vek; pohlavi = _pohlavi;
- }
- string DejJ(){ return jmeno; }
- int DejV(){ return vek; }
- char DejPohlavi() { return pohlavi; }
- };
- int main() {
- ifstream cteni("soubor.txt");
- int pocet = 0;
- string s;
- while (getline(cteni, s)) {
- pocet++;
- }
- cteni.clear();
- cteni.seekg(0);
- lidi *osoby = new lidi[pocet];
- int i = 0; string j; int v; char p;
- while (cteni >> j >> v >> p) {
- *(osoby+i) = lidi(j, v, p);
- i++;
- }
- cteni.close();
- for (int i = 0; i < pocet; i++){
- cout << i + 1 << ". Osoba: " << " Jmeno: " << (osoby+i)->DejJ() << ", Vek: " << (osoby + i)->DejV() << ", Pohlavi: " << (osoby + i)->DejPohlavi() << endl;
- }
- ofstream muzi("muzi.txt");
- ofstream zeny("zeny.txt");
- muzi << "Tabulka muzu: " << endl;
- zeny << "Tabulka zen: " << endl;
- for (int i = 0; i < pocet; i++) {
- if ((osoby + i)->DejPohlavi() == 'm') {
- muzi << "Jmeno: " << (osoby + i)->DejJ() << ",Vek: " << (osoby + i)->DejV() << ",Pohlavi: " << (osoby + i)->DejPohlavi() << endl;
- }
- else {
- zeny << (osoby + i)->DejJ() << ", Vek: " << (osoby + i)->DejV() << ", Pohlavi: " << (osoby + i)->DejPohlavi() << endl;
- }
- }
- muzi.close();
- zeny.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement