// Example C++ code for OPT// From: http://www.inference.phy.cam.ac.uk/teaching/comput/C++/examples/SimpleClass.shtml// DateClass.cc// Program to demonstrate the definition of a simple class// and member functions#include <iostream>using namespace std;// Declaration of Date classclass Date {public:Date(int, int, int);void set(int, int, int);void print();private:int year;int month;int day;};int main(){// Declare today to be object of class Date// Values are automatically intialised by calling constructor functionDate today(1,9,1999);cout << "This program was written on ";today.print();cout << "This program was modified on ";today.set(5,10,1999);today.print();return 0;}// Date constructor function definitionDate::Date(int d, int m, int y){if(d>0 && d<31) day = d;if(m>0 && m<13) month = m;if(y>0) year =y;}// Date member function definitionsvoid Date::set(int d, int m, int y){if(d>0 && d<31) day = d;if(m>0 && m<13) month = m;if(y>0) year =y;}void Date::print(){cout << day << "-" << month << "-" << year << endl;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。