302b.cpp

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

CPP
36
字号
/*	302b.cpp	Written By S.Y.Feng	demo a simple Time class
with a default constructor 
The default constructor for class X is one 
that takes no arguments;
it usually has the form X::X().
If no user-defined constructors exist for a class,
C++ system generates a default constructor.
*/
#include <iostream.h>
class Time // define Time class
{
		int hh,mm,ss;
  public:
  		//Time(){hh=0;mm=0;ss=0;}
		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;
		t1.Disp();
		t1.Set(2,22,22);		t1.Disp();
		return 0;
}

/*
The time is 4225416:4238172:1
The time is 2:22:22


*/

⌨️ 快捷键说明

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