Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class WARTOSC {
- double w;
- public:
- WARTOSC (double a = 0) {w = a;}
- double zwroc() { //metoda zwracajaca wartosc
- return w;
- }
- virtual void wypisz()
- {
- cout<<w<<" ";
- }
- friend istream & operator >> (istream & wejscie, WARTOSC & obj) {
- wejscie>>obj.w;
- return wejscie;
- }
- friend ostream & operator << (ostream & wyjscie, WARTOSC & obj) {
- wyjscie<<obj.w<<endl;
- return wyjscie;
- }
- WARTOSC operator+(const WARTOSC & obj) const
- {
- return WARTOSC(w + obj.w);
- }
- };
- class WAGA : public WARTOSC {
- private:
- string jednostka;
- public:
- WAGA(double a, string j):WARTOSC(a) {
- jednostka = j;
- }
- void wypisz()
- {
- WARTOSC::wypisz();
- cout<<jednostka<<endl;
- }
- };
- class MIARA : public WARTOSC {
- private:
- string jednostka;
- public:
- MIARA(double a, string j):WARTOSC(a) {
- jednostka = j;
- }
- void wypisz()
- {
- WARTOSC::wypisz();
- cout<<jednostka<<endl;
- }
- };
- int main() {
- //zadanie 2
- //a
- WAGA c(5, "kg");
- MIARA x(0, "m");
- //b
- cout<<c.zwroc()<<endl<<endl;
- //c
- cin>>x;
- x.wypisz();
- //d
- WARTOSC wynik = c + x;
- cout << wynik.zwroc() << endl;
- //zadanie 3
- WARTOSC * wsk;
- wsk=&c;
- wsk->wypisz();
- wsk=&x;
- wsk->wypisz();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement