• 自考新教材--p97


    源程序:

    #include <iostream>

    #include <string>

    using namespace std;

    class myDate

    {

    private:

    int year, month, day;

    public:

    myDate();

    myDate(int);   //默认参数,从右向左初始化

    myDate(int, int);

    myDate(int, int, int);

    void show();

    };

    myDate::myDate() :year(1990), month(9), day(19) {}

    myDate::myDate(int y, int m) : day(25)

    {

    year = y;

    month = m;

    }

    myDate::myDate(int y) : month(12), day(11)

    {

    year = y;

    }

    myDate::myDate(int y, int m, int d)

    {

    year = y;

    month = m;

    day = d;

    }

    void myDate::show()

    {

    cout << "year:" << year << "month:" << month << "day:" << day << endl;

    }

    int main()

    {

    myDate *pM=new myDate();

    myDate *pN=new myDate(1982);

    myDate *pP=new myDate(1992, 5);

    myDate *pQ=new myDate(2001, 11, 11);

    cout << endl;

    pM->show();

    pN->show();

    pP->show(); 

    pQ->show();

    system("pause");

    return 1;

    }

    运行结果:

  • 相关阅读:
    Oracle-函数-split 和 splitstr 的创建
    git merge方法
    查看Android 设备进程id
    内存泄漏
    Mac显示隐藏文件快捷键
    gradle版本
    commit单一文件
    21不下发信号
    FileInputStream read函数何时返回-1
    maven turbonet目录
  • 原文地址:https://www.cnblogs.com/duanqibo/p/12021162.html
Copyright © 2020-2023  润新知