Hakunin

domaci OBP1 V1

Mar 22nd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. /////////////////////////////////// vreme.h /////////////////////////////////////
  2.  
  3. #pragma once
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. class Vreme{
  8. private:
  9.     int sat;
  10.     int minut;
  11.     int sekund;
  12. public:
  13.     Vreme();
  14.     Vreme(int sat,int minut,int sekund);
  15.  
  16.     Vreme dodajVreme(Vreme a, Vreme b);
  17.     void stampajVreme();
  18. };
  19.  
  20. ////////////////////////////////// vreme.cpp //////////////////////////////////////
  21.  
  22. #include "vreme.h"
  23.  
  24. Vreme::Vreme(){
  25.     sat=10;
  26.     minut=20;
  27.     sekund=15;
  28. }
  29.  
  30. Vreme::Vreme(int sat, int minut, int sekund){
  31.     this->sat=sat;
  32.     this->minut=minut;
  33.     this->sekund=sekund;
  34. }
  35.  
  36. Vreme Vreme::dodajVreme(Vreme a, Vreme b){
  37.  
  38.     Vreme temp;
  39.     int tmpsat=0,tmpminut=0;
  40.  
  41.     if((a.sekund+b.sekund)<60){
  42.     temp.sekund=a.sekund+b.sekund;
  43.     }
  44.     else if((a.sekund+b.sekund)>60){
  45.     temp.sekund=a.sekund+b.sekund;
  46.     tmpminut++;
  47.     }
  48.     else{
  49.     temp.sekund=0;
  50.     tmpminut++;
  51.     }
  52.  
  53.     if((a.minut+b.minut+tmpminut)<60){
  54.     temp.minut=a.minut+b.minut+tmpminut;
  55.     }
  56.     else if((a.minut+b.minut+tmpminut)>60){
  57.     temp.minut=a.minut+b.minut+tmpminut-60;
  58.     tmpsat++;
  59.     }
  60.     else{
  61.     temp.minut=0;
  62.     tmpsat++;
  63.     }
  64.  
  65.     if((a.sat+b.sat+tmpsat)<24){
  66.     temp.sat=a.sat+b.sat+tmpsat;
  67.     }
  68.     else if((a.sat+b.sat+tmpsat)>24){
  69.     temp.sat=a.sat+b.sat-24+tmpsat;
  70.     }
  71.     else{
  72.     temp.sat=0;
  73.     }
  74.     return(temp);
  75. }
  76.  
  77. void Vreme::stampajVreme(){
  78.     cout << sat << ":" << minut << ":" << sekund << endl;
  79. }
  80.  
  81. ////////////////////////////////////////////////// Source.cpp //////////////////////////////////////////////////////////////
  82.  
  83. #include<iostream>
  84. #include "vreme.h"
  85.  
  86. using namespace std;
  87.  
  88. int main() {
  89.  
  90.     char a;
  91.     Vreme X = Vreme(11, 24, 44);
  92.     Vreme Y = Vreme();
  93.  
  94.  
  95.     Vreme Z;
  96.  
  97.     Z.dodajVreme(X, Y); //nisam siguran kako se ovo poziva!! -- HOW DOES THIS WORK :(
  98.     Z.stampajVreme();
  99.     cin >> a;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment