302a.cpp

来自「C++实训教程」· C++ 代码 · 共 30 行

CPP
30 行
字号
/*	302a.cpp	-- Written By S.Y.Feng	demo constructor and overload of Time class*/
#include <iostream.h>
class Time // define Time class
{
		int hh,mm,ss;
  public:
  		Time(){hh=0;mm=0;ss=0;}
  		Time(int h,int m=0,int s=0){hh=h;mm=m;ss=s;}  		
		void Set(int h, int m, int s)	{hh = h; mm = m; ss=s;}
		void Disp();
};
void Time::Disp()
{
		cout << "The time is " << hh << ":"
		<< mm << ":" << ss <<endl;
}
int main()
{
		Time t1(1,11),t2(2,22,22);  //两个对象
		t1.Disp();
		t2.Disp();
		return 0;
}

/* 
The time is 1:11:0
The time is 2:22:22
	
*/

⌨️ 快捷键说明

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