谭浩强c++第三版课后习题------第八章(类和对象的特性)第二题解法1

1:在类体内定义成员函数。
2:代码如下

#include 

using namespace std;
class Time
{
    private:
    int hour,minute,sec;
    public:
    void set_time()
    {
        cin>>hour>>minute>>sec;
    }
    void disp_time()
    {
        cout<<hour<<":"<<minute<<":"<<sec;
    }
};
int main()
{
   Time t1;
   t1.set_time();
   t1.disp_time();
   return 0;
}
/*/*12 13 14
12:13:14
Process returned 0 (0x0)   execution time : 6.038 s
Press any key to continue.
*/

你可能感兴趣的:(谭浩强c++第三版课后习题------第八章(类和对象的特性)第二题解法1)