恩 自己写的嘛 已经很不错啦 至少比我写的好
这样改应该可以吧 运行一下试试
-------------------
#include<iostream.h>
#include<string.h>
#define N 2
class data
{
public:
void getdata()
{
cout<<"请输入职工编号:";cin>>anum;
cout<<"请输入职工姓名:";cin>>aname;
cout<<"请输入职工性别:";cin>>asex;
cout<<"请输入职工年龄:";cin>>aage;
cout<<endl<<endl;
}
virtual void display()
{
cout<<anum<<" \t"<<aname<<" \t"<<asex<<" \t"<<aage<<endl;
}
protected:
long anum;
char aname[20],asex[10];
int aage;
};
class sdata:public data
{
public:
void display()
{
cout<<aname<<" \t"<<aage<<endl;
}
};
void printer(data &p)
{
p.display();
}
void main()
{
sdata a[N];
int i;
cout<<" 职工信息输入"<<endl;
for(i=0;i<N;i++)
{
cout<<"请输入第 "<<i+1<<"名职工的信息:"<<endl;
a[i].getdata();
}
cout<<" 职工信息输入"<<endl
<<"----------------------------------"<<endl;
cout<<"职工编号\t职工姓名\t职工性别\t职工年龄"<<endl
<<"----------------------------------"<<endl;
for(i=0;i<N;i++)
{
printer(a[i]);
cout<<"---------------------------------------------------"<<endl;
}
cout<<endl<<endl;
cout<<" 职工简表信息输出"<<endl
<<"-----------------------------------"<<endl;
cout<<"职工姓名\t职工年龄"<<endl
<<"----------------------------------"<<endl;
for(i=0;i<N;i++)
{
printer(a[i]);
cout<<"----------------------------------------"<<endl;
}
}