pr11011.cpp

来自「c++编程宝典源码及Quincy99编译器 是《标准C++编程宝典》电子工业出」· C++ 代码 · 共 40 行

CPP
40
字号
////////////////////////////////////////
// File Name: pr11011.cpp
////////////////////////////////////////
#include <iostream>

////////////////////////////////////////
// The Date class definition.
////////////////////////////////////////
class Date
{
    int mo, da, yr;

public:
    Date(int m, int d, int y) { mo = m; da = d; yr = y; }

    // A member function to return the year.
    int getyear() const { return yr; }

    // A member function to set the year.
    void setyear(int y) { yr = y; }
};

////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
    // Set up a Date.
    Date dt(4, 1, 89);

    // Use a member function to read the year value.
    std::cout << "The year is: " << dt.getyear() << std::endl;

    // Use a member function to change the year.
    dt.setyear(97);
    std::cout << "The new year is: " << dt.getyear();

    return 0;
}

⌨️ 快捷键说明

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