1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <iostream>
#include <string>
using namespace std;
class Date{
private:
unsigned day;
unsigned month;
string monthName;
unsigned year;
public:
Date();
Date(unsigned m, unsigned d, unsigned y);
Date(const string &mn, unsigned d, unsigned y);
void printNumeric() const;
void printAlpha() const;
private:
bool isLeap(unsigned) const;
unsigned daysPerMonth(unsigned m, unsigned y) const;
string name(unsigned m) const;
unsigned number(const string &mn) const;
};
Date::Date (){
day = 1;
month = 1;
monthName = "January";
year = 2000;
}
Date::Date(unsigned m, unsigned d, unsigned y){
month = m;
day = d;
year = y;
}
Date::Date(const string &mn, unsigned d, unsigned y){
monthName = mn;
day = d;
year = y;
}
bool Date::isLeap(unsigned year) const{
int x;
if ( (year % 4) == 0){
x = 5;
if ( (year % 100) == 0){
x = 0;
if ( (year % 400) == 0)
x = 5;
}
}
if ( x == 5 )
return true;
else
return false;
}
void Date::printNumeric() const{
cout << month << "/" << day << "/" << year;
}
void Date::printAlpha() const{
cout << monthName << " " << day << ", " << year;
}
int main(){
Date today, tomorrow(11,16,1994), yesterday("November",16,1994);
today.printNumeric();
cout << "\n";
today.printAlpha();
cout << "\n";
tomorrow.printNumeric();
cout << "\n";
yesterday.printAlpha();
cout << "\n";
//This is the piece I'm having trouble with
//How do I make use of my bool class function to check for leap years?
yesterday.isLeap(1994);
cout << "\n";
//If what I'm attempting to do looks stupid it's because I have no idea how
//to make this work
}
|