////////////////////#include <iostream>
////////////////////
////////////////////using namespace std;
////////////////////
////////////////////int main()
////////////////////{
//////////////////// cout << "Hello world!" << endl;
//////////////////// return 0;
////////////////////}
//////////////////#include <iostream>
//////////////////using namespace std;
//////////////////class Circle{
//////////////////int radius;
//////////////////public:
////////////////// Circle() {radius=1;}
////////////////// Circle(int r) {this->radius=r;}
////////////////// void sett(int radius) {this->radius=radius;}
////////////////// double getArea() {return 3.14*radius*radius;}
//////////////////};
//////////////////Circle getC()
//////////////////{
////////////////// Circle tmp(30);
////////////////// return tmp;
//////////////////}
//////////////////int main()
//////////////////{
////////////////// Circle c;
////////////////// cout << c.getArea() << endl;
//////////////////
////////////////// c=getC();
////////////////// cout << c.getArea() << endl;
//////////////////}
//////////////
////////////////#include <iostream>
////////////////using namespace std;
////////////////int main()
////////////////{
//////////////// cout << "i" << '\t'
////////////////
////////////////
////////////////
////////////////}
////////////////*/
////////////////
////////////////#include<stdio.h>
////////////////
////////////////int main() {
//////////////// char word[100];
////////////////
//////////////// scanf("%s", word);
//////////////// printf("%s", word);
////////////////}
////////////////
////////////////// char &find = 'S';
////////////////// &s[0] = 'S';
//////////////#include <iostream>
//////////////using namespace std;
//////////////int main()
//////////////{
////////////// cout << "i" << '\t' << "n" << '\t' << "refn" << endl;
////////////// int i =1;
////////////// int n=2;
////////////// int &refn = n;
////////////// n=4;
////////////// refn++;
////////////// cout << i << '\t' << n << '\t' << refn << endl;
//////////////
////////////// refn = i;
////////////// refn++;
////////////// cout << i << '\t' << n << '\t' <<refn << endl;
//////////////
////////////// int *p=&refn;
////////////// *p=20;
////////////// cout << i << '\t' << n << '\t' << refn << endl;
//////////////}
////////////#include <iostream>
////////////using namespace std;
////////////class C{
////////////int radius;
////////////public:
//////////// C() { radius = 1;}
//////////// C(int r) { radius = r;}
//////////// void sett(int r) { radius = r;}
//////////// double getArea() { return 3.14*radius*radius;}
////////////};
////////////int main()
////////////{
//////////// C c;
//////////// C &refc = c; //둘이 주소까지 같아짐.
//////////// refc.sett(10);
//////////// cout << refc.getArea() << " " << c.getArea();
////////////}
//////////#include <iostream>
//////////using namespace std;
//////////bool average(int a[],int size,int& avg)
//////////{
////////// if(size <=0)
////////// {
////////// return false;
////////// }
////////// int sum=0;
////////// for(int i=0;i<size;i++)
////////// {
////////// sum +=a[i];
////////// }
////////// avg = sum/size;
////////// return true;
//////////}
//////////int main()
//////////{
////////// int x[] = {0,1,2,3,4,5};
////////// int avg;
////////// if(average(x,6,avg)) cout << "평균은 " << avg << endl;
////////// else cout << "매개변수 오류 " << endl;
//////////
////////// if(average(x,-2,avg)) cout << "평균은 " << avg << endl;
////////// else cout << "매개변수 오류 " << endl;
//////////}
////////#include <iostream>
////////using namespace std;
////////class C{
////////private:
//////// int radius;
////////public:
//////// C();
//////// C(int r);
//////// ~C();
//////// double getA() {return 3.14*radius*radius;}
//////// int getR() {return radius;}
//////// void sett(int radius) {this->radius=radius;}
////////
////////};
////////C::C()
////////{
//////// radius = 1;
//////// cout << "생성자 실행 radius = " << radius << endl;
////////}
////////C::C(int r)
////////{
//////// this->radius = r;
//////// cout << "생성자 실행 radius = " << radius << endl;
////////}
////////C::~C()
////////{
//////// cout << "소멸자 실행 radius = " << radius << endl;
////////}
////////void increase(C &c)
////////{
//////// int r = c.getR();
//////// c.sett(r+1);
////////}
////////int main()
////////{
//////// C waffle(30);
//////// increase(waffle);
//////// cout << waffle.getA() << endl;
////////}
//////#include <iostream>
//////using namespace std;
//////class C{
//////int radius;
//////public:
////// C() {radius=1;}
////// C(int r) {this->radius=r;}
////// void sett(int r) {this->radius=r;}
////// double getA() {return 3.14*radius*radius;}
//////};
//////void read(C &donut1)
//////{
////// int r;
////// cout << "정수 값으로 반지름을 입력하세요>> ";
////// cin >> r;
////// donut1.sett(r);
//////}
//////int main()
//////{
////// C donut;
////// read(donut);
////// cout << "donut의 면적 = " << donut.getA() << endl;
//////}
//////
//////
//////#include <iostream>
//////using namespace std;
//////char& find(char s[],int index)
//////{
////// return s[index];
//////}
//////int main()
//////{
////// char name[] = "Mike";
////// cout << name << endl;
//////
////// find(name,0) = 'S';
////// cout << name << endl;
//////
////// char& ref = find(name,2);
////// ref='t';
////// cout << name << endl;
//////
//////}
////#include <iostream>
////using namespace std;
////class C{
////private:
//// int radius;
////public:
//// C(const C& c);
//// C() { radius = 1;}
//// C(int r) { this->radius = r;}
//// double getArea() {return 3.14*radius*radius;}
////};
////C::C(const C& c)
////{
//// radius=c.radius;
//// cout << "복사 생성자 실행 radius = " << radius << endl;
////
////}
////int main()
////{
//// C src(30);
//// C dest(src);
////
//// cout << "원본의 면적 = " << src.getArea() << endl;
//// cout << "사본의 면적 = " << dest.getArea() << endl;
////}
//#include <iostream>
//#include <cstring>
//using namespace std;
//class Person{
//char* name;
//int id;
//public:
// Person(int id,const char* name);
// ~Person();
// void changeName(const char *name);
// void show() {cout << id << ',' << name << endl;}
//};
//Person::Person(int id,const char* name)
//{
// this->id=id;
// int len = strlen(name);
// this->name = new char[len+1];
// strcpy(this->name,name);
//}
//Person::~Person()
//{
// if(name)
// delete [] name;
//}
//void Person::changeName(const char* name)
//{
// if(strlen(name)>strlen(this->name))
// return;
// strcpy(this->name,name);
//}
//int main()
//{
// Person father(1,"Kitea");
// Person daughter(father);
//
// cout << "daughter 객체 생성 직후 ---" << endl;
//
// father.show();
// daughter.show();
//
// daughter.changeName("Grace");
// cout << "daughter 이름을 Grace로 변경한 후 ---" << endl;
// father.show();
// daughter.show();
//
// return 0;
//}
#include <iostream>
#include <cstring>
using namespace std;
class Person
{
char* name;
int id;
public:
Person(int id,const char* name);
Person(const Person& person);
~Person();
void changeName(const char *name);
void show() { cout << id << ',' << name << endl;}
};
Person::Person(int id,const char* name)
{
this->id=id;
int len = strlen(name);
this->name = new char[len+1];
strcpy(this->name,name);
}
Person::Person(const Person& person)
{
this->id=person.id;
int len = strlen(person.name);
this->name = new char [len+1];
strcpy(this->name,person.name);
cout << "복시 생성자 실행. 원본 객체의 이름 " << this->name << endl;
}
Person::~Person()
{
if(name)
delete [ ] name;
}
void Person::changeName(const char* name)
{
if(strlen(name)>strlen(this->name))
return;
strcpy(this->name,name);
}
int main()
{
Person father(1,"Kitae");
Person daughter(father);
cout << "daughter 객체 생성 직후 " << endl;
father.show();
daughter.show();
daughter.changeName("Grace");
cout << "daughter 이름 변경 후 " << endl;
father.show();
daughter.show();
return 0;
}