yhkn.net
当前位置:首页 >> 【C++】设计一个时间类TimE,其中包含三个数据成员(时hour、分minutE、秒sEConD)... >>

【C++】设计一个时间类TimE,其中包含三个数据成员(时hour、分minutE、秒sEConD)...

#include 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 =

留意下错误信息就行了#include<iostream> using namespace std; class Clock { public: Clock(int h=0,int m=0,int s=0) { hour=h;minute=m;second=s; } void setHour(){cin>>hour;} void setMinute(){cin>>minute;} void setSecond() {cin>>second;} void

#include<iostream> class Clock { public void SetTime(int hour,int minute, int second) { Hour = Minute = Second = 0; if (hour <24 && hour >=0) { Hour = hour; } if (minute< 60 && minute>=0) Minute=minute; if (second<60 && second >=0) Second =

#include <iostream> using namespace std; class time { int hour; int min; int sec; public: time(int h=0,int m=0,int s=0) { hour=h;min=m;sec=s; } ~time(){} friend time operator+(time t1,time t2); friend time operator-(time t1,time t2); void operator=(time);

# include class time { //定义成公有成员 int hour ; int minute; int second ; public :void settime(int hour,int minute,int second){ hour = hour; minute = minute ; second = second ; } void printtime(){ cout cout } }; void main(){ time time; time.settime(9,20,30); //设置时间 time.printtime(); //显示时间 }

//MyTime.h 文件中的代码:#ifndef _MY_TIME_H_#define _MY_TIME_H_class MyTime{public: MyTime(void);//默认构造函数 MyTime(short hour, short minute, short second); ~MyTime(void);private: short m_Hour; short m_Minute; short m_Second;

public class Time{ private int hour; private int minute; private int second; public void setTime(int hour,int minute,int second){ this.hour=hour; this.minute=minute; this.second=second; } public void printTime(){ System.out.println("Now Time is:"+hour+"时"+minute+"分"+second+"秒"); }}

返回一个时间,其时分秒分别为hour,minute,second.例如timeserial(12, 40, 3)返回12:40:03.

#includeusingnamespacestd;classtime{private:inthour,minute,second;public:time(){hour=0;minute=0;second=0;}voidsettime();voidshowtime();};voidtime::settime(){cin>>hour;cin>>minute;cin>>second;}voidtime::showtime(){cout<

//htime.h#include <iostream>using namespace std;class time{ int hour; int minute; int second;public: time(); void acquisitionTime(int &,int &,int &); void printTime();};time::time(){ hour=0; minute=0; second=0;}void time::acquisitionTime(int &h,int &m,

相关文档
网站首页 | 网站地图
All rights reserved Powered by www.yhkn.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com