#include <iostream>
using namespace std;
class Time {
private:
int hours;
int minutes;
public:
void set_time(int, int);
void print_time();
int convert_to_min(int, int);
};
void Time::set_time(int hrs, int mins) {
hours = hrs;
minutes = mins;
}
void Time::print_time() {
cout << hours << ':' << minutes;
}
int Time::convert_to_min(int hrs, int mins) {
return hrs * 60 + mins;
}
int main() {
Time time;
int hrs, mins;
cout << "Enter the time: ";
cin >> hrs >> mins;
time.set_time(hrs, mins);
cout << "Time is: ";
time.print_time();
cout << "\nTime in minutes is: " << time.convert_to_min(hrs, mins);
return 0;
}
Output:
Comments
Leave a comment