4 回答
TA贡献1911条经验 获得超7个赞
Clock类 class Clock { int hour; int minute; int seconde; Clock() { hour = 0; minute = 0; seconde = 0; } ~Clock() { cout<<"调用析构函数成功"<<endl; } public void setH(int h) { hour = h; } public void setM(int m) { minute = m; } public void setS(int s) { second = s; } public void display() { String hh = ""; String mm = ""; String ss = ""; if(hour<10)hh = "0"+hour; else hh = ""+hour; if(minute<10)mm = "0"+minute; else mm = ""+minute; if(seconde<10)ss = "0"+seconde; else ss = ""+second; cout<<hh<<":"<<mm<<":"<<ss<<endl; } }
Main类 #include<iostream> using namespace std; int main() { Clock clock = new Clock(); clock.setH(5); clock.display(); } |
- 4 回答
- 0 关注
- 1376 浏览
添加回答
举报