hi,
sorry for the newb questions,
ive got this part of a assignment its instructions are:
"Define a class called Clock
-it has a single, private, data member of type unsigned long called secs
-it has these four public interface methods plus necessary constructors

setClock() accepts nothing, returns nothing
- prompts the user for hours, minutes, and seconds since midnight
- then converts the time to seconds since midnight
-the user may enter any number of hours, minutes, seconds, that is s/he is not limited to 24 hours per day, 60 minutes per hour, or 60 seconds per minute
- the mutator method will use the modulus operator to limit the total number of seconds to 86400 before storing it in secs

setTime() accepts three integers, returns nothing
-send three unsigned, long integers as hours, minutes, seconds
-it sets the clock’s secs data member accordingly

mTime() displays the time in military format (00:00:00 to 23:59:59)

time() displays the time in am/pm format

clock may have private methods that support the interface methods – as you see fit "


so far im working on setClock() i dont even really understand what setTime() would do and havent even stated to think about mtime() or time yet

anyway heres what i have so far

#define UL unsigned long

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class Clock
{
private:
UL secs;

public:
void setClock(int, int, int)
void setTime(void)
void Time()
void mTime()

};


int main(void) {  
clock::setClock();
 getchar();
  return 0;    
}

  void Clock::setClock()
{
       UL h, m, s;
     cout << "please enter time in hours, minutes and seconds with a space inbetween  eg. 23 59 59\n";
     cin  >> h >> m >> s;
     
         h+=h*3600;//hours to seconds
         m+=m*60;//minutes to minutes
         s+=s+h+m;//seconds for hours, minutes and minutes
         secs = s % 86400;//using modulus so second contains the remainder less than a full day
         


 void Clock::setTime(UL hrs, UL min, UL sec)
{
     h = hrs;
     m = min;
     s = sec;  
}

am i on the right track with setClock?
i appreciate any help wether it be code or just helping me better understand this stuff

thanks

Recommended Answers

All 2 Replies

Close.

void Clock::setClock()
{
       UL h, m, s;
     cout << "please enter time in hours, minutes and seconds with a space inbetween  eg. 23 59 59\n";
     cin  >> h >> m >> s;
     
         h+=h*3600;//hours to seconds
         m+=m*60;//minutes to minutes
         s+=s+h+m;//seconds for hours, minutes and minutes
         secs = s % 86400;//using modulus so second contains the remainder less than a full day

If you enter 2 for h, your statement loads h with 7202, not 7200. += is wrong in this case.

oh ok that makes sense
anyone got any other ideas , things that could help?

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.