分类: C/C++
2011-08-02 20:23:44
/*
* C++第一个简单实例
* Lzy 2011-8-2
*/
#include
using namespace std;
class Date
{
private:
int year, month,date;
public:
Date(int y=2011, int m=8, int d=2):year(y),month(m),date(d){}
void GetDate(void);
void SetDate(int y, int m, int d);
};
void Date::GetDate(void)
{
cout<
}
void Date::SetDate(int y, int m, int d)
{
year=y; month = m; date = d;
}
int main(void)
{
Date date;
date.GetDate();
cout<<"修改日期输入年月日:";
int y, m, d;
cin>>y>>m>>d;
date.SetDate(y,m,d);
date.GetDate();
return 0;
}
/*
* 访问时间类公有成员实例
* Lzy 2011-8-2
*/
#include
using namespace std;
class Time
{
private:
int hour, minute, second;
public:
void SetTime(int h, int m, int s);
void GetTime(void);
};
void Time::SetTime(int h, int m, int s)
{
hour = (h>24||h<0)?0:h;
minute = (m>=0 && m<60)?m:0;
second = (s>=0 && s<60)?s:0;
}
void Time::GetTime(void)
{
cout<<"现在时间";
cout<
}
int main(void)
{
Time t;
int h, m, s;
cout<<"输入时分秒:";
cin>>h>>m>>s;
t.SetTime(h, m, s);
t.GetTime();
}