#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; } }; intmain() { 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; }
Define a person class person, including name, number, gender, and derive a student class student (increase grades)
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324728203&siteId=291194637
Recommended
Ranking