increment/decrement operators

I can't seem to figure my code below to work.

I have two files NumDays.h and ClientProgram.cpp

clientprogram.cpp basically has the main module below
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
56
57
58
59
60
61
62
63
64
65
66
   int main()          
{
	// Initialized UDT object Declarations
	NumDays hoursWorked_John;       // Instantiate with Default Constructor
	NumDays hoursWorked_Sue(36.9);  // Instantiate with Initializing Constructor
	NumDays hoursUsed_Sue(4.5);     // Instantiate with Initializing Constructor


	// Describe the Project Assignment to the User
	cout << "                 PROG-113: Project #3\n"
		 << "                    Class: NumDays\n"
		 << "                 Client Test Program\n" << endl;


	cout << "John's initial hours worked: " << hoursWorked_John << endl;
	hoursWorked_John.addHours(56.78);
	cout << "  John's final hours worked: " << hoursWorked_John << endl << endl;

	cout << "Sue's hours worked: " << hoursWorked_Sue << endl;
	cout << "Total hours worked: " << (hoursWorked_John + hoursWorked_Sue)
		 << endl << endl;

	hoursWorked_Sue -= hoursUsed_Sue;
	cout << "    Sue's hours Used: " << hoursUsed_Sue << endl;
	cout << "Sue's adjusted hours: " << hoursWorked_Sue << endl;
	cout << "Adjusted Total hours: " << (hoursWorked_John + hoursWorked_Sue)
		 << endl << endl;

	cout << "Adding 39.5 hours to Sue's Used hours" << endl;
	hoursUsed_Sue.addHours(39.5);
	hoursWorked_Sue -= hoursUsed_Sue;
	cout << "    Sue's hours Used: " << hoursUsed_Sue << endl;
	cout << "Sue's adjusted hours: " << hoursWorked_Sue << endl;
	cout << "Adjusted Total hours: " << (hoursWorked_John + hoursWorked_Sue)
		 << endl << endl;

	cout << "Adding 39.5 hours to Sue's Hours Worked" << endl;
	hoursWorked_Sue.addHours(39.5);
	cout << "  Sue's adjusted Hours worked: " << hoursWorked_Sue << endl;
	cout << "Prefix increment Sue's hours worked in the display statement:" << endl;
	cout <<  "  Sue's hours worked: " << ++hoursWorked_Sue << endl;
	cout <<  "   Sue's Final hours: " << hoursWorked_Sue << endl <<endl;
	cout << "Postfix increment Sue's hours worked in the display statement:" << endl;
	cout <<  "  Sue's hours worked: " << hoursWorked_Sue++ << endl;
	cout <<  "   Sue's Final hours: " << hoursWorked_Sue << endl <<endl;

	cout << "Adding 5.67 hours to John's hours worked" << endl;
	cout << "   John's current hours worked: " << hoursWorked_John << endl;
	hoursWorked_John.addHours(5.67);
	cout << "  John's adjusted Hours worked: " << hoursWorked_John << endl;
	cout << "Prefix decrement John's hours worked in the display statement:" << endl;
	cout <<  "   John's Final hours: " << hoursWorked_John << endl;
	cout <<  "  John's hours worked: " << --hoursWorked_John << endl;
	cout << "Postfix decrement John's hours worked in the display statement:" << endl;
	cout <<  "  John's hours worked: " << hoursWorked_John-- << endl;
	cout <<  "   John's Final hours: " << hoursWorked_John << endl;


	// This prevents the Console Window from closing during debug mode
	// Note: Generally, you should not remove this code
	cin.ignore(cin.rdbuf()->in_avail());
	cout << "\nPress only the 'Enter' key to exit program: ";
	cin.get();

	return 0;
0}


below is NumDays.h

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
56
57
58
59
60
61
62
63
64
65
66
67
#include <cstdlib>
#include <iostream>
using namespace std;
 
class NumDays
{
private:
    int hoursWorked;
public:
    NumDays(int hW)
    {
        addHours(hW);
    }
    NumDays(){ addHours(0);}
    // Getters
    double getDays(){ return hoursWorked / 8.0;}
    int getHours() { return hoursWorked;}
    
    // Setters
    void addHours(int hW){ hoursWorked  = hW;}
    void setDays(double d) { addHours(8*d);}
    
    friend NumDays operator + (NumDays, NumDays);
    friend NumDays operator - (NumDays, NumDays);
    // Prefix operators
    NumDays  operator++()
    {
       ++ hoursWorked;
       return *this;
    }
    NumDays operator--()
    {
        -- hoursWorked;
        return *this;
    }
    // Postfix operators
     NumDays  operator++(int)
    {
         NumDays temp = *this;
         hoursWorked ++;
         return temp;
    }
    NumDays operator--(int)
    {
         NumDays temp = *this;
         hoursWorked --;
         return temp;
    }
};


/***********************************************
 *              operator +                     *
 ***********************************************/
NumDays operator+(NumDays a, NumDays b)
{
    return NumDays(a.hoursWorked + b.hoursWorked);
}

/***********************************************
 *              operator -                     *
 ***********************************************/
NumDays operator-(NumDays a, NumDays b)
{
    return NumDays(a.hoursWorked - b.hoursWorked);
}


I can't figure out anything to put in for NumDays.cpp so it's not there.



What the problem?
basically these kinds of errors

1>c:\users\sang\documents\visual studio 2012\projects\proj3\proj3\clientprogram.cpp(108): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'NumDays' (or there is no acceptable conversion)
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(695): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
cout << hoursWorked_John; Why did you think this would work?
Actually, ClientProgram.cpp is provided by the teacher. Only NumDays.h is mine. So you saying teacher is wrong?
Nope. I say it won't work for same reason that hoursWorked_John /= !(hoursWorked_John * hoursWorked_John) won't work: you did not defined operator << for NumDays. That what error message tells you.
Topic archived. No new replies allowed.