I am supposed to create a program like this, with separate clock.cpp, clock.h, and main.cpp files. The program is supposed to do these tasks: I have started the clock.cpp and dont quite know where to go for some of the tasks, and I don't quite know how to use the time.h library
* Setting the Clock's current time by specifying hours, minutes as arguments
* Setting the Clock's current time by reading the time from the operating
system. Use the time() and localtime() calls for this: see "man 2 time", "man 3
localtime". ( Any suggestions on how to go about doing this? )
* Being configured as either a 24-hour or am/pm clock (picture a switch on the
back of a clock that changes its display mode)
* Printing the Clock's current time
* Getting the Clocks' current time (returning hours, minutes as output
parameters -- this is different than printing the current time) (Any suggestions on how to do this? )
* Comparing the time represented in two Clocks using operator<. ( havent attempted this but I don't see it as being so difficult )
#include <time.h>
#include <iostream>
#include <sstream>
using namespace std;
class Clock{
private:
public:
typedef struct{
int hours;
int minutes;
bool military;
bool ampm;
} time;
time setTime( time A ){
cout << "Enter Hours:";
cin >> A.hours;
cout << "\nEnter Minutes:";
cin >> A.minutes;
cout << "\nEnter 1 for a twelve hour clock, 0 for 24";
cin >> A.military;
if( A.military ){
if( A.hours > 12 ){
A.hours = A.hours - 12;
A.ampm = 1;
}
}
}
void printTime( time A ){
cout << "The current time is:" << A.hours << ":" << A.minutes << endl;
}
}
To be honest, i havent created the main program yet, but will do that shortly and will have more questions, Im just seeing what kind of input i get for this program so far.