複習筆記-構造-繼承

#include "Class.h"
#include <stdio.h>

struct DateInfo
{
	int year;
	int month;
	int day;

	DateInfo()
	{
		year = 2015;
		month = 04;
		day = 02;
	}

	DateInfo(int year, int month, int day)
	{
		this->year = year;
		this->month = month;
		this->day = day;
	}

	void SetDay(int day)
	{
		this->day = day;
	}

	int GetDay()
	{
		return this->day;
	}

	void SetYear(int year)
	{
		this->year = year;
	}

	int GetYear()
	{
		return this->year;
	}

	void SetMonth(int month)
	{
		this->month = month;
	}

	int GetMonth()
	{
		return this->month;
	}
};


struct TimeInfo:DateInfo
{
	int hr;
	int min;
	int sec;

	TimeInfo ()//無參初始化
	{
		hr = 00;
		min = 00;
		sec = 00;
	}

	TimeInfo(int hr,int min,int sec)
	{
		this->hr = hr;
		this->min = min;
		this->sec = sec;
	}

	void SetTime(int hr, int min, int sec)
	{
		this->hr = hr;
		this->min = min;
		this->sec = sec;
	}

	int GetHr()
	{
		return this->hr;
	}

	int Getmin()
	{
		return this->min;
	}
	int GetSec()
	{
		return this->sec;
	}
};

void Test()
{

	TimeInfo time(16,14,55);
	TimeInfo* pt = &time;
	pt->year;
	pt->month;
	pt->day;
	pt->hr;
	pt->min;
	pt->sec;

	DateInfo* pd = &time;
	pd->year;
	pd->month;
	pd->day;

	//printf("%d\n",);
}

int main(void)
{
	Test();

	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章