Untitled
unknown
c_cpp
3 years ago
1.9 kB
9
Indexable
// Online C++ Compiler - Build, Compile and Run your C++ programs online in your favorite browser
#include<iostream>
using namespace std;
class Zwierze {
public:
string imie;
int wiek;
string gatunek;
explicit Zwierze(string x, int y, string z) {
imie = x;
wiek = y;
gatunek = z;
}
void zmienDane(string x, int y, string z) {
imie = x;
wiek = y;
gatunek = z;
}
void wypiszDane() {
cout<<"imie: "<<imie<<" "<<"wiek: "<<wiek<<" "<<"gatunek: "<<gatunek<<endl;
}
};
class Pies : public Zwierze {
public:
using Zwierze::Zwierze;
void dajGlos() {
cout<<"Hau"<<endl;
}
};
class Kot : public Zwierze {
public:
using Zwierze::Zwierze;
void dajGlos() {
cout<<"Miau"<<endl;
}
};
class Krowa : public Zwierze {
public:
using Zwierze::Zwierze;
void dajGlos() {
cout<<"Muuu"<<endl;
}
};
class Ryba : public Zwierze {
public:
using Zwierze::Zwierze;
void dajGlos() {
cout<<"Blob"<<endl;
}
};
class Swinia : public Zwierze {
public:
using Zwierze::Zwierze;
void dajGlos() {
cout<<"Chrum"<<endl;
}
};
int main()
{
Zwierze zwierzeta[5] = {Pies("Kata", 1, "Pies"), Kot("Misia", 3, "Kot"), Swinia("Kinga", 27, "Swinia"),
Ryba("Nami", 1, "Ryba"), Krowa("Patka", 26, "Krowa")
};
for (int i=0; i<5; i++) {
zwierzeta[i].wypiszDane();
}
cout<<endl;
cout<<"Zmieniam dane kota:"<<endl;
zwierzeta[2].zmienDane("Mamrot", 3, "Kot");
zwierzeta[2].wypiszDane();
return 0;
}
Editor is loading...