C++ codes - Date
main.cpp
#include "Date.h"
int main()
{
date d;
int a;
int b;
int c;
d.displayDate();
cout<<"\nEnter Value for month: ";
cin>>b;
cout<<"Enter Value for day: ";
cin>>a;
cout<<"Enter Value for year: ";
cin>>c;
d.setDate(a,b,c);
d.displayDate();
getch();
return 0;
}
Date.h
#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
class date
{
public:
date()
{
day=1;
month=1;
year=1990;
}
void setDate(int a, int b, int c)
{
day=a;
year=c;
if(b>0&&b<13)
{
month=b;
}
else
{
month=1;
}
}
string getDate()
{
char bluff[10], temp[10]={’\0′};
itoa(month, bluff, 10);
strcat(temp, bluff);
strcat(temp, "\\");
itoa(day, bluff, 10);
strcat(temp, bluff);
strcat(temp, "\\");
itoa(year, bluff, 10);
strcat(temp, bluff);
return temp;
}
void displayDate()
{
cout<<endl<<getDate();
}
private:
int day;
int month;
int year;
};


