这个程序也是一个MM问我的
我不会啊
好郁闷
靠,算你白活了,看一下书就会了
雁无留踪之意,水无取影之心
继承的概念,注意大小的笔误写就行了,运行下...
#include <iostream.h>
#include <string.h>class Person
{
protected:
char m_strName[20];
int m_nAge;
int m_nSex;
public:
Person(char* name,int age,char sex)
{
strcpy(m_strName,\"李四\");
m_nAge=20;
m_nSex=0;
}
~Person()
{
cout<<\"deconstructor of Person\"<<endl;
}
void Register(char*name,int age,char sex)
{
strcpy(m_strName,name);
m_nAge=age;
m_nSex=(sex=='m'?0:1);
}
void Showme()
{
cout<<\"姓名:\"<<m_strName<<endl;
cout<<\"年龄:\"<<m_nAge<<endl;
cout<<\"性别:\"<<(m_nSex==0?\"男\":\"女\")<<endl;
}
};class Teacher:public Person
{
char m_strDept[20];
int m_nSalary;
public:
Teacher(char *name,int age,char sex,char *dept, int salary):Person(name,age,sex)
{
strcpy(m_strDept,\"电子高专办分室\");
m_nSalary=1500;
}
~Teacher()
{
cout<<\"deconstructor of Teacher\"<<endl;
}
void ShowMe()
{
cout<<\"工作单位:\"<<m_strDept<<endl;
cout<<\"月薪:\"<<m_nSalary<<endl;
}
};
void main()
{
Teacher t1(\"张三\",25,'f',\"电子高专计算机系\",2000);
t1.ShowMe();
}