Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class Silnik{
- private:
- int pojemnosc;
- public:
- Silnik(){
- pojemnosc = 0;
- }
- Silnik(int poj){
- ustawPojemnosc(poj);
- }
- void ustawPojemnosc(int poj){
- if(poj > 0 && poj < 10000) pojemnosc = poj;
- else pojemnosc = 0;
- }
- int pobierzPojemnosc(){
- return pojemnosc;
- }
- };
- class Pojazd{
- private:
- int rok_produkcji;
- public:
- Pojazd(){
- rok_produkcji = 0;
- }
- Pojazd(int rp){
- ustawRok(rp);
- }
- void ustawRok(int rp){
- if(rp > 1950 && rp < 2017) rok_produkcji = rp;
- else rok_produkcji = 0;
- }
- int pobierzRok(){
- return rok_produkcji;
- }
- };
- class Autobus : public Pojazd{
- public:
- int lbPasaz;
- Silnik * silnik;
- Autobus()
- : Pojazd()
- {
- lbPasaz = 0;
- silnik = new Silnik;
- }
- Autobus(int lb, int rokPr, int poj)
- : Pojazd(rokPr)
- {
- lbPasaz = lb;
- silnik = new Silnik(poj);
- }
- Autobus(Autobus &x)
- : Pojazd(x.pobierzRok())
- {
- lbPasaz = x.lbPasaz;
- silnik = new Silnik(x.silnik->pobierzPojemnosc());
- }
- };
- int main() {
- Autobus jelcz(52, 2010, 5000);
- Autobus ikarus(jelcz);
- Autobus autobus;
- cout << jelcz.pobierzRok() << ", " << jelcz.lbPasaz << ", " << jelcz.silnik->pobierzPojemnosc();
- cout << endl << ikarus.pobierzRok() << ", " << ikarus.lbPasaz << ", " << ikarus.silnik->pobierzPojemnosc();
- cout << endl << autobus.pobierzRok() << ", " << autobus.lbPasaz << ", " << autobus.silnik->pobierzPojemnosc();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement