Smart猫小萌
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();}