Advertisement
Talar97

[JPO] Powtorka egzamin 3

Jun 25th, 2018
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. class Silnik{
  7. private:
  8.     int pojemnosc;
  9. public:
  10.     Silnik(){
  11.         pojemnosc = 0;
  12.     }
  13.    
  14.     Silnik(int poj){
  15.         ustawPojemnosc(poj);
  16.     }
  17.    
  18.     void ustawPojemnosc(int poj){
  19.         if(poj > 0 && poj < 10000) pojemnosc = poj;
  20.         else pojemnosc = 0;
  21.     }
  22.    
  23.     int pobierzPojemnosc(){
  24.         return pojemnosc;
  25.     }
  26. };
  27.  
  28. class Pojazd{
  29. private:
  30.     int rok_produkcji;
  31. public:
  32.     Pojazd(){
  33.         rok_produkcji = 0;
  34.     }
  35.    
  36.     Pojazd(int rp){
  37.         ustawRok(rp);
  38.     }
  39.    
  40.     void ustawRok(int rp){
  41.         if(rp > 1950 && rp < 2017) rok_produkcji = rp;
  42.         else rok_produkcji = 0;
  43.     }
  44.    
  45.     int pobierzRok(){
  46.         return rok_produkcji;
  47.     }
  48. };
  49.  
  50. class Autobus : public Pojazd{
  51. public:
  52.     int lbPasaz;
  53.     Silnik * silnik;
  54.     Autobus()
  55.         : Pojazd()
  56.     {
  57.         lbPasaz = 0;
  58.         silnik = new Silnik;
  59.     }
  60.        
  61.     Autobus(int lb, int rokPr, int poj)
  62.             : Pojazd(rokPr)
  63.     {
  64.         lbPasaz = lb;
  65.         silnik = new Silnik(poj);
  66.     }
  67.    
  68.     Autobus(Autobus &x)
  69.             : Pojazd(x.pobierzRok())
  70.     {
  71.         lbPasaz = x.lbPasaz;
  72.         silnik = new Silnik(x.silnik->pobierzPojemnosc());
  73.     }
  74.                
  75. };
  76.  
  77.  
  78.  
  79. int main() {
  80.     Autobus jelcz(52, 2010, 5000);
  81.     Autobus ikarus(jelcz);
  82.     Autobus autobus;
  83.    
  84.     cout << jelcz.pobierzRok() << ", " << jelcz.lbPasaz << ", " << jelcz.silnik->pobierzPojemnosc();
  85.     cout << endl << ikarus.pobierzRok() << ", " << ikarus.lbPasaz << ", " << ikarus.silnik->pobierzPojemnosc();
  86.     cout << endl << autobus.pobierzRok() << ", " << autobus.lbPasaz << ", " << autobus.silnik->pobierzPojemnosc();
  87.     return EXIT_SUCCESS;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement