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.
#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;
}
Comments
Leave a comment