twitter

Within a year the number of days is 365-366 days depending on the year. When theleap year day is the amount of 366 days if no number of days is 365 days. But what if the count input the date, month and year is different. For example:
The first input: 12-12-1990
Put the two: 2-2-2004
To better understand the program consider the following:


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

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

public :
jumlah_hari();
void hitung_hari(){
a=(th_akhr-th_awal)*365;
b=(bln_akhr-bln_awal)*30;
c=(tggl_akhr-tggl_awal)+1;
jumlah=a+b+c;
};

private :
int tggl_awal, bln_awal, th_awal;
int tggl_akhr, bln_akhr, th_akhr;
int a,b,c,jumlah;
};

jumlah_hari::jumlah_hari(){
cout<<"menghitung jumlah hari dari dua tanggal berbeda\n"<<endl;
}

istream& operator>>(istream& cin, jumlah_hari& msk){
cout<<"tanggal awal : ";
cin>>msk.tggl_awal;
cout<<"bulan awal   : ";
cin>>msk.bln_awal;
cout<<"tahun awal   : ";
cin>>msk.th_awal;
cout<<endl;
cout<<"tanggal akhir : ";
cin>>msk.tggl_akhr;
cout<<"bulan akhir   : ";
cin>>msk.bln_akhr;
cout<<"tahun akhir   : ";
cin>>msk.th_akhr;
return cin;
}

ostream& operator<<(ostream& out, const jumlah_hari& metu){
out<<"\njumlah hari dari dua tanggal tersebut adalah : "<<metu.jumlah<<endl;
}

void main(){
jumlah_hari A;
cin>>A;
A.hitung_hari();
cout<<A;
getch();
}


Running Result :



Jumat, 08 Juli 2011 | 0 komentar | Label: