Answer to Question #322360 in C++ for ali

Question #322360

Create a class named TIME that has hours, minutes, and seconds, data members, as integers. The class has gettime () to get the specified value in the object, showtime () to display the time object in *hh:mm:ss* format. Write a main () function to create two-time objects. get the value in two objects and display all time objects.

1
Expert's answer
2022-06-30T15:19:34-0400
#include <iostream>

using namespace std;

class TIME
{
	int hours;
	int minutes;
	int seconds;

public:
	void gettime(int hours, int minutes, int seconds)
	{
		this->hours = hours;
		this->minutes = minutes;
		this->seconds = seconds;
	}

	void showtime()
	{
		cout << (hours < 10 ? "0" : "") << hours << ":";
		cout << (minutes < 10 ? "0" : "") << minutes << ":";
		cout << (seconds < 10 ? "0" : "") << seconds << endl;
	}
};

int main()
{
	TIME time1;
	time1.gettime(15, 30, 35);
	TIME time2;
	time2.gettime(8, 30, 5);
	time1.showtime();
	time2.showtime();
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog