Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <sstream>
- using namespace std;
- /*
- Napisz klasę Licznik, zawierającą:
- – prywatne pole liczba (typu int)
- – konstruktor przyjmujący pojedynczy parametr, inicjalizujący pole liczba wartością
- argumentu
- – akcesor (getter) pola liczba
- – metodę inkrementuj(), inkrementującą wartość pola liczba
- Następnie napisz klasę LicznikOdZera, dziedziczącą po klasie Licznik. Nowa klasa powinna
- posiadać wyłącznie konstruktor domyślny (bezargumentowy), inicjalizujący pole liczba wartością
- zero (należy zauważyć, że pole z klasy bazowej jest prywatne).
- */
- class Licznik{
- private:
- int liczba;
- public:
- Licznik(int l){
- this->liczba=l;
- }
- int getLiczba(){
- return this->liczba;
- }
- void inkrementuj(){
- this->liczba++;
- }
- void setLiczba(int l){
- this->liczba = l;
- }
- };
- class LicznikOdZera : public Licznik {
- public:
- LicznikOdZera():Licznik(0){};
- };
- int main()
- {
- Licznik a1(5);
- cout << a1.getLiczba() << endl;
- a1.inkrementuj();
- cout << a1.getLiczba() << endl;
- LicznikOdZera a2;
- a1 = a2;
- cout << a1.getLiczba() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment