Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Animal {
- protected:
- int height;
- int weight;
- int width;
- public:
- Animal() {};
- Animal(int height, int weight,int width) {
- this->height = height;
- this->weight = weight;
- this->width = width;
- }
- virtual void print() = 0;
- };
- class Mammals:public Animal {
- private:
- char name[20];
- public:
- Mammals(){}
- Mammals(char *name ,int weight, int height, int width) :Animal(weight, height, width) {
- strcpy(this->name, name);
- }
- void print() {
- cout << "Mammal: ";
- for (int i = 0; i < strlen(name); i++) {
- cout << name[i];
- }
- cout << "\n";
- cout << "Weight: " << weight << "\nHeight: " << height << "\nWidth: " << width << endl;
- }
- ~Mammals(){}
- };
- class Birds:public Animal {
- private:
- char name[20];
- public:
- Birds() {}
- Birds(char *name,int weight, int height,int width):Animal(weight,height,width) {
- strcpy(this->name, name);
- }
- void print() {
- cout << "Bird: ";
- for (int i = 0; i < strlen(name); i++) {
- cout << name[i];
- }
- cout << "\n";
- cout << "Weight: " << weight << "\nHeight: " << height << "\nWidth: " << width << endl;
- }
- ~Birds(){}
- };
- class Fish:public Animal {
- private:
- char name[20];
- public:
- Fish() {
- }
- Fish(char *name ,int weight, int height, int width) :Animal(weight, height, width) {
- strcpy(this->name, name);
- }
- void print() {
- cout << "Fish: ";
- for (int i = 0; i < strlen(name); i++) {
- cout << name[i];
- }
- cout << "\n";
- cout << "Weight: " << weight << "\nHeight: " << height << "\nWidth: " << width << endl;
- }
- ~Fish(){}
- };
- int main() {
- /*char name[20];
- int weight, height, width;
- cin >> name >> weight >> height >> width; ova e za vnesuvanje ako sakas */
- Fish a((char*)"Kit",1200,10,15);// char od prede za kastiranje od string vo char
- a.print();
- Birds b((char*)"Ptica", 2, 3, 4);// char od prede za kastiranje od string vo char
- Mammals c((char*)"Monkey", 5, 6, 7);// char od prede za kastiranje od string vo char
- b.print();
- c.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement