Create a program that will perform the default constructor.
#include <iostream>
#include <string>
using namespace std;
class Date {
public:
//default constructor
Date(){
day = 1;
month = 1;
year = 2000;
}
void setdate(int d , int m, int y){
day = d;
month = m;
year = y;
}
string Month(int n){
string m[12]={"January","February.","March","April","May","June","July","August",
"September","October","November","December"};
return m[n-1];
}
void show(){
cout<<day<<" "<<Month(month)<<" "<<year<<endl;
}
private:
int day;
int month;
int year;
};
int main()
{
Date myData;
myData.show();
myData.setdate(21,1,1961);
myData.show();
cout << endl;
return 0;
}
Comments
Leave a comment