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
|
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cctype>
using namespace std;
// Class declaration
class Date
{
private:
int month;
int day;
int year;
public:
Date(int = 7, int = 4, int = 2005); // constructor
void convrt(); // another constructor
void showdate(); // member function to display a date
void setdate(int, int, int); // member function to copy a date
};
// implementation section
Date::Date(int mm, int dd, int yyyy)
{
month = mm;
day = dd;
year = yyyy;
}
void Date::setdate(int mm, int dd, int yyyy)
{
month = mm;
day = dd;
year = yyyy;
return;
}
void Date:: Convrt(yyyy*10000+mm*100+dd)
{
year = int (yyyymmdd/1000.0); // extract the year
month = int ( (yyyymmdd - year * 10000.0)/100.00); // extract the month
day = int (yyyymmdd - year * 10000.0 - month * 100.0); // extract the day
}
void Date::showdate()
{
cout << "The date is ";
cout << setfill ('0')
<< setw(2) << month << '/'
<< setw(2) << day << '/'
<< setw(2) << year % 100; // extract the last 2 year digits
cout << endl;
return;
}
int main()
{
Date a, b(4, 1, 1998), c(20060515), d (12, 20, 1993); // declare FOUR objects
a.showdate(); // display object a's values
b.showdate(); // display object b's values
c.showdate(); // display object c's values
d.showdate(); // display object d's values
cout<<"\n\n\nThank You.\n\n\n";
system("PAUSE");
return EXIT_SUCCESS;
}
|