淘先锋技术网

首页 1 2 3 4 5 6 7

#include<iostream>
#include<string>
using namespace std;
class person{
public:
person(int number,string name)//构造函数
{
 number=number1;
 name=name1;
}
void print()
{
 cout<<"number"<<number<<endl;
 cout<<"name"<<name<<endl;
}
private:
int number;//编号
string name;//姓名
};
class teacher: public person{
public:
 teacher(int number,string name,string work,string company)://构造函数
   person(number,name)
   {
    work=work1;//职称
    company=company1//部门
   }
   void print()
   {
    person::print();
    cout<<"职称"<<work<<endl;
    cout<<"部门"<<company<<endl;
private:
 string work;
 string company;
};
class student:public person{//声明类person是类student的虚基类
public:
 student(int number,string name,int classes,float score):
   person(number,name)
   {
    classes=classes1;
    score=scpre1;
   }
void print()
{
 person::print();
 cout<<"班级"<<classes<<endl;
 cout<<"分数"<<score<<endl;
private:
 int classes;//班号
 float score;//分数
};
int main()
{
 teacher teacher1('1',"xiaoming","教师","baidu")
 cout<<"老师:"<<endl;
 teacher1.print();
 student student1('1',"xiaohong",'1','99')
 student1.print;
 return 0;
}