#include <iostream> #include <string> using namespace std; class jianli { public: void getvalue() { cin>>name>>age>>sex>>major; } void display() { cout<<"name:"<<name<<endl; cout<<"age:"<<age<<endl; cout<<"sex:"<<sex<<endl; cout<<"major:"<<major<<endl; } private: string name; int age; char sex; string major; }; class jianli1:public jianli { public: void getvalue1() { cin>>school; } void display1() { cout<<"school:"<<school<<endl; } private: string school; }; class jianli2:public jianli { public: void getvalue2() { cin>>pay; } void display2() { cout<<"pay:"<<endl; } private: double pay; }; int main() { jianli1 xiaohua; jianli2 xiaohua2; string a="langchao",b="lenovo"; string c; xiaohua.getvalue(); xiaohua.getvalue1(); xiaohua2.getvalue2(); cin>>c; if(c==a) { xiaohua.display(); xiaohua.display1(); } if(c==b) { xiaohua.display(); xiaohua2.display2(); } return 0; }
原文地址:http://blog.csdn.net/zjx211314/article/details/27353813