Advertisement
Hadix

C++ proejkt

Mar 7th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1.  
  2. #include <iostream>
  3.  
  4. class Czas {
  5. private:
  6.     int sekundy;
  7.     int minuty;
  8.     int godziny;
  9. public:
  10.     int podajSekundy();
  11.     int podajMinuty();
  12.     int podajGodziny();
  13.     void ustawSek(int _ile);
  14.     void ustawMin(int _ile);
  15.     void ustawGodz(int _ile);
  16.     void podajStan();
  17.  
  18. };
  19.  
  20.  
  21. #include "Czas.h"
  22.  
  23.  
  24. int Czas::podajSekundy()
  25. {
  26.     return sekundy;
  27. }
  28.  
  29. int Czas::podajMinuty()
  30. {
  31.     return minuty;
  32. }
  33.  
  34. int Czas::podajGodziny()
  35. {
  36.     return godziny;
  37. }
  38. void Czas::ustawSek(int _ile)
  39. {
  40.     if (_ile >= 0 && _ile < 60) {
  41.         sekundy = _ile;
  42.     }
  43.     else {
  44.         sekundy = 0;
  45.         std::cout << "ERROR - niepoprawny format czasu";
  46.     }
  47. }
  48.  
  49. void Czas::ustawMin(int _ile)
  50. {
  51.     if (_ile >= 0 && _ile < 60) {
  52.         minuty = _ile;
  53.     }
  54.     else {
  55.         minuty = 0;
  56.         std::cout << "ERROR - niepoprawny format czasu";
  57.     }
  58. }
  59.  
  60. void Czas::ustawGodz(int _ile)
  61. {
  62.     if (_ile >= 0 && _ile < 60) {
  63.         godziny = _ile;
  64.     }
  65.     else {
  66.         godziny = 0;
  67.         std::cout << "ERROR - niepoprawny format czasu";
  68.     }
  69. }
  70.  
  71. void Czas::podajStan() {
  72.     std::cout << "Sekundy:"<< " " << sekundy<<" " << "Minuty:"<< " "  << minuty<< " " << "Godziny:" << " " << godziny<< " " << std::endl;
  73. }
  74.  
  75. #include "Czas.h"
  76. #include <iostream>
  77.  
  78. int main()
  79. {
  80.     Czas Test1, Test2, Test3;
  81.     Test1.ustawSek(3);
  82.     Test1.ustawMin(50);
  83.     Test1.ustawGodz(23);
  84.     Test1.podajStan();
  85.     Test2.ustawSek(45);
  86.     Test2.ustawMin(2);
  87.     Test2.ustawGodz(11);
  88.     Test2.podajStan();
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement