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 86 87 88 89 90 91 92
|
#include <iostream>
using namespace std;
class Date {
void set(int y, int m, int d);
int get_year;
int get_month;
int get_day;
Date();
Date(int y, int m, int d);
void print();
Date plus(int num);
};
***********************************************
#include "date.h"
Date::Date() //default constructor
{
day = 1;
month = 1;
year = 1900;
}
Date::Date(int Month, int Day, int Year) // construct from month/day/year
{
month = Month;
day = Day;
year = Year;
}
void Date::setDay(int d)
{
day = d;
}
void Date::setMonth(int m)
{
month = m;
}
void Date::setYear(int y)
{
year = y;
}
int Date::getDay() const
{
return day;
}
int Date::getMonth() const
{
return month;
}
int Date::getYear() const
{
return year;
}
void Date::print() const
{
if (year < 10) cout <<'0';
cout << year << ",";
if (month < 10) cout <<'0';
cout << month << ",";
if (day < 10) cout <<'0';
cout << day << "." << endl;
}
*******************************************************
#include "date.h"
int main()
{
Date begin;
Date check_in;
int y, m, d;
begin.set (0, 0, 0);
cout << "Please enter Year, Month, and Day: ";
cin >>y>>m>>d;
check_in.set (y, m, d);
cout << "You have entered: ";
check_in.print();
return 0;
}
|