Advertisement
MalikaImamovic

Datum (struct) #1

Jul 4th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Datum
  5. {
  6.     int dan, mjesec, godina;
  7.    
  8.     void Unos()
  9.     {
  10.         cout<<"Unesite dan, mjesec i godinu: ";
  11.         cin>>dan>>mjesec>>godina;
  12.     }
  13.    
  14.     void Ispis()
  15.     {
  16. cout<<dan<<"."<<mjesec<<"."<<godina<<". god."<<endl;
  17.      }
  18.  
  19.      bool isGodinaPrestupna()
  20.        {
  21.            if ((godina%4==0 && godina%100>0) || godina%400==0)
  22.             return true;
  23.            
  24.             else
  25.             return false;
  26.        }  
  27.        
  28.     void isDatumValidan()
  29.     {
  30.         if (godina<0 || godina>2500)
  31.               {  
  32.           cout << endl << "Uneseni datum je netacan. Molimo, ponovite Vas unos."<< endl << endl;
  33.         Unos();
  34.           }
  35.         else if (mjesec<1 || mjesec>12)
  36.            {
  37.                cout << endl << "Uneseni datum je netacan. Molimo, ponovite Vas unos."<< endl << endl;
  38.         Unos();
  39.            }
  40.         else if (dan<1 || dan>31)
  41.         {
  42.             cout << endl << "Uneseni datum je netacan. Molimo, ponovite Vas unos."<< endl << endl;
  43.         Unos();
  44.         }
  45.         else if (isGodinaPrestupna() && mjesec==2 && dan>29)
  46.           {
  47.         cout << endl << "Uneseni datum je netacan. Molimo, ponovite Vas unos."<< endl << endl;
  48.         Unos();
  49.          }
  50.          else if ((isGodinaPrestupna()==0 && mjesec==2 && dan>28) || (mjesec==4 && dan>30) || (mjesec==6 && dan>30) || (mjesec==9 && dan>30) || (mjesec==11 && dan>30))
  51.          {
  52.              cout << endl << "Uneseni datum je netacan. Molimo, ponovite Vas unos."<< endl << endl;
  53.         Unos();
  54.          }
  55.     }
  56.    
  57.      
  58. };
  59.  
  60. int main()
  61. {
  62.    
  63.   Datum rodjenje;
  64.   rodjenje.Unos();
  65.   cout<<endl;
  66.   rodjenje.isDatumValidan();
  67.   rodjenje.Ispis();
  68.    
  69.   return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement