Advertisement
Paszta

Psy i koty po raz kolejny oraz słowa ranią

Dec 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. 1.
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class pies{
  7. public:
  8.     string gatunek(){
  9.         return "Pies";
  10.     }
  11. };
  12.  
  13. class kot{
  14. public:
  15.     string gatunek(){
  16.         return "Kot";
  17.     }
  18. };
  19.  
  20. template <typename B, int pojemnosc>
  21. class Buda{
  22.     B* miejsca_w_budzie[pojemnosc];
  23.     B *buda;
  24. public:
  25.  
  26.     void umiesc(B* mieszkaniec, int index){
  27.         miejsca_w_budzie[index]=mieszkaniec;
  28.     }
  29.     B* pokazwierza(int index){
  30.         return miejsca_w_budzie[index];
  31.     }
  32. };
  33. int main()
  34. {
  35.     pies p, p2;
  36.     Buda <pies, 2> bp;
  37.     bp.umiesc(&p,0);
  38.     bp.umiesc(&p2,1);
  39.     for(int i=0; i<2; i++){
  40.     cout << "Pies nr" << i << " to " << bp.pokazwierza(i)->gatunek() << endl;
  41.             }
  42.     kot k, k2;
  43.     Buda <kot, 4> bk;
  44.     bk.umiesc(&k,0);
  45.     bk.umiesc(&k2,1);
  46.     cout << bk.pokazwierza(0)->gatunek() << endl;
  47.     cout << bk.pokazwierza(1)->gatunek() << endl;
  48.    
  49.     return 0;
  50. }
  51.  
  52. 2.
  53.  
  54. #include <iostream>
  55. #include <vector>
  56.  
  57. using namespace std;
  58.  
  59. int main()
  60. {
  61.     string slowo;
  62.   vector<string> v1;
  63.   while(true){
  64.   cout << "Podaj slowo" << endl;
  65.   cin >> slowo;
  66.   if(slowo == "exit") break;
  67.   else{
  68.         v1.push_back(slowo);
  69.   }
  70.   }
  71.  
  72. for(int i =0; i<v1.size(); i++){
  73.     cout << v1[i] << endl;
  74.  
  75. }
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement