zoukankan      html  css  js  c++  java
  • 关于构造函数的一点理解

    source code:

    base class:

    class persion 
    {
    protected:
     string _name,_sex,_birthday,_number;
     int _age;
    public:
     persion(string st_name,string st_sex,string st_birthday,int st_age,string st_number);
     persion(){}
     virtual bool SearchData(string studentnumber,string name)=0; 

     void DisplayData();  };

    derived class:

    class Student:virtual public persion
    {
    private:

     string _major;
     string _electiveslesson;
     int _electivessore;  
    public: 
     int basesore[3];
     Student(){}
     Student(string st_name,string st_sex,string st_birthday,int st_age,string st_number);//report student information
     Student(string st_major,int st_chinese,int st_math,int st_english,string st_electiveslesson,int st_electivessore);
          
     bool SearchData(string studentnumber,string name);    
     void DisplayStudentData();         };

    Student::Student(string st_name,string st_sex,string st_birthday,int st_age,string st_number)
    :persion(st_name,st_sex,st_birthday,st_age,st_number)
    {
    }
    Student::Student(string st_major,int st_chinese,int st_math,int st_english,string st_electiveslesson,int st_electivessore)
    {  
     
     _major= st_major;
     basesore[0]=st_chinese;
     basesore[1]=st_math;
     basesore[2]=st_english;
     _electiveslesson=st_electiveslesson;
     _electivessore=st_electivessore;
    }

    bool Student::SearchData(string studentnumber,string name)  
    {
     if(string(name)==string(_name)||string(studentnumber)==string(_number))
     {                        
      cout<<"search success!"<<endl;
      return true;
     }
     else
      return false;

    void Student::DisplayStudentData()            
    {
     cout<<"major "<<"Chinese "<<"math "<<"English "<<"elective "<<"elective score"<<endl;
     cout<<_major<<" ";
     for(int i=0;i<3;i++)
      cout<<basesore[i]<<" ";
     cout<<_electiveslesson<<" "<<_electivessore<<endl;
    }

      case 1:
           {
            cout<<"Please input number,name: ";
            cin>>number>>name;
                              for(x=0;x<st_num;x++)
            {
             if (st_infor[x].SearchData(number,name)==true)
             {
              st_infor[x].DisplayData();
              score_infor[x].DisplayStudentData();
              break;
             }
            
             }
             if(x==st_num)
             cout<<"search no report!"<<endl;
            break;
              }

  • 相关阅读:
    ​Docker 数据卷的管理及自动构建docker镜像
    写代码有这16个好习惯,可以减少80%非业务的bug
    启动Docker“Got permission denied while trying to connect to the Docker daemon socket“问题(亲测可用)
    Docker从入门到干活,看这一篇足矣 [建议收藏]
    docker技术入门与精通(2020.12笔记总结)
    MySQL相关 死锁的发生和避免
    使用docker运行zabbixserver
    Cloudflare 是谁?
    扛得住的MySQL数据库架构
    好未来第一届PHP开源技术大会资料分享
  • 原文地址:https://www.cnblogs.com/batman425/p/3171980.html
Copyright © 2011-2022 走看看