输入时分秒,然后输出现在的时间。
重点理解如何创建一个指针型的对象,而且指针型对象在调用类方法的时候,是用->而不是用点,需要区别一下。
- #include<iostream>
- using namespace std;
-
- class Clock{
- private:
- int h;
- int m;
- int s;
- public:
- void set(int H,int M,int S){
- h=H;
- m=M;
- s=S;
- }
- void display(){
- cout<<"Now is: "<<h<<":"<<m<<":"<<s<<endl;
- }
- };
- int main(){
- Clock a,b,*s,*t;
- a.set(12,2,23);
- a.display();
- b=a;
- b.display();
- s=new Clock;
- s->set(12,3,4);
- s->display();
- }