I am writing a program using classes, the program should allow a user to enter a time in , hours, minutes, and seconds. The program should then generate the next 20 times (in military time). The problem is I cannot find one example online or in my book that uses classes and also uses cin in main(). Can someone please help with this and let me know how I can fix this? Thanks!
EDIT- I get an error at the cin statements saying it does not know how to handle >> of type Time.
Code:
#include <iostream>
using namespace std;
//Class Declaration
class Time
{
private:
int secs;
int mins;
int hours;
public:
Time(int = 0, int = 0, int = 0);
void settime(int, int , int);
void showtime();
void tictime();
};
// Constructor
Time::Time(int h, int m, int s)
{
secs = s;
mins = m;
hours = h;
}
void Time::settime(int h, int m, int s)
{
secs = s;
mins = m;
hours = h;
return;
}
void Time::showtime()
{
cout << "The time is " << hours << ":" << mins << "." << secs;
cout << endl;
return;
}
void Time::tictime()
{
secs = secs + 1;
if(secs > 59)
mins = mins + 1;
if(mins > 59)
hours = hours +1;
return;
}
int main()
{
Time a, b, c;
cout << "Enter hours\n";
cin >> a;
cout << "Enter minutes\n";
cin >> b;
cout << "Enter seconds\n";
cin >> c;
for(int i = 1; i < 21; i++)
{
a.tictime();
a.showtime();
b.tictime();
b.showtime();
c.tictime();
c.showtime();
}
system("pause");
return 0;
}