コード例 #1
0
        static void Main(string[] args)
        {
            Tempo t1 = new Tempo();
            Tempo t2 = new Tempo();

            t1.Solicita_Tempo();
            t1.Formata_Tempo();
            t2.Solicita_Tempo();
            t2.Formata_Tempo();
            Tempo t = new Tempo();

            t = t1.Adiciona_Tempo(t2);
            Console.Write("A soma dos dois tempos com ");
            t.Formata_Tempo();
            t = t1.Subtrai_Tempo(t2);
            Console.Write("A subtração dos dois tempos com ");
            t.Formata_Tempo();
            Console.ReadLine();
        }
コード例 #2
0
        /*   item f)    */

        public Tempo Subtrai_Tempo(Tempo tempo)
        {
            Tempo t = new Tempo();

            t.setHora(hora - tempo.getHora());
            t.setMin(min - tempo.getMin());
            t.setSeg(seg - tempo.getSeg());

            if (t.seg < 0)
            {
                t.seg = (60 + t.seg);
                t.min--;
            }
            if (t.min < 0)
            {
                t.min = (60 + t.min);
                t.hora--;
            }

            return(t);
        }
コード例 #3
0
        /*   item e)    */

        public Tempo Adiciona_Tempo(Tempo tempo)
        {
            Tempo t = new Tempo();

            t.setHora(hora + tempo.getHora());
            t.setMin(min + tempo.getMin());
            t.setSeg(seg + tempo.getSeg());

            if (t.seg >= 60)
            {
                t.seg = (t.seg - 60);
                t.min++;
            }
            if (t.min >= 60)
            {
                t.min = (t.min - 60);
                t.hora++;
            }

            return(t);
        }