help with overload program

I have this program that needs to overload the increment and decrement operators to increase the date by a day and decrease the date by a day,respectively. compare the dates and stream operators for easy input and output. I had a friend helping me, but he left town for the weekend and can no longer help. I'm stuck on the part he was helping me with and do not really know where to go from here. some help would be appreciated.


here is my header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef dateType_H
#define dateType_H
  
class dateType
{
public:
    void setDate(int month, int day, int year);
      //Function to set the date.
      //The member variables dMonth, dDay, and dYear are set 
      //according to the parameters.
      //Postcondition: dMonth = month; dDay = day;
      //               dYear = year

    int getDay() const;
      //Function to return the day.
      //Postcondition: The value of dDay is returned.

    int getMonth() const;
      //Function to return the month.  
      //Postcondition: The value of dMonth is returned.

    int getYear() const;
      //Function to return the year.     
      //Postcondition: The value of dYear is returned.

      dateType operator++ ();
      dateType operator--();

    void printDate() const;
      //Function to output the date in the form mm-dd-yyyy.

    dateType(int month = 1, int day = 1, int year = 1900);
      //Constructor to set the date
      //The member variables dMonth, dDay, and dYear are set 
      //according to the parameters.
      //Postcondition: dMonth = month; dDay = day; dYear = year;
      //               If no values are specified, the default 
      //               values are used to initialize the member
      //               variables.

private:
    int dMonth; //variable to store the month
    int dDay;   //variable to store the day
    int dYear;  //variable to store the year
};
#endif 


my imp file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//Implementation file date
 
#include <iostream>
#include <fstream>
#include "dateType.h"

using namespace std;

void dateType::setDate(int month, int day, int year)
{
    dMonth = month;
    dDay = day;
    dYear = year;
}

int dateType::getDay() const 
{
    return dDay;
}

int dateType::getMonth() const 
{
    return dMonth;
}

int dateType::getYear() const 
{
    return dYear;
}
//this is the problem area at the moment
 dateType dateType::operator++(){
         dateType temp;
         temp.setDate(ge.tmonth(),get.day()+1,get.year());
         
         return dateType;
}
dateType dateType::operator--(){
         dateType temp;
         temp.setDate(getmonth(),getday()-1,getyear());
         
         return dateType;
}

void dateType::printDate() const
{
    cout << dMonth << "-" << dDay << "-" << dYear;
}

    //Constructor with parameters
dateType::dateType(int month, int day, int year) 
{ 
    dMonth = month;
    dDay = day;
    dYear = year;
}


and my main which is not really done.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <fstream>
#include <iostream>
#include "dateType.h"


using namespace std;

int main ()

{
    dateType Date(10, 26, 2012);
cout <<"The date is:" << Date <<endl;



 
 

 
 
 system ("pause");
 return 0;
 
    
}

Last edited on
I had a friend helping me, but he left town for the weekend and can no longer help. I'm stuck on the part he was helping me with and do not really know where to go from here


Are we expected to know what part your stuck on? Use code tags. Look for the <> button, and feel free to edit your original post to insert them.
i commented the part that is the problem. its in the imp file if you didnt notice.
Last edited on
Well, you can't use use setDate in operator++. setDate is expecting a valid date, and operator++ might be giving it a date that's not.

You need to consider what happens when day is the last day of the month and you increase it, and what happens when day is the last day of the month and also happens to be the last day of the year.
alright...well do i need to change it to something else i have in the program or will i need to write up something new for it? also the error i have now is that dateType does not name a type
You're missing the function declarations in the dateType class for operator++ and operator--
oops i had those both in there but must have loaded old code, my bad. I added them above, but had them in the code im working with now but still have the same error of dateType does not name a type and also now expecting ; after operator in the header file.
You should include the actual text of errors since you can't remember what the errors actually are.

In operator++ and operator -- you try to return dateType; which doesn't make sense. dateType is class name. You should return *this While we're on the subject, they should probably return a reference, but it's not terribly important at this stage.

'dateType': "illegal use of this type as an expression" is a little bit different than "dateType does not name a type"
the text or errors is "dateType does not name a type" but i do see what you mean by return dateType. when my friend was helping me he began to use *this but then changed to get since we have never used *this in my class yet. the other error is expected ; before operator on line 27 and 28
Topic archived. No new replies allowed.