#include <iostream>
#include <string.h>
using namespace std;
class Name
{
public:
Name(char *ch = " ");
void Display();
protected:
char m_name[15];
char m_family_name[15];
};
class Employee
{
public:
Employee(char *name = " ", char *add = " ", char *city = " ", char *post = " "):n(name)
{
strncpy(m_add, add, sizeof(m_add));
m_add[sizeof(m_add) - 1] = '/0';
strncpy(m_city, city, sizeof(m_city));
m_city[sizeof(m_city) - 1] = '/0';
strncpy(m_post, post, sizeof(m_post));
m_post[sizeof(m_post) - 1] = '/0';
}
//
void ChangName(char *name = " ")
//
{
//
n(name);
//
}
void Display();
protected:
Name n;
char m_add[100];
char m_city[50];
char m_post[10];
};
Name::Name(char *ch)
{
int i = 0, j = 0;
while(ch[i] != 32)
{
m_name[i] = ch[i];
i++;
}
m_name[i++] = '/0';
while (ch[i] != '/0')
{
m_family_name[j++] = ch[i++];
}
m_family_name[j] = '/0';
}
void Name::Display()
{
cout << m_name << " " << m_family_name << endl;
}
/*
void Employee::ChangName(char *name)
{
strncpy(m_name, name, sizeof(m_name));
m_name[sizeof(m_name) - 1] = '/0';
}
*/
void Employee::Display()
{
//
cout <<"name: " << m_name <<endl;
//
cout << "name: " << n.Display() << endl;
cout << "address: " << m_add << endl;
cout << "city: " << m_city << endl;
cout << "post number: " << m_post << endl;
}
void main()
{
Employee em("张三", "shan gu da dao 48 hao", "XiAn city ShanXi Province", "710600");
em.Display();
Name M("jian yong");
M.Display();
}