赞
踩
- #include <iostream>
- #include<string.h>
- using namespace std;
- class person
- { private:
- string name,sex;
- int number;
- public:
- void setperson(string n,string s,int nu)
- {
- name = n;
- sex = s;
- number = nu;
- }
- void output();
- };
- void person::output()
- {
- cout<<"name: "<<name<<endl;
- cout<<"sex: "<<sex<<endl;
- cout<<"number: "<<number<<endl;
- }
- class student:public person
- {
- private:
- int grade;
- public:
- student(){}
- student(string n,string s,int nu,int g)
- {
- person::setperson(n,s,nu);
- grade=g;
- }
- void output()
- {
- person::output();
- cout<<"grade: "<<grade<<endl;
- }
- };
- class teacher:public person
- {
- private:
- int teachage;
- public:
- teacher(){}
- teacher(string n,string s,int nu,int t)
- {
- person::setperson(n,s,nu);
- teachage=t ;
- }
- void output()
- {
- person::output();
- cout<<"teachage: "<<teachage<<endl;
- }
- };
- int main()
- {
- student m("李磊","男",16064,100);
- m.output();
- teacher n("赵宝宝","男",1141,20);
- n.output();
- }
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。