Display's user input Date month and year

"Design a class called Date that has integer data members to store month, day, and year.
The class should have a three-parameter default constructor that allows the date to be set at the time a new Date object is created. If the user creates a Date object without passing any arguments, or if any of the values passed are invalid, the default values of 1, 1, 2001 (i.e, January 1, 2001) should be used. The class should have member functions to print the date in the following formats:

3/15/2008
March 15, 2008
15 March 2008

Demonstrate the class by writing a program that uses it.

Input Validation: Only accept values between 1 and 12 for the month. Only accept values between 1 and 31 for the day. Only accept values between 1900 and 2010 for the year.

This is what i have so far but it is Giving me some errors please help me

#include <iostream>
using namespace std;


class date

{
int month;
int day;
int year;

public:

date (int month = 1, int day = 1, int year = 2001)

{

date::month = month;
date::day = day;
date::year = year;

};

void showDate();

~date(){}

};



void date::showDate(){

cout << month << "/" << day << "/" << year << endl;

}

int main()

{

int month;

int day;

int year;


string monthName[12] = {"January","February","March","April","May","June","July",

"August","September","October","November","December"};



cout << "enter month (between 1 and 12)" << endl;

cin >> month;



if (month > 12 || month < 1)

{

month = 1;

}

cout << "enter day (between 1 and 31)" << endl;

cin >> day;


if (day > 31 || day < 1)

{

day = 1;

}

cout << "enter year (between 1900 and 2010)"<< endl;

cin >> year;

if (year > 2010 || year < 1900)

{

year = 2001;

}


date newDate(month, day, year);
newDate.showDate();
cout << monthName[month-1] << " " << day << ", " << year << endl;
cout << day << " " << monthName[month-1] << " " << year << endl;


system ("PAUSE");

return 0;

}


Giving me some errors please help me

1. you did not #include <string> and #include <cstdlib>
2. stop using system("blah-blah"); : http://www.cplusplus.com/forum/beginner/1988/
3. if there are other errors, just post it -don't make me use ESP all the time, it drains my aura :p
edit: 4. oh, and use code tags
Last edited on
Topic archived. No new replies allowed.