#include <iostream>
#include <string>
using namespace std;
class Animal {
protected:
string name;
int age;
public:
Animal(string n, int a) : name(n), age(a) {}
virtual void sound() = 0;
};
class Dog : public Animal {
public:
Dog(string n, int a) : Animal(n, a) {}
void sound() override {
cout << name << "(" << age << "살):멍멍" << endl;
}
};
class Cat : public Animal {
public:
Cat(string n, int a) : Animal(n, a) {}
void sound() override {
cout << name << "(" << age << "살):야옹" << endl;
}
};
int main() {
string type;
int age;
cin >> type >> age;
if (type == "Dog") {
Dog d(type, age);
d.sound();
} else if (type == "Cat") {
Cat c(type, age);
c.sound();
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: