Skip to content

Program memasukan bulan n tahun untuk mengetahui jumlah hari

Januari 4, 2011


#include <iostream.h>
#include <conio.h>
class Bulan {
friend ostream& operator<<(ostream& , const Bulan&);
friend istream& operator>>(istream& ,  Bulan&);
public:
Bulan(){};
int hari() const;
private:
int bln,thn;
};
ostream& operator<<(ostream& out , const Bulan& N){
out<<N.hari()<<endl;
return out;
}
istream& operator>>(istream& in,Bulan& q){
cout<<“Masukkan bulan : “;in>>q.bln;
cout<<“Masukkan tahun : “;in>>q.thn;
return in; }
int Bulan::hari() const{
int h;
switch(bln) {
case 1: h = 31; break;
case 2: if ((thn%4==0&&thn%100!=0)||thn%400==0) h=29; else h=28; break;
case 3: h = 31;break;
case 4: h = 30;break;
case 5: h = 31;break;
case 6: h = 30;break;
case 7: h = 31;break;
case 8: h = 31;break;
case 9: h = 30;break;
case 10:h = 31;break;
case 11:h = 30;break;
case 12:h = 31;break;
default:h = 0;break;
}
return h;
}
void main(){
Bulan n;
cin>>n;
cout<<“Jumlah harinya adalah “<<n.hari()<<endl;
getch();
return;
}


From → Latihan

Tinggalkan sebuah Komentar

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: