Hyluss icon

Czas, tworzenie obiektow, konst. param., funckje w klasie

Hyluss | PRO | 07/02/16 06:13:44 PM UTC | 0 ⭐ | 481 👁️ | Never ⏰ | []
C |

1.35 KB

|

None

|

0 👍

/

0 👎

// tworzenie obiektow, konstruktor paramteryczny, funkcje w klasie
 
#include "stdafx.h"
#include <conio.h>
class Time
{
int sekundy;
 
public:
Time::Time (int godz, int min, int sek)
{
    sekundy = godz *60*60 + min*60 + sek;
}
 
Time::Time (int godz, int min)
{
    sekundy = godz *60*60 + min*60;
}
 
Time::Time (int sek)
{
    sekundy = sek;
}
 
void set_time (int godz, int min, int sek)
{
    sekundy = godz *60*60 + min*60 + sek;
}
 
 int get_hours ()
{
    int godziny = sekundy / (60*60);
    return godziny;
}
 
int get_minutes ()
{
    int godziny = sekundy / (60*60);
    int minuty = sekundy / 60 - (godziny*60 );
    return minuty;
}
 
int get_seconds ()
{
    int godziny = sekundy / (60*60);
    int minuty = sekundy / 60 - (godziny*60 );
    int seconds = sekundy - godziny*60*60 - minuty*60;
    return minuty;
}
 
 
};
 
int _tmain(int argc, _TCHAR* argv[])
{
Time czas1 (5,20,30);
Time czas2 (5,20);
Time czas3 (30);
 
printf ("%d \n",czas1.get_hours() );
printf ("%d \n",czas2.get_hours() );
printf ("%d \n",czas3.get_hours() );
 
puts ("\n");
 
printf ("%d \n",czas1.get_minutes() );
printf ("%d \n",czas2.get_minutes() );
printf ("%d \n",czas3.get_minutes() );
 
puts ("\n");
 
printf ("%d \n",czas1.get_seconds() );
printf ("%d \n",czas2.get_seconds() );
printf ("%d \n",czas3.get_seconds() );
 
//puts ("\n");
_getch();
    return 0;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎