p394 11.10 继承和组合.cpp

来自「谭浩强 《C++ 程序设计》第三版的部分课后练习题源码」· C++ 代码 · 共 76 行

CPP
76
字号
#include<iostream>
#include<string>
using namespace std;
class Teacher;
class Birthday
{
      private:
              int year;
              int month;
              int day;
      public:
             Birthday(int y,int m,int d):year(y),month(m),day(d){}
             void birthday_value();
             void display();
      
}; 

void Birthday::display()
{
     cout<<"the birthday is :"<<day<<"/"<<month<<"/"<<year<<endl;
     
}    

void Birthday::birthday_value()
{
     cout<<"please input the day/month/year: ";
     cin>>day>>month>>year;
     
     
} 

class Teacher
{
      private:
              int num;
              string name;
              char sex;
              Birthday day;
              
      public:
             Teacher(int d,int m,int y,int n,string nam,char s):day(y,m,d),num(n),name(nam),sex(s){}
             void setbirvalue();
             void display();
              
};

        

void Teacher::setbirvalue()
{
     day.birthday_value();
     
     
     }    
void Teacher::display()
{
     cout<<"the number is : "<<num<<endl;
     cout<<"the name is : "<<name<<endl;
     cout<<"the sex is : "<<sex<<endl;
     day.display();
     
     
}       
      
int main()
{
    Teacher t(23,8,1978,3457264,"ji qiang",'m');
    t.display();
    t.setbirvalue();
    t.display();
    system("pause");
    return 0;
    
    
    }         

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?