瑞星卡卡安全论坛技术交流区系统软件 c++的一个问题,请各位帮帮忙~~~

1   1  /  1  页   跳转

c++的一个问题,请各位帮帮忙~~~

c++的一个问题,请各位帮帮忙~~~

完成给出的部分代码,它将实现以下任务:
1 用单独的函数初始化时,分,秒
2 按给定的格式 hh:mm:ss 显示时间

class Time
{
  int hour;
  int minute;
  int second;
  public:
  Time()
  {
    hour = 0;
    minute = 0;
    second = 0;
  }
  Time(int hour; int minute = 0; int second = 0)
  {
    hour = hour;
    minute = minute;
    second = second;
  }
  void setTime()
  {
   
  }
};

int main()
{
  Time time;
  time.setTime(12,30,50);
  time.display();
  time.setTime(35);
  time.display();
  time.setTime(42,31);
  time.display();
}
最后编辑2005-11-18 15:03:20
分享到:
gototop
 

#include<iostream>
using namespace std;

class Time
{
int hour;
int minute;
int second;
public:
Time(int hour,int minute = 0,int second = 0)
{
this->hour = hour;
this->minute = minute;
this->second = second;
}
void setTime()
{
  cout<<hour<<":"<<minute<<":"<<second<<endl;
}
};

int main()
{
Time time(12,30,50);
time.setTime();

}
反正这么写显示的就是 12:30:50
gototop
 

看看我这样行不行
#include<iostream>
#include<stdlib.h>
using namespace std;

class Time
{
  int hour;
  int minute;
  int second;
  public:
  Time()
  {
    hour = 0;
    minute = 0;
    second = 0;
  }
  Time(int hour, int minute = 0, int second = 0)
  {
    hour = hour;
    minute = minute;
    second = second;
  }
  void setTime(int x,int y,int z)
  {
    hour = x;
    minute = y;
    second = z;
  }
  void setTime(int x,int y)
  {
   
    minute = x;
    second = y;
  }
  void setTime(int x)
  {
   
    second = x;
  }
  void display()
  {
    cout << hour << ":" << minute << ":" << second << endl;
  }
};

int main()
{
  Time time;
  time.setTime(12,30,50);
  time.display();
  time.setTime(35);
  time.display();
  time.setTime(42,31);
  time.display();
  system("pause");
}
gototop
 

看好要求哦 他是让用单独函数初始化 时分秒

我的和你的好像都不是哦
gototop
 

Time(int hour, int minute = 0, int second = 0)
{
hour = hour;
minute = minute;
second = second;
}

你这里有错误
这样写
Time(int hour, int minute = 0, int second = 0)
{
this->hour = hour;
this->minute = minute;
this->second = second;
gototop
 

偶写的,

Turob C++3.0 IDE通过测试!

PS:浏览器有问题,故没打程序。

附件附件:

下载次数:0
文件类型:image/pjpeg
文件大小:
上传时间:2005-11-18 15:03:20
描述:



gototop
 
1   1  /  1  页   跳转
页面顶部
Powered by Discuz!NT