diff --git a/examples/constructors.cpp b/examples/constructors.cpp new file mode 100644 index 0000000..e8b62cf --- /dev/null +++ b/examples/constructors.cpp @@ -0,0 +1,71 @@ +#include +#include +using namespace std; + +class DayOfYear +{ +private: + int month; + int day; + void testDate(); +public: + DayOfYear(int monthValue, int dayValue); + DayOfYear(int monthValue); + DayOfYear(); + + void input(); + void output(); + int getMonthNumber(); + int getDay(); +}; + +DayOfYear::DayOfYear(int monthValue, int dayValue) + : month(monthValue), day(dayValue) +{ + testDate(); +} + +DayOfYear::DayOfYear(int monthValue) + : month(monthValue), day(1) +{ + testDate(); +} + +DayOfYear::DayOfYear() + : month(1), day(1) +{} + +void DayOfYear::testDate() +{ + // + if((month < 1) || (month > 12)) + { + // + cout << "Invalid month.\n"; + } + if((day < 1) || (day > 31)) + { + // + cout << "Invalid day.\n"; + } +} + +void DayOfYear::output() +{ + string Months [] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + cout << "The month is " << Months[month-1] << " and the day is " << day; +} + +int main() +{ + DayOfYear date1(2, 21), date2(5), date3; + cout << "Initialized dates:" << endl; + date1.output(); cout << endl; + date2.output(); cout << endl; + date3.output(); cout << endl; + + date1 = DayOfYear(10, 31); + cout << "Date 1 reset to the following: " << endl; + date1.output(); cout << endl; + return 0; +} diff --git a/examples/test b/examples/test new file mode 100755 index 0000000..f0fa5c1 Binary files /dev/null and b/examples/test differ diff --git a/examples/test.cpp b/examples/test.cpp new file mode 100644 index 0000000..022cb02 --- /dev/null +++ b/examples/test.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void printSize(int array[]) +{ + // + cout << sizeof(*array) << "\n"; +} + +int main() +{ + // + int array[] = {1, 2, 3, 4, 5, 6}; + cout << sizeof(array) << "\n"; + printSize(array); + return 0; +} \ No newline at end of file