Google PlusFacebookTwitter

Classes – Time Data

By on Apr 8, 2007 in On A Whim | 4 comments

Share On GoogleShare On FacebookShare On Twitter

/* Copyright © 2007 Ankur Banerjee. Special thanks to Naman Bagga for source code verification. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. */

/* Classes – Program to perform functions on time data */

#include <iostream.h>
#include <conio.h>

class time
int hours, minutes, second;
void readtime(int h, int m, int s)
hours = h;
minutes = m;
second = s;
void showtime()
cout<<hours<<” : “<<minutes<<” : “<<second;
time addtime(time t1, time t2)
time t3;
t3.second = (t1.second + t2.second) % 60;
t3.minutes = (t1.minutes + t2.minutes) % 60;
t3.minutes += (t1.second + t2.second) / 60;
t3.hours = t1.hours + t2.hours;
t3.hours += (t1.minutes + t2.minutes) / 60;
return t3;
} time1, time2, time3;

void main()
int hh, mm, ss;
cout<<endl<<“Program to perform functions on time”
<<endl<<“Note : Use hours minutes seconds time format”;
cout<<endl<<“Enter first time duration : “;
time1.readtime(hh, mm, ss);
cout<<endl<<“Enter second time duration : “;
time2.readtime(hh, mm, ss);
time3 = time3.addtime(time1, time2);
cout<<endl<<“Added time duration is “;;

/* Output */

Program to perform functions on time
Note : Use hours minutes seconds time format

Enter first time duration : 18 42 42
Enter second time duration : 9 6 19
Added time duration is 27 : 49 : 1


  1. Siddharth Razdan

    April 8, 2007

    Post a Reply

    What could possibly go wrong in this program that you had to write such a “scary” disclaimer?
    Agreed C++ has the capability to churn out the most deadliest of the executables, but it is very very very very very hard to do so by an accident.

    (Siddharth Razdan)

  2. Siddharth Razdan

    April 8, 2007

    Post a Reply

    Anyway, it’s goos to see that you picked up C++ so early. Classes aren’t taught in 11th, I suppose..

    (Siddharth Razdan)

  3. GQ

    April 8, 2007

    Post a Reply

    Nah. That disclaimer is simply the standard text which is supposed to be given with GNU LGPL version 2.1, nothing more. And thanks.

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.