AIIIQ2 - system("notepad date.out"); return 0; }...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <fstream> using namespace std; class date { public: date(int d, int m, int y); void write(ostream& out); int day_number(void); int days_between(date& other); private: int day; int month; int year; }; const int DAYS[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; int main(void) { ofstream fout("date.out"); date d(12, 6, 2010); date e(14, 9, 2012); fout << "The date is "; e.write(fout); fout << endl; fout << "Days so far this year " << e.day_number() << endl; fout << "Days between "; d.write(fout); fout << " and "; e.write(fout); fout << " = " << d.days_between(e) << endl; fout.close();
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: system("notepad date.out"); return 0; } date::date(int d, int m, int y){ day=d; month=m; year=y; } void date::write(ostream& out){ out<<day<<"/"<<month<<"/"<<year; } int date::day_number(void){ int i,d (day); if(year%4==0) d++; for(i=1;i<month;i++) d=d+DAYS[i]; return d; } int date::days_between(date& other){ int d,x,y,i; if(year<=other.year){ x=year; y=other.year; d=365-day_number()+other.day_number(); } else{ x=other.year; y=year; d=365-other.day_number()+day_number(); } if(x%4==0) d=d+2; for(i=x+1;i<y;i++){ if(i%4==0) d++; d=d+365; } return d; }...
View Full Document

This note was uploaded on 02/21/2010 for the course ENGM 2282 taught by Professor Phillips during the Winter '10 term at Dalhousie.

Page1 / 2

AIIIQ2 - system("notepad date.out"); return 0; }...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online