program menentukan tahun kabisat dalam dec c++
| #include <cstdlib> |
| #include <iostream> |
| #include <fstream> |
| |
| using namespace std; |
| class kabisat { |
| friend ostream& operator<<(ostream&, const kabisat&); |
| friend istream& operator>>(istream&, kabisat&); |
| public: |
| kabisat(){ |
| cout<<"ini adalah program untuk menetukan tahun kabisat"<<endl; |
| } |
| void proses(); |
| private: |
| int n; |
| char*kata; |
| }; |
| |
| istream& operator>>(istream& in, kabisat& masuk){ |
| cout<<"masukan nilai n :"; |
| in>>masuk.n; |
| return in; |
| } |
| ostream& operator<<(ostream& out, const kabisat& keluar){ |
| out<<keluar.kata<<endl; |
| return out; |
| } |
| void kabisat :: proses (){ |
| if (n%4 == 0){ |
| kata="kabisat"; |
| } |
| else { |
| kata="bukan kabisat"; |
| } |
| } |
| int main(int argc, char *argv[]) |
| { |
| kabisat x; |
| cin>>x; |
| x.proses(); |
| cout<<x; |
| system("PAUSE"); |
| return EXIT_SUCCESS; |
| } |
Berikut adalah konversi dalam Jeliot
| import jeliot.io.*; |
| |
| class kabisat { |
| public kabisat(){ |
| System.out.print("ini adalah program untuk menetukan tahun kabisat"); |
| } |
| private int n; |
| private String kata; |
| |
| public void kabisatproses(int n){ |
| if (n%4 == 0){ |
| System.out.print("kabisat"); |
| } |
| else { |
| System.out.print("bukan kabisat"); |
| } |
| } |
| |
| public static void main(){ |
| int n; |
| kabisat x = new kabisat(); |
| System.out.print("masukan nilai n :"); |
| n = Input.readInt (); |
| x.kabisatproses(n); |
| } |
| |
| } |


0 komentar:
Posting Komentar