回复 2楼 tongzhipeng
#include <iostream>
#include <string>
using namespace std;
class person //person类
{
private:
int no; //编号
string name; //姓名
public:
void input() //数据输入
{
cout<<"请输入编号和姓名:";
cin>>no>>name;
}
void display() //数据显示
{
cout<<"编号:"<<no<<endl;
cout<<"姓名:"<<name<<endl;
}
};
class student:public person //学生类
{
private:
int class_id; //班号
double score; //成绩
public:
void get() //学生数据输入
{
input();
cout<< "请输入班号和成绩:";
cin>>class_id>>score;
}
void show() //学生数据显示
{
display();
cout<<"班号:"<<class_id<<endl;
cout<<"成绩:"<<score<<endl;
}
};
class teacher:public person //教师类
{
private:
string pos,dep; //职称与部门
public:
void get() //教师数据输入
{
input();
cout<< "请输入职称和部门:";
cin>>pos>>dep;
}
void show( ) //教师数据显示
{
display();
cout<<"职称:"<<pos<<endl;
cout<<"部门:"<<dep<<endl;
}
};
int main( )
{
student s;
teacher t;
cout<< "学生数据输入\n"<<endl;
s.get( );
s.show( );
cout<< "\n教师数据输入\n"<<endl;
t.get( );
t.show( );
return 0;
}
就比如说这个程序中如果在三个类中分别加如记录实例各自个数的静态成员~
是不是派生类每次都得调用下基类的那个编号和姓名啊