Print? # Include <iostream>
# Include <string. h>
# Include <iomanip>
Using namespace std;
Class CPerson
{
Protected:
Char * m_szName;
Char * m_szId;
Int m_nSex; // 0: women, 1: man
Int m_nAge;
Public:
CPerson (char * name, char * id, int sex, int age );
Void Show1 ();
~ CPerson ();
};
Class CEmployee: public CPerson
{
Private:
Char * m_szDepartment;
Float m_Salary;
Public:
CEmployee (char * name, char * id, int sex, int age, char * department, float salary );
Void Show2 ();
~ CEmployee ();
};
CPerson: CPerson (char * name, char * id, int sex, int age)
{
M_szName = new char [strlen (name) + 1];
Strcpy (m_szName, name );
M_szId = new char [strlen (id) + 1];
Strcpy (m_szId, id );
M_nSex = sex;
M_nAge = age;
}
Void CPerson: Show1 ()
{
Cout <setw (10) <m_szName <setw (25) <m_szId;
If (m_nSex = 0)
Cout <setw (7) <"women ";
Else
Cout <setw (7) <"man ";
Cout <setw (5) <m_nAge <endl;
}
CPerson ::~ CPerson ()
{
Delete [] m_szName;
Delete [] m_szId;
}
CEmployee: CEmployee (char * name, char * id, int sex, int age, char * department, float salary)
: CPerson (name, id, sex, age)
{
M_szDepartment = new char [strlen (department) + 1];
Strcpy (m_szDepartment, department );
M_Salary = salary;
}
Void CEmployee: Show2 ()
{
Cout <"name" <setw (5) <"id" <setw (5) <"sex" <setw (5) <"age" <setw (15) <"department" <setw (10) <"salary" <endl;
Cout <m_szName <setw (5) <m_szId;
If (m_nSex = 0)
Cout <setw (5) <"women ";
Else
Cout <setw (5) <"man ";
Cout <setw (5) <m_nAge <setw (15) <m_szDepartment <setw (10) <m_Salary <endl;
}
CEmployee ::~ CEmployee ()
{
Delete [] m_szDepartment;
}
Int main ()
{
Char name [10], id [19], department [10];
Int sex, age;
Float salary;
Cout <"input employee's name, id, sex (0: women, 1: man), age, department, salary: \ n ";
Cin> name> id> sex> age> department> salary;
CEmployee employee1 (name, id, sex, age, department, salary );
Employee1.Show2 ();
Return 0;
}
Running result:
# Include <iostream>
# Include <string. h>
# Include <iomanip>
Using namespace std;
Class CPerson
{
Protected:
Char * m_szName;
Char * m_szId;
Int m_nSex; // 0: women, 1: man
Int m_nAge;
Public:
CPerson (char * name, char * id, int sex, int age );
Void Show1 ();
~ CPerson ();
};
Class CEmployee: public CPerson
{
Private:
Char * m_szDepartment;
Float m_Salary;
Public:
CEmployee (char * name, char * id, int sex, int age, char * department, float salary );
Void Show2 ();
~ CEmployee ();
};
CPerson: CPerson (char * name, char * id, int sex, int age)
{
M_szName = new char [strlen (name) + 1];
Strcpy (m_szName, name );
M_szId = new char [strlen (id) + 1];
Strcpy (m_szId, id );
M_nSex = sex;
M_nAge = age;
}
Void CPerson: Show1 ()
{
Cout <setw (10) <m_szName <setw (25) <m_szId;
If (m_nSex = 0)
Cout <setw (7) <"women ";
Else
Cout <setw (7) <"man ";
Cout <setw (5) <m_nAge <endl;
}
CPerson ::~ CPerson ()
{
Delete [] m_szName;
Delete [] m_szId;
}
CEmployee: CEmployee (char * name, char * id, int sex, int age, char * department, float salary)
: CPerson (name, id, sex, age)
{
M_szDepartment = new char [strlen (department) + 1];
Strcpy (m_szDepartment, department );
M_Salary = salary;
}
Void CEmployee: Show2 ()
{
Cout <"name" <setw (5) <"id" <setw (5) <"sex" <setw (5) <"age" <setw (15) <"department" <setw (10) <"salary" <endl;
Cout <m_szName <setw (5) <m_szId;
If (m_nSex = 0)
Cout <setw (5) <"women ";
Else
Cout <setw (5) <"man ";
Cout <setw (5) <m_nAge <setw (15) <m_szDepartment <setw (10) <m_Salary <endl;
}
CEmployee ::~ CEmployee ()
{
Delete [] m_szDepartment;
}
Int main ()
{
Char name [10], id [19], department [10];
Int sex, age;
Float salary;
Cout <"input employee's name, id, sex (0: women, 1: man), age, department, salary: \ n ";
Cin> name> id> sex> age> department> salary;
CEmployee employee1 (name, id, sex, age, department, salary );
Employee1.Show2 ();
Return 0;
}
Running result: