I have to write a class called time, which has a set member function that takes no arguments which prompts the user to enter the time and assigns them to hour, minute and second. My question is if the function takes no arguments how would you assign the user's input to those values? Here's the code how i understand it, please let me know if i have approached this in the right way.
#include <iostream>
#include <iomanip>
using namespace std;
class Time
{
private:
int hour;
int minute;
int second;
char ch;
public:
bool setTime()
{
cout << endl << "Enter a time of the appointment (HH:MM:SS
===> ";
cin >> hour >> ch >> minute >> ch >> second;
if (!cin.good() )
{
cout << "Invalid time!";
cout << endl;
cin.clear();
cin.ignore(1024, '\n');
}
else
{
return true;
}
}
void Print()
{
cout << (hour < 10 ? "0" : "") << hour << ":";
cout << (minute < 10 ? "0" : "") << minute << ":";
cout << (second < 10 ? "0" : "") << second << endl;
};