Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Silnik
  7. {
  8. public:
  9.     Silnik() {}
  10.  
  11.     Silnik(int pojemnosc, string producent) {
  12.         this->pojemnosc = pojemnosc;
  13.         this->producent = producent;
  14.     }
  15.  
  16.     string getProducent() {
  17.         return producent;
  18.     }
  19.  
  20.     string toString() {
  21.         return " SILNIK: producent - " + producent + " pojemnosc - " + to_string(pojemnosc);
  22.     }
  23.  
  24. private:
  25.     int pojemnosc;
  26.     string producent;
  27. };
  28.  
  29. class Urzadzenie
  30. {
  31. public:
  32.     Urzadzenie() {}
  33.  
  34.     Urzadzenie(int obroty, Silnik silnik) {
  35.         this->obroty = obroty;
  36.         this->silnik = silnik;
  37.     }
  38.  
  39.     string getProducent() {
  40.         return producent;
  41.     }
  42.  
  43.     Silnik getSilnik() {
  44.         return this->silnik;
  45.     }
  46.  
  47.     string toString() {
  48.         return "URZADZENIE: producent - " + producent + " obroty - " + to_string(obroty) + " ____ " + silnik.toString();
  49.     }
  50. private:
  51.     const string producent = "BOSCH";
  52.     int obroty = 0;
  53.     Silnik silnik;
  54. };
  55.  
  56. int const ilosc = 6;
  57. string zwroc(Urzadzenie tab[]);
  58.  
  59. int main() {
  60.  
  61.     Urzadzenie tab[ilosc] = {
  62.         Urzadzenie(1000, Silnik(600, "BOSCH")),
  63.         Urzadzenie(2000, Silnik(1200, "INNY")),
  64.         Urzadzenie(3000, Silnik(1500, "BOSCH")),
  65.         Urzadzenie(4000, Silnik(1800, "BOSCH")),
  66.         Urzadzenie(5000, Silnik(2500, "JAKIS")),
  67.         Urzadzenie(6000, Silnik(3000, "BOSCH")),
  68.     };
  69.  
  70.     cout << zwroc(tab);
  71.  
  72. }
  73.  
  74. string zwroc(Urzadzenie tab[]) {
  75.  
  76.     string wyswietl = "";
  77.    
  78.     for (int i = 0; i < ilosc; i++)
  79.     {
  80.         if (tab[i].getProducent() == tab[i].getSilnik().getProducent())
  81.         {
  82.             wyswietl += "Poz nr "+to_string(i+1) + ": " +tab[i].toString() + "\n";
  83.         }
  84.     }
  85.  
  86.     return wyswietl;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement