test.cpp file#include "test.h"
#include
Time::Time( int hr, int min, int sec)
{
hour = (hr >= 0 && hr < 24) ? hr : 0;
minute = (min >= 0 && min < 60) ? min : 0;
second = (sec >= 0 && sec < 60) ? sec : 0;
}
void Time::settime(int h, int m, int s)
{
hour = (h >= 0 && h < 24) ? h : 0;
minute = (m >= 0 && m < 60) ? m : 0;
second = (s >= 0 && s < 60) ? s : 0;
}
void Time::sethour(int h)
{hour = (h >= 0 && h < 24) ? h : 0;}
void Time::setmin(int m)
{minute = (m >= 0 && m < 60) ? m : 0;}
void Time::setsec(int s)
{second = (s >= 0 && s < 60) ? s : 0;}
int Time::gethour() const {return hour;}
int Time::getmin() const {return minute;}
int Time::getsec() const {return second;}
void Time::printmili() const
{
cout (more...)
t.cpp file
#include <iostream.h>
#include "test.h"
// void increasement(Time &, const int);
main()
{
Time t;
t.sethour(17);
t.setmin(34);
t.setsec(25);
cout << "Result of setting all valid values:\n Hour: "
<< t.gethour()
<< " Minute: " << t.getmin()
<< " Second: " << t.getsec() <<"\n\n";
t.sethour(234);
t.setmin(43);
t.setsec(6373);
cout << "Result of attemping to set invalid hour and"
<< " second\n Hour: " << t.gethour()
<< " Minute: " << t.getmin()
<< " Second: " << t.getsec() <<"\n\n";
t.settime(11,58,0);
// increasement(t, 3);
return 0;
}
//void increasement (Time &tt, const int count)
//{
// cout << "Increasementing minute "<< count
// << " times:\nStart time: ";
// tt.printsta();
//
// for (int i = 1; i<= count ; i++)
// {
// tt.setmin((tt.getmin()+1)%60);
// if (tt.getmin()==0)
// tt.sethour((tt.gethour()+1)%24);
// cout << "\nminute +1: ";
// tt.printsta();
// }
// cout <<endl;
//}
#include "test.h"
// void increasement(Time &, const int);
main()
{
Time t;
t.sethour(17);
t.setmin(34);
t.setsec(25);
cout << "Result of setting all valid values:\n Hour: "
<< t.gethour()
<< " Minute: " << t.getmin()
<< " Second: " << t.getsec() <<"\n\n";
t.sethour(234);
t.setmin(43);
t.setsec(6373);
cout << "Result of attemping to set invalid hour and"
<< " second\n Hour: " << t.gethour()
<< " Minute: " << t.getmin()
<< " Second: " << t.getsec() <<"\n\n";
t.settime(11,58,0);
// increasement(t, 3);
return 0;
}
//void increasement (Time &tt, const int count)
//{
// cout << "Increasementing minute "<< count
// << " times:\nStart time: ";
// tt.printsta();
//
// for (int i = 1; i<= count ; i++)
// {
// tt.setmin((tt.getmin()+1)%60);
// if (tt.getmin()==0)
// tt.sethour((tt.gethour()+1)%24);
// cout << "\nminute +1: ";
// tt.printsta();
// }
// cout <<endl;
//}