C++面向对象程序设计第二版第二章习题

在上题的基础上进行如下修改:在类体内声明成员函数,而在类外定义成员函数。

如需知道上题,请看上个博客

#include<iostream>
using namespace std;
class Time
{
    
    
public:
	int hour;
	int minute;
	int sec;
};

int main()
{
    
    
	void set_time(Time &);
	void show_time(Time &);
	Time t;
	set_time(t);
	show_time(t);
	return 0;
}
void set_time(Time &t)
{
    
    
	cin>>t.hour;
	cin>>t.minute;
	cin>>t.sec;
}
void show_time(Time &t)
{
    
    
	cout<<t.hour<<":"<<t.minute<<":"<<t.sec<<endl;
}

猜你喜欢

转载自blog.csdn.net/weixin_48699354/article/details/109036880