⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 10.14.cpp

📁 这是C++的一部分练习程序!对初学者有一定的帮助作用。
💻 CPP
字号:
#include <iostream.h>
#include <string.h>
#include <stdio.h>
typedef char string80[80];
class Date
{
public:
	Date()
	{  }
	Date(int y,int m,int d)
	{  SetDate(y,m,d);  }
	void SetDate(int y,int m,int d)
	{
		Year=y;
		Month=m;
		Day=d;
	}
	void GetStringDate(string80 &Date)
	{  sprintf(Date,"%d,%d,%d",Year,Month,Day);  }
protected:
	int Year,Month,Day;
};
class Time
{
public:
	Time()
	{  }
	Time(int h,int m,int s)
	{  SetTime(h,m,s);  }
	void SetTime(int h,int m,int s)
	{
		Hours=h;
		Minutes=m;
		Seconds=s;
	}
	void GetStringTime(string80 &Time)
	{  sprintf(Time,"%d:%d:%d",Hours,Minutes,Seconds);  }
protected:
	int Hours,Minutes,Seconds;
};
class TimeDate:public Date,public Time
{
public:
	TimeDate()
	{  }
	TimeDate(int y,int mo,int d,int h,int mi,int s):Date(y,mo,d),Time(h,mi,s)
	{  }
	void GetStringDT(string80 &DTstr)
	{  sprintf(DTstr,"%d/%d/%d;%d:%d:%d",Year,Month,Day,Hours,Minutes,Seconds);  }
};
void main()
{
	TimeDate date1,date2(2005,7,7,18,10,30);
	string80 DemoStr;
	date1.SetDate(1998,12,23);
	date1.SetTime(10,10,45);
	date1.GetStringDT(DemoStr);
	cout<<"The date1's date and time is "<<DemoStr<<endl;
	date1.GetStringDate(DemoStr);
	cout<<"The date1's date is "<<DemoStr<<endl;
	date1.GetStringTime(DemoStr);
	cout<<"The date1's time is "<<DemoStr<<endl;
    date2.GetStringDT(DemoStr);
	cout<<"The date2's date and time is "<<DemoStr<<endl;
}



⌨️ 快捷键说明

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