Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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;
- }
Advertisement