Jumat, 15 April 2011

Program C++ menentukan tahun kabisat


Algoritma :
a.   Inisialisasikan variable x.
b.   Inputkan tahun x.
c.    Proses pembagian inputan tahun x dengan angka 4.
d.   Proses pemilihan menggunakan if...else di mana jika sisa hasil pembagian = 0, maka tahun tersebut adalah tahun kabisat. Tetapi jika sisa hasil pembagian 0 maka tahun tersebut bukan tahun kabisat.
e.   Program selesai.

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

int main () {

    int x;
    cout<<"Masukan tahun : " ;
    cin>>x;

    if (x % 4 == 0)
       cout<<"tahun"<<"\t"<< x <<"\t"<<"adalah tahun kabisat"<<endl;
    else
       cout<<"tahun"<<"\t"<< x <<"\t"<<"Bukan tahun kabisat"<<endl;


    getch();
    return 0;
}

Program classnya :

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

class kabisat {
friend istream& operator >> (istream&, kabisat&);
friend ostream& operator << (ostream&, const kabisat&);

public :
kabisat();
void tentukan(){
     if (x % 4 == 0)
        cout<<" Tahun "<<x<<" adalah Tahun Kabisat "<<endl;
     else
        cout<<" Tahun "<<x<<" Bukan Tahun Kabisat "<<endl;
}


private :
   int x,hasil;     //konstruktor
};

kabisat::kabisat(){
   cout<<" Program menentukan tahun kabisat " << endl;
}

istream& operator >> (istream& cin, kabisat& masuk){
   cout<<"Masukan tahun : "<<endl;
   cin>>masuk.x;
   cout<<endl;

   return cin;
}

ostream& operator << (ostream& out, const kabisat& keluar){
   out<<"Terima kasih dan selamat mencoba...";

   return out;
}

void main(){
kabisat X;
cin>>X;
X.tentukan();
cout<<X;

getch ();
}

Explanation:
The program above diguanakan to find out whether the year is a leap year or not. In this program using a selection of which if ... else if year% 4 = 0 then the year is a leap year. By using the variable x as input the year. The program will work if the year runs out at the 0 and displays the year is a leap year.

2 komentar:

Aku Tau mengatakan...

hebat mbakbrow,,,, tanks zaaaaaaa

Muhammad Misbahul Umam mengatakan...

Great Article :
come to my blog: http://akubecus.blogspot.com/2015/03/tahun-kabisat-pada-c.html

Posting Komentar

Template by:

Free Blog Templates