#include <iostream> using namespace std; class person{ private: string name,sex,number; public : person( string na ,string s,string n){ name=na; sex=s; number=n; } string getname(){ return name; } string getnumber(){ return number; } void show(); }; void person::show(){ cout<<"姓名 "<<name<<endl; cout<<"性别 "<<sex<<endl; cout<<"编号 "<<number<<endl; } class student:public person{ private : int chengji; string name; public: student( string na,string s,string n,int c):person(na,s,n){ chengji=c; } void show(){ person::show(); cout<<"成绩 "<<chengji<<endl; } }; int main() { person p("张三","男","160693"); student s("王二麻子","男","3189479",100); cout<<p.getname()<<endl; cout<<s.getname()<<endl; cout<<p.getnumber()<<endl; cout<<s.getnumber()<<endl; p.show(); s.show(); return 0; }
定义一个人员类person,包括姓名,编号,性别,派生一个学生类student(增加成绩)
猜你喜欢
转载自blog.csdn.net/liuzmcscs/article/details/80054123
今日推荐
周排行