0
点赞
收藏
分享

微信扫一扫

习题 8.1 请检查下面程序,找出其中的错误(先不要上机,在纸面上作人工检查),并改正之。然后上机调试,使之能正常运行。运行时从键盘输入时、分、秒的值,检查输出是否正确。

兽怪海北 2022-03-11 阅读 16
c++c语言

习题 8.1 请检查下面程序,找出其中的错误(先不要上机,在纸面上作人工检查),并改正之。然后上机调试,使之能正常运行。运行时从键盘输入时、分、秒的值,检查输出是否正确。

原代码:

#include <iostream>
using namespace std;
class Time

{
	void set_time(void);
	void show_time(void);
	int hour;
	int minute;
	int sec;
};
Time t;
int main()
{

	set_time();
	show_time();
	return 0;
}
int set_time(void)
{

	cin >> t.hour;
	cin >> t.minute;
	cin >> t.sec;
}

int show_time(void)
{
	cout << t.hour << ″:″ << t.minute << ″ : ″ << t.sec << endl;
}

修改后:

#include <iostream>
using namespace std;

class Time
{
public:
	void set_time(void);
	void show_time(void);
	int hour;
	int minute;
	int sec;
};
Time t;

int main()
{
	t.set_time();
	t.show_time();

	return 0;
}

void Time::set_time(void)
{

	cin >> hour;
	cin >> minute;
	cin >> sec;
}

void Time::show_time(void)
{
	cout << hour << " : " << minute << " : " << sec << endl;
}
举报
0 条评论