编写一个时间类Time,包含时,分,秒3个数据成员,成员函数实现对这3个数据成员数值的设置和显示功能。
另外要求:1.time类的定义包含在头文件time.h中;
2.成员函数的定义包含在源程序文件time.cpp中;
3.主函数的定义包含在源程序文件client.cpp中。
#include<iostream.h>
classTimer
{
longsecond;
public:
Timer(intsecond)
{
this->second=second;
}
Timer(intminute,intsecond)
{
this->second=minute*60+second;
}
Timer(inthour,intminute,intsecond)
{
this->second=hour*60+minute*60+second;
}
intgetSecond()
{
returnsecond;
}
};
voidmain()
{
Timert1(45),t2(10,25),t3(1,4,10),t4(2,16,0);
cout<<"Fromt1tot2:"<<t2.getSecond()-t1.getSecond()<<endl;
cout<<"Fromt3tot4:"<<t4.getSecond()-t3.getSecond()<<endl;
}
扩展资料
定义一个日期类:包括年、月、日三个成员变量,显示日期的方法
publicclassDemo{
publicstaticvoidmain(String[]args){
Datedate1=newDate(1994,5,22);
date1.showInfo();
Datedate2=newDate();
date2.year=1995;
date2.month=6;
date2.day=29;
date2.showInfo();
}
}
//日期类:
publicclassDate{
intyear;
intmonth;
intday;
//构造方法
publicDate(intyear,intmonth,intday){
this.year=year;
this.month=month;
this.day=day;
}
publicDate(){
}
publicvoidshowInfo(){
System.out.println(year+"年"+month+"月"+day+"日");
}
}
用c++编写一个时间类Time,包含时,分,秒3个数据成员
Timert1(45),t2(10,25),t3(1,4,10),t4(2,16,0);cout<<"Fromt1tot2:"<<t2.getSecond()-t1.getSecond()<<endl;cout<<"Fromt3tot4:"<<t4.getSecond()-t3.getSecond()<<endl;}
【C++】设计一个时间类Time,其中包含三个数据成员(时hour、分minute、秒...
Timer t1(45),t2(10,25),t3(1,4,10),t4(2,16,0);cout<<"From t1 to t2: "<<t2.getSecond()-t1.getSecond()<<endl;cout<<"From t3 to t4: "<<t4.getSecond()-t3.getSecond()<<endl;}
...一个CTime类,里面封装了时、分、秒三个数据成员,并实现以下功能...
include <iostream>#include <iomanip>using namespace std;class CTime {int hour, minute, second;static int count;public:CTime(int h = 0, int m = 0, int s = 0) {SetTime(h, m, s);count++;}CTime(const CTime& another) {hour = another.hour;minute = another.minute;second ...
设计一简单C++时间类,包含时分秒3个数据成员项,以秒为单位增加时间的成...
说明已为0点,时数清为0m_Hour = 0;}}}\/\/打印时间void MyTime::PrintTime(){std::cout<<m_Hour<<":"<<m_Minute<<":"<<m_Second<<std::endl;}\/\/Main.cpp 文件中的测试代码:#include "MyTime.h"int main(){MyTime time;time...
C++编程编写一个时间类time,包含时,分,秒数据成员实现时间的加,减...
void operator=(time); friend ostream& operator<<(ostream &,time); friend istream& operator>>(istream &,time);};int main(){ time t1,t2(100,300,500),t3(1,2,3); cout<<t1<<endl; cout<<t2<<endl; cout<<t3<<endl; cout<<t2-t3<<endl; cout<<...
c++编程 制作一个时钟,可以显示小时 分秒
类自己写吧,很累,不想写了 bool setTime1(int h, int m, int s) \/\/ 倒计时{ if( (h<0) || (m<0||m>=60) || (s<0||s>=60) ) { printf("Time set error!\\n"); return false; } while( h>0 || m>0 || s>0 ) { printf("%02d:%0...
在线等,挺急的!!用C++设计一个类Time(时间),具有成员私有变量hour,minute...
include <cstdio>using namespace std;class Time{private: int hour, minute, second; \/\/1public: Time(int h, int m, int s) :hour(h), minute(m), second(s) {} \/\/2 void printTime() { printf("%02d:%02d:%02d\\n", hour, minute, second); } \/\/3 int getH...
C++编程实现一个TIME类,要求:
class TIME{private:int h;int m;int s;public:TIME(){};~TIME(){};TIME(int h,int m,int s){this->h = h;this->m = m;this->s = s;}void add_s(int s){this->s = this->s + s;}void set(int h,int m,int s){if(h>23 || h < 0){return ;}if(m>60 || ...
1、声明一个时间类Time,类中有3个私有数据成员Hour,Minute,Second和两...
\/\/1. public class Time{ private int Hour; private int Minute; private int Second; public void SetTime(int h,int m,int s) { Hour=h; Minute=m; Second=s; } public void PrintTime() { printf("%d:%d:%d\\n",Hour,Minute,Second); }} void main()...
用c++编写日期时间计时器,定义一个时间类Time,能提供时、分、秒组成的...
include <windows.h> include <iostream> using namespace std;void main(){ int h=0,m=0,s=0;while(1){ if(s<=60)++s;if(s==60){ ++m;s=0;} if(m==60)++h;cout<<h<<":"<<m<<":"<<s<<endl;Sleep(1000);system("cls");} } 这样行不?不是很明白你的意思!