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
|
//date.cpp
#include <iostream>
using namespace std;
#include "date.h"
Date::Date(int m, int d, int y)
{
if(m<=12 && d<= 31 && y<=2500)
{
mth=m,day=d,yr=y;
}
else
{
mth = 0;
day = 0;
yr =1000;
}
};
void Date::printDate()
{
cout<<mth<<"/"<<day<<"/"<<yr<<endl;
}
//test.cpp
/* Insert any #include directives you need here*/
#include <iostream>
using namespace std;
#include "date.h"
void setDateValues (int&, int&, int&);
int main()
{
int mth, day, yr;
setDateValues (mth, day, yr);
/* Create a Date instance from the user input here*/
Date day1(int mth,int day,int yr);
cout << "Date is:"<<endl;
/* Call your print function 3 separate times to test print the date in each of 3 formats */
void day1.printDate();
}
// SetDateValues obtains the user input in this test driver -- NOT in the Date class
// implementation file
void setDateValues (int& m, int& d, int& y)
{
cout << "Enter month: ";
cin >> m;
cout << "Enter day: ";
cin >> d;
cout << "Enter year: ";
cin >> y;
}
//date.h
#include <string>
using namespace std;
class Date {
private:
int mth, day, yr;
public:
Date(int,int,int);
void printDate();
};
|