Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Samochod
- {
- private: // pola prywatne (cechy obiektu)
- float fuel;
- int passengers;
- float speed;
- public: // metody publiczne (działania obiektu)
- Samochod(); // konstruktor domyślny (bezargumentowy)
- void accelerate();
- void refuel(float amount);
- void print();
- };
- Samochod::Samochod()
- {
- fuel = 0;
- passengers = 5;
- speed = 0;
- cout << "Samochod zostal stworzony\n";
- }
- void Samochod::accelerate()
- {
- if (fuel == 0)
- {
- cout << "Nie mozna przyspieszyc!\n";
- return;
- }
- speed += 10;
- --fuel;
- cout << "Samochod przyspieszyl, teraz jedzie " << speed << " km/h\n";
- }
- void Samochod::refuel(float amount)
- {
- fuel += amount;
- cout << "Paliwo dotankowano, teraz jest " << fuel << " litrow\n";
- }
- void Samochod::print()
- {
- cout << "fuel: " << fuel << endl;
- cout << "passengers: " << passengers << endl;
- cout << "speed: " << speed << endl;
- }
- int main()
- {
- Samochod s1; // wywołanie konstruktora domyślnego
- s1.accelerate();
- s1.refuel(20);
- s1.accelerate();
- s1.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement