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
|
//Date.cpp
#include<iostream>
#include "Date.h"
const string Date::months[12] = { "January", "Febraury", "March", "April", "May","June","July","August","September","October","November","December" };
Date::Date(int m, int d, int y) {
month = m;
day = d;
year = y;
month_name = months[month - 1];
}
Date::Date() {
month = 1;
day = 1;
year = 2001;
month_name = months[month - 1];
}
void Date::showDate1() { //This line will display the date 1/1/2001 format.
cout << month << "/" << day << "/" << year << endl;
}
void Date::showDate2() { //This line will display the date January 1, 2001 format.
cout << month_name << " " << day << ", " << year << endl;
}
void Date::showDate3() { //This line will display the date 1 January 2001 format.
cout << day << " " << month_name << " " << year << endl;
}
void Date::setDate(int m, int d, int y) { //This line will take month, day, and year as parameters and then it will set the object data member values.
month = m;
day = d;
year = y;
month_name = months[month - 1];
}
//Date.h
#include<string>
using namespace std;
class Date {
private:
int month;
int day;
int year;
string month_name;
static const string months[12];
Date(int m, int d, int y);
Date();
void showDate1();
void showDate2();
void showDate3();
void setDate(int m, int d, int y);
};
//Assignment6.cpp
#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;
}
|