This commit is contained in:
Light-City
2020-04-06 00:57:02 +08:00
parent f97c156cc4
commit a4d828bb4c
120 changed files with 4413 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
#include<iostream>
#include"clock.h"
using namespace std;
Clock::Clock(int NewH,int NewM,int NewS)
{
this->Hour=NewH;
this->Minute=NewM;
this->Second=NewS;
}
Clock::Clock(Clock &c)
{
this->Hour=c.Hour;
this->Minute=c.Minute;
this->Second=c.Second;
}
void Clock::SetTime(int NewH,int NewM,int NewS)
{
//加不加this指针都一样
this->Hour=NewH;
this->Minute=NewM;
this->Second=NewS;
}
void Clock::ShowTime()
{
cout<<this->Hour<<endl;
cout<<this->Minute<<endl;
cout<<this->Second<<endl;
}
//析构函数
Clock::~Clock()
{
}
int main(int argc, char const *argv[])
{
Clock c(0,0,0);
c.SetTime(10,20,30);
c.ShowTime();
//拷贝构造函数调用
Clock c1(c);
c1.ShowTime();
c1.SetTime(90,98,99);
c1.ShowTime();
system("pause");
return 0;
}

View File

@@ -0,0 +1,26 @@
#ifndef CLOCK
# define CLOCK
class Clock
{
public:
Clock(int NewH,int NewM,int NewS);
Clock(Clock &c);//拷贝构造函数,如果不加,编译器会自动生成一个拷贝构造函数,因此加不加都可以直接使用。
void SetTime(int NewH,int NewM,int NewS);
void ShowTime();
~Clock();//析构函数,编译器会自动产生一个默认的析构函数。
private:
int Hour,Minute,Second;
};
#endif
/*
#ifndef 标识符
程序段1
#else
程序段2
#endif
如果“标识符”未被定义过则编译程序段1否则编译程序段2。
*/