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 93 94 95 96 97 98 99 100 101
|
#include<string>
using namespace std;
class Date {
public:
Date();
Date(int, int,int);
void showDate1(int month,int day,int year);
void showDate2(string monthName, int day, int year);
void showDate3(int day,string monthName,int year);
void setDate(int month, int day, int year);
string monthName();
private:
int month;
int day;
int year;
};
#include<string>
#include<iostream>
using namespace std;
#include "date.h"
//HW6 class implementation
Date::Date()
{
day = 1;
month = 1;
year = 2001;
}
Date::Date(int month, int day, int year)
{
day = day;
month = month;
year = year;
}
string Date::monthName()
{
if (month == 1)
return "January";
else if (month == 2)
return "February";
else if (month == 3)
return "March";
else if (month == 4)
return "April";
else if (month == 5)
return "May";
else if (month == 6)
return "June";
else if (month == 7)
return "July";
else if (month == 8)
return "August";
else if (month == 9)
return "September";
else if (month == 10)
return "October";
else if (month == 11)
return "November";
else if (month == 12)
return "December";
}
void Date:: showDate1(int month, int day, int year)
{
cout << month << "/" << day << "/" << year << endl;
}
void Date :: showDate2(string monthName, int day, int year)
{
cout << monthName << " " << day << ", " << year << endl;
}
void Date:: showDate3(int day, string monthName, int year)
{
cout << day << " " << monthName << " " << year << endl;
}
void Date:: setDate(int month, int day, int year)
{
day = day;
month = month;
year = year;
}
#include <iostream>
using namespace std;
#include "date.h"
int main()
{
Date d1;
Date d2(2, 12, 2010);
d1.showDate1();
d2.showDate2();
d1.setDate(8, 29, 1986);
d1.showDate3();
system("pause");
return 0;
}
|