Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ex1
- {
- class Time : Base
- {
- protected internal Time() : base()
- {
- if (I1 < 0) I1 = 24 + I1;
- else if(I1 > 24)
- {
- I1 = I1 / 24;
- I2 = I1 % 24;
- }
- if (I3 < 0) I3 = 60+I3;
- else if (I3 > 60)
- {
- I2 = I3 / 60;
- I3 = I3 % 60;
- }
- if (I2 < 0) I2 = 60+I2;
- if (I2 > 60)
- {
- I1 = I2 / 60;
- I2 = I2 % 60;
- }
- }
- protected internal Time(int a, int b, int c) : base(a, b, c)
- {
- if (I1 < 0) I1 = 24 + I1;
- else if (I1 > 24)
- {
- I1 = I1 / 24;
- I2 = I2+I1 % 24;
- }
- if (I3 < 0) I3 = 60 + I3;
- else if (I3 > 60)
- {
- I2 =I2+ I3 / 60;
- I3 = I3 % 60;
- }
- if (I2 < 0) I2 = 60 + I2;
- if (I2 > 60)
- {
- I1 =I1+ I2 / 60;
- I2 = I2 % 60;
- }
- }
- public static Time operator -(Time m1, Time m2)
- {
- Time m = new Time(m1.I1 - m2.I1, m1.I2 - m2.I2, m1.I3 - m2.I3);
- return m;
- }
- public Time Add(int sec)
- {
- Time temp = new Time(this.I1,this.I2, this.I3 + sec);
- return temp;
- }
- public override string ToString()
- {
- return I1.ToString() + ":" + I2.ToString() + ":" + I3.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement