Selasa, 12 April 2011

Program untuk menentukan tahun kabisat atau bukan

#include <iostream.h>
#include <string.h>
#include <conio.h>

class Kabisat
{
  private:
    int bil;
    char tahun[30];

  public:
    Kabisat();
    void hitungKabisat();
    friend istream &operator >> (istream &in, Kabisat &);
    friend ostream &operator << (ostream &out, Kabisat &);
};

int main()
{

  Kabisat x;

  cin >> x;
  cout << x;

  system ("pause");
  return EXIT_SUCCESS;

}


Kabisat::Kabisat(){
  cout << "============================================" << endl;
  cout << "|| PROGRAM UNTUK MENENTUKAN TAHUN KABISAT ||" << endl;
  cout << "============================================" << endl << endl << endl;
  }

void Kabisat::hitungKabisat()
{
    if ( bil % 4 != 0)
      strcpy(tahun,"BUKAN TAHUN KABISAT");
    else if (bil % 100 == 0 && bil % 400 !=0)
      strcpy(tahun,"BUKAN TAHUN KABISAT");
      else
        strcpy(tahun," TAHUN KABISAT");

}

istream &operator >> (istream &in, Kabisat &masukan)
{
  cout << " Masukan Sebuah tahun : " ;
  in >> masukan.bil;

  return in;
}

ostream &operator << (ostream &out, Kabisat &tampil)
{

  tampil.hitungKabisat();
  out << tampil.bil << "  "
      << tampil.tahun << endl;
  return out;
}

OUTPUT :

Tidak ada komentar:

Posting Komentar