C언어 Chicken 클래스
너에게제공
466 0 0
#include<iostream>
#include<string>
using namespace std;
class Chicken
{
private: string name;
string breed;
int age;
public: Chicken(string n="",string b="",int a=1)
{
name=n;
breed=b;
age=a;
}
void speak()
{
cout<<"꼬끼오"<<endl;
}
void print()
{
cout<<"이름:"<<name<<"품종:"<<breed<<"나이:"<<age<<endl;
}
};
int main()
{
Chicken my("통통이","오골계",2);
Chicken *p=&my;
my.print();
p->print();
}
#include<string>
using namespace std;
class Chicken
{
private: string name;
string breed;
int age;
public: Chicken(string n="",string b="",int a=1)
{
name=n;
breed=b;
age=a;
}
void speak()
{
cout<<"꼬끼오"<<endl;
}
void print()
{
cout<<"이름:"<<name<<"품종:"<<breed<<"나이:"<<age<<endl;
}
};
int main()
{
Chicken my("통통이","오골계",2);
Chicken *p=&my;
my.print();
p->print();
}