-3

The problem tells me:

"The class should have member functions to print the date in the following format"

  • 3/15/13 //showShortDate
  • March 13, 2013 //showLongDate
  • 15 March, 2013 //showEuroDate

The following in the function implementation file will not compile and give a "cout : undeclared identifier" error. I have #include <iostream> in the main program .cpp file.

// Date.cpp is the Date class function implementation file

    #include "Date.h"


    Date::Date(int m, int d, int y)
    {  month = m;
       day = d;
       year = y;
    }

    Date::Date()
    {
      month = 1;
      day = 1;
      year = 2001;      
    }


    void Date::showShortDate()
    {
      cout << month << "/" << day << "/" << year;
    }
    void Date::showLongDate()
    {
       cout << month << " " << day << ", " << year;

    }
    void Date::showEuroDate()
    {
       cout << day << " " << month << " " << year;
    }
RufioLJ
  • 427
  • 1
  • 6
  • 12
  • Argh, I've dupe-closed the question, but the linked stuff was wrong wrt this. Sorry. Now someone else needs to close-vote this for it lacks basic research. – Sebastian Mach Nov 07 '14 at 09:49

1 Answers1

2

Change it to:

void Date::showShortDate()
{
  std::cout << month << "/" << day << "/" << year;
}
void Date::showLongDate()
{
   std::cout << month << " " << day << ", " << year;

}
void Date::showEuroDate()
{
   std::cout << day << " " << month << " " << year;
}

Or do using namespace std; which i don't recommend.

include also in case you don't have already: #include <iostream>

Basically there are standard functions in C++ which are defined within a namespace. That namespace is std if you want to access these functions you need to tell the compiler where these functions come from. You do that by adding std:: in front of the function. Or by telling it to use the std namespace ( again not recommended ).


Read this to understand the basic idea behind a namespace.

deW1
  • 5,562
  • 10
  • 38
  • 54