Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. void wyrocznia(){
  9.     string pytanie;
  10.     cout<<"Zadaj zamkniete pytanie"<<endl;
  11.     getline(cin,pytanie);
  12.     bool xd;
  13.     xd=rand()%2;
  14.     if(xd==0)
  15.     cout<<"tak"<<endl;
  16.     else cout<<"nie"<<endl;
  17.    
  18. }
  19.  
  20. void ustaw_generowanie()
  21. {
  22.     srand( time( NULL ) );
  23. }
  24.  
  25.  
  26.  
  27. string changestring(string &napis){
  28.     string removed;
  29.     cout<<"Podaj co chcesz usunac z napisu"<<endl;
  30.     getline(cin,removed);
  31.     cout<<"Podaj co chcesz wstawic do napisu"<<endl;
  32.     string added;
  33.     getline(cin,added);
  34.     size_t pos = napis.find(removed);
  35.    
  36.     while(pos!=string::npos) {
  37.     napis.replace(pos,removed.length(),added);
  38.     pos=napis.find(removed,pos+added.size());
  39. }
  40.     return napis;
  41. }
  42.  
  43. class Villager{
  44.     string name;
  45.     int age;
  46.     int MaxAge;
  47.     bool sex;
  48.     string malesname[5]={"bartek","jacek","tadek","gacek","twoj_stary"};
  49.     string femalesname[5]={"karyna","katarzyna","kurwina","morfina","dopalkracja"};
  50.     public:
  51.         int lifetime(){
  52.             return rand()%101;
  53.         }
  54.         /*string nameL(){
  55.        
  56.             if(sex==0){
  57.            
  58.             return femalesname[rand()%5];
  59.         }
  60.         else return malesname[rand()%5];
  61.     } */
  62.         bool sexL(){
  63.             return rand()%2;
  64.         }
  65.         Villager(){
  66.            
  67.             age=0;
  68.             MaxAge=lifetime();
  69.             sex=sexL();
  70.             if(!sex)
  71.             {
  72.             name=femalesname[rand()%5]; }
  73.             else name=malesname[rand()%5];
  74.            
  75.         }
  76.        
  77.         string get_name(){
  78.             return name;
  79.         }
  80.        
  81.         int get_age(){
  82.             return age;
  83.         }
  84.        
  85.         int get_MaxAge(){
  86.             return MaxAge;
  87.         }
  88.        
  89.         bool get_sex(){
  90.             return sex;
  91.         }
  92.        
  93.         void czas(){
  94.             age++;
  95.         }
  96.         ~Villager(){
  97.             if(age==MaxAge)
  98.             cout<<name<<" umiera w wieku "<<age<<" lat"<<endl;
  99.         }
  100.    
  101. };
  102.  
  103. string weryfikuj(Villager p){
  104.     string plec;
  105.     if(p.get_sex()==0){
  106.         return plec="kobieta";
  107.     }
  108.     else return plec="mezczyzna";
  109. }
  110.  
  111. class Household{
  112.     int n;
  113.     Villager *obiekt=new Villager[n];
  114.     public:
  115.        
  116.         void addage(){
  117.             for(int i=0;i<n;i++){
  118.                 obiekt[i].czas();
  119.             }
  120.         }
  121.        
  122.         void addage2(){
  123.             for(int i=0;i<obiekt->get_MaxAge();i++){
  124.                 addage();
  125.             }
  126.         }
  127. };
  128.  
  129. int main(){
  130. /*  string edited;
  131.     string removed;
  132.     string added;
  133.     cout<<"Podaj napis"<<endl;
  134.     getline(cin,edited);
  135.     cout<<"Podaj to co chcesz usunac z napisu"<<endl;
  136.     getline(cin,removed);
  137.     cout<<"Podaj co chcesz podstawic"<<endl;
  138.     getline(cin,added);
  139.     size_t pos=edited.find(removed);
  140.  
  141.     while(pos!=string::npos) {
  142.         edited.replace(pos,removed.length(), added);
  143.         pos=edited.find(removed,pos+added.size());
  144.     }
  145.      */
  146.    /* string napis;
  147.     cout<<"Podaj napis"<<endl;
  148.     getline(cin,napis);
  149.     changestring(napis);
  150.     cout << napis << endl; */
  151.     ustaw_generowanie();
  152.     Villager zyd;
  153.     Villager zyd2;
  154.     cout<<"Imie: "<<zyd.get_name()<<" "<<"wiek: "<<zyd.get_age()<<" "<<"dlugosc zycia: "<<zyd.get_MaxAge()<<" "<<"plec: "<<weryfikuj(zyd)<<" "<<endl;
  155.     cout<<"Imie: "<<zyd2.get_name()<<" "<<"wiek: "<<zyd2.get_age()<<" "<<"dlugosc zycia: "<<zyd2.get_MaxAge()<<" "<<"plec: "<<weryfikuj(zyd2)<<" "<<endl;
  156.     for(int i=zyd.get_age();i<zyd.get_MaxAge();i++){
  157.         cout<<zyd.get_age()<<endl;
  158.        
  159.         zyd.czas();
  160.  
  161.     }
  162.    
  163.     return 0;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement