Jumat, 30 Maret 2012

Program Menentukan Tahun Kabisat

#include <cstdlib>
#include <iostream>

using namespace std;

class kabisat{
      friend istream& operator>>(istream&, kabisat&);
      friend ostream& operator<<(ostream&, kabisat&);
     
      public:
      kabisat();
      void proses();
     
      private:
      int x;
      string cetak;       
      };
     
kabisat::kabisat(){
                   cout<<"\t\tmenentukan tahun kabisat\t\t"<<endl;
                   cout<<endl;
                   }
                  
istream& operator>>(istream& in, kabisat& masuk){
         cout<<"masukkan tahun: ";
         in>>masuk.x;
         return in;
         }
        
ostream& operator<<(ostream& out, kabisat& keluar){
         out<<keluar.x<<" "<<keluar.cetak<<endl<<endl;
         return out;
         }
        
void kabisat::proses(){
         if(x==0) cetak = "awal tahun masehi";
         else if (x>0 && x % 4 == 0) cetak = "tahun kabisat";
         else if (x<0 && x % 4 == 0) cetak = "tahun bukan kabisat";
         else cetak = "bukan tahun kabisat";
         }

int main(int argc, char *argv[])
{
    system("color c7");   
    kabisat tanggal;
    cin>>tanggal;
    tanggal.proses();
    cout<<tanggal;
    system("color c7");   
    system("PAUSE");
    return EXIT_SUCCESS;
}

0 komentar:

Posting Komentar