zoukankan      html  css  js  c++  java
  • 公有继承中派生类Student对基类Person成员的访问 代码参考

     1 #include <iostream>
     2 #include <cstring>
     3 
     4 using namespace std;
     5 
     6 class Person
     7 {
     8     private:
     9         char Name[20];
    10         char Sex;
    11         int Age;
    12     public:
    13         void Register(char *name, int age, char sex);
    14         void ShowMe();
    15 };
    16 
    17 class Student:public Person
    18 {
    19     private:
    20         int Number;
    21         char ClassName[10];
    22     public:
    23         void RegisterStu(char *classname, int number, char *name, int age, char sex);
    24         void ShowStu();
    25 };
    26 
    27 void Person::Register(char *name, int age, char sex)
    28 {
    29     strcpy(Name,name);
    30     Age=age;
    31     Sex=sex;
    32     return;
    33 }
    34 void Person::ShowMe()
    35 {
    36     cout<<Name<<' '<<Age<<' '<<Sex<<endl;
    37     return;
    38 }
    39 
    40 void Student::RegisterStu(char *classname, int number, char *name, int age, char sex)
    41 {
    42     strcpy(ClassName,classname);
    43     Number=number;
    44     Person::Register(name,age,sex);
    45     return;
    46 }
    47 
    48 void Student::ShowStu()
    49 {
    50     cout<<Number<<' '<<ClassName<<' ';
    51     Person::ShowMe();
    52     Person::ShowMe();
    53     return;
    54 }
    55 
    56 int main()
    57 {
    58     char ClassName[10],Name[20];
    59     char Sex;
    60     int Age,Number;
    61     Student one;
    62     cin>>ClassName>>Number>>Name>>Age>>Sex;
    63     one.RegisterStu(ClassName,Number,Name,Age,Sex);
    64     one.ShowStu();
    65     return 0;
    66 }
    67     
    68     
  • 相关阅读:
    创建并发布npm包
    ubuntu下python+tornado+supervisor+nginx部署
    Ubuntu下pycharm设定任务栏图标后打开出现问号图标
    Ubuntu下安装keras
    Windows和Ubuntu双系统
    Java获取精确到秒的时间戳
    Jmeter Java请求
    git 生成公钥、私钥方法与clone使用方法
    Oracle 安全管理
    五、python沉淀之路--字典
  • 原文地址:https://www.cnblogs.com/Conan-jine/p/12738870.html
Copyright © 2011-2022 走看看