class bulan


gimana si caranya bikin program menampilkan bulan dan jumlah hari? begini teman-teman, langsung aja lah kita ke programnya aja biar gak bikin pusing.. silahkan dicoba ya listing program ini

#include
#include
class Bulan {
friend ostream& operator<>(istream& , Bulan&);
public:
Bulan(){};
int hari() const;
private:
int bln,thn;
};
ostream& operator<<(ostream& out , const Bulan& N){
out<<N.hari()<>(istream& in,Bulan& q){
cout<>q.bln;
cout<>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;
}

semoga berguna

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: