Hyluss

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

Jul 2nd, 2016
543
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. // tworzenie obiektow, konstruktor paramteryczny, funkcje w klasie
  2.  
  3. #include "stdafx.h"
  4. #include <conio.h>
  5. class Time
  6. {
  7. int sekundy;
  8.  
  9. public:
  10. Time::Time (int godz, int min, int sek)
  11. {
  12.     sekundy = godz *60*60 + min*60 + sek;
  13. }
  14.  
  15. Time::Time (int godz, int min)
  16. {
  17.     sekundy = godz *60*60 + min*60;
  18. }
  19.  
  20. Time::Time (int sek)
  21. {
  22.     sekundy = sek;
  23. }
  24.  
  25. void set_time (int godz, int min, int sek)
  26. {
  27.     sekundy = godz *60*60 + min*60 + sek;
  28. }
  29.  
  30.  int get_hours ()
  31. {
  32.     int godziny = sekundy / (60*60);
  33.     return godziny;
  34. }
  35.  
  36. int get_minutes ()
  37. {
  38.     int godziny = sekundy / (60*60);
  39.     int minuty = sekundy / 60 - (godziny*60 );
  40.     return minuty;
  41. }
  42.  
  43. int get_seconds ()
  44. {
  45.     int godziny = sekundy / (60*60);
  46.     int minuty = sekundy / 60 - (godziny*60 );
  47.     int seconds = sekundy - godziny*60*60 - minuty*60;
  48.     return minuty;
  49. }
  50.  
  51.  
  52. };
  53.  
  54. int _tmain(int argc, _TCHAR* argv[])
  55. {
  56. Time czas1 (5,20,30);
  57. Time czas2 (5,20);
  58. Time czas3 (30);
  59.  
  60. printf ("%d \n",czas1.get_hours() );
  61. printf ("%d \n",czas2.get_hours() );
  62. printf ("%d \n",czas3.get_hours() );
  63.  
  64. puts ("\n");
  65.  
  66. printf ("%d \n",czas1.get_minutes() );
  67. printf ("%d \n",czas2.get_minutes() );
  68. printf ("%d \n",czas3.get_minutes() );
  69.  
  70. puts ("\n");
  71.  
  72. printf ("%d \n",czas1.get_seconds() );
  73. printf ("%d \n",czas2.get_seconds() );
  74. printf ("%d \n",czas3.get_seconds() );
  75.  
  76. //puts ("\n");
  77. _getch();
  78.     return 0;
  79. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment