im trying to creat a class called Date that includes data members: a month, a day and a year (all type int). that have a constructor with three parameters to initialize the three data members. i have to use a set and a get function for each data member and provide a member function displaydate that displays the month, day and year in separate by foward slashes all of these asuming the users enter the correct date. could you please take a look of what i have and tell me what do i have wrong and how to correct it.? this is for tomorrow can you please help?

// Create Date class
#include <iostream>
using std::cout; 
using std::cin;
using std::endl;


// Date class definition
class Date
{
public:
    //constructor initializes month, day and year
    Date (int month, int day, int year)
    {
       setMonth (themonth)
       setDay (theday)
       setYear (theyear);
    } // end Date constructor
       
    // function that sets the month, day and year
   void setMonth( int themonth)
   {      
      Month = themonth; // store the month in the object
   }
   
   void setDay ( int theday)
   {
      Day = theday; //store the day in the object
   }
   
   void setYear ( int theyear)
   {
      Year = theyear; //store the year in the object
   }
   
   
   // function that gets the month, day and year
   int getMonth() 
   {
      return Month; // return the object's Month
   }// end function getMonth
   int getDay()
   {
      return Day; //return the object's Day
   } //end function getDay
   int getYear()
   {
      return Year; //return the object's Year
   } //end function getYear
   
   // function that displays the month, day and year
   void displayDate(int displayDate)
   {
      // this statement calls getMonth, getDay, getYear to get the date
      cout << "Enter the date" << getMonth() << getDay()<< getYear()
         << endl;
   } // end function displayDate
   
  // function main begins program execution
int main()
{
  // create Date objects
  Date month()
  Date day()
  Date year() 
  
  
  int month; // user enters the month
  int day; // user enters the day
  int year; // user enters the year
  int displayDate; // display the date in month/day/year
  
   Date myDate; // create a Date object named myDate
   
   // display initial value of Month, Day and Year
   cout << "Enter the month " << month.getMonth()
        <<"/day"<<day.getDay()
        <<"/year"<<year.getYear()
      << endl;
   cin >> "Enter the date:"// user enters the full date 
  
   system ("pause");
   return 0; // indicate successful termination
} // end main

Your code is missing closing brace and semicolon at the end of the class declaration and before main() on line 58. After correcting that you can probabably figure out how to correct the other one million errors.

In the constructor you are trying to initialize the Day, Month and Year variables to variables which do not exist. In that scope theday, themonth and theyear are not accessible. To fix that you would replace it with the parameter names given ie., day, month, year.

//constructor initializes month, day and year
    Date (int month, int day, int year)
    {
       setMonth (month); //You forgot the delimeter on this
       setDay (day);       // and this
       setYear (year);
    } // end Date constructor

With the following bit I'll point you in the direction of the C++ book that you're using to get a better understanding of the cin/cout commands.

// Why does it say enter the month? These functions display it, not retrieve it from user
   cout << "Enter the month " << month.getMonth()   
        <<"/day"<<day.getDay()
        <<"/year"<<year.getYear()
      << endl;
   cin >> "Enter the date:"// user enters the full date 
//(This doesn't take input from the ser, I'm surprised it compiles since you are trying to insert data into a string literal

This function does not require the parameter

void displayDate(int displayDate)
   {
      // this statement calls getMonth, getDay, getYear to get the date
      cout << "Enter the date" << getMonth() << getDay()<< getYear()
         << endl;
   } // end function displayDate

It can be fixed by:

void displayDate()
   {
      // this statement calls getMonth, getDay, getYear to get the date
      cout << getMonth() <<"/"<< getDay()<<"/"<< getYear() << endl;
   } // end function displayDate

You've also made three superfluous instances of the class Date which can be removed.
The set functions aren't really needed in this case since the date can be created by the constructor after input is taken.

int main()
{
  int month; // user enters the month
  int day; // user enters the day
  int year; // user enters the year
   cout<<"Enter the month:";
   cin >> month;
   cout<<"\nEnter the year:";
   cin<< year;
   cout<<"\nEnter the day:";
   cin>> day;
   
   Date Today(month, day, year);
   cout<<"Today is: ";
   Today.displayDate();

   system ("pause");
   return 0; // indicate successful termination
} // end main

There seems to be a rash of "do it for tomorrow" posts at the moment :icon_rolleyes:

There seems to be a rash of "do it for tomorrow" posts at the moment :icon_rolleyes:

I guess it's better than "Please help this was due yesterday!"

thanks for the help it was really helpful

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.