#include<iostream.h>
class date
{
private:
int day;
int month;
int year;
public:
void getdate(void)
{
cout<<"/nEnter the day(dd):";
cin>>day;
cout<<"/nEnter the month(mm):";
cin>>month;
cout<<"/nEnter the year(yy):";
cin>>year;
} //函数getdate结束
void display(void)
{
cout<<"/nThe date is"<<day<<"/";
cout<<month<<"/"<<year<<endl;
} //函数display结束
};
void main()
{
date today;
today.getdate();
today.display();
}
--《面向对象编程:C++》
本文展示了一个简单的C++面向对象编程实例,通过定义一个日期类并实现获取和显示日期的功能。用户可以输入日、月、年,程序将按指定格式输出完整的日期。
1378

被折叠的 条评论
为什么被折叠?



