trouble compiling class object code

I have been working on the following program for days, most the time i have spent trying and failing to get my code to compile, my code is as follows

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

#ifndef TIME_H
#define TIME_H

class Time
{
   public:

      Time(int theHour, int theMin, int theSec);
      Time(int theHour, int theMin);
      Time(void);
      void setMinute(int theMinute);
      void setHour(int theHour);
      void setSecond(int theSecond);
      void addSeconds(int seconds2Add);
      void addMinutes(int minutes2Add);

      int  addHours(int hours2Add);

      void displayMilitaryTime(bool displaySeconds = false);

      void promptForTime(string prompt, bool readSeconds = false);

      Time operator + (Time time1);                           


      bool operator < (Time time1);
      bool operator > (Time time1);
      bool operator == (Time time1);
      bool operator <= (Time time1);
      bool operator >= (Time time1);

      friend ostream& operator << (ostream &out, const Time &time1);

      friend istream& operator >> (istream &in, Time &time1);

   private:
      int hour;
      int minute;
      int second;
};
#endif

int main (void)
{
   const bool DISPLAY_SECONDS = true;
   const bool READ_SECONDS = true;

   int hourInput;
   int minInput;
   int secInput;

   Time time1;
   cout << "\nTime1 = " << time1;
   Time time2(8,10);
   cout << "\nTime2 = " << time2; 
   time2.promptForTime("\nChange Time2 (hh:mm): ");

   Time time3(12,30,15);
   time3.promptForTime("Enter Time3 (hh:mm:ss): ",READ_SECONDS);

   Time time4;
   cout << "Enter Time4 (hh:mm): ";
   cin >> time4;

   cout << "\nTime1 = ";
   time1.displayMilitaryTime(DISPLAY_SECONDS);
   cout << "\nTime2 = ";
   time2.displayMilitaryTime(DISPLAY_SECONDS);
   cout << "\nTime3 = ";
   time3.displayMilitaryTime(DISPLAY_SECONDS);
   cout << "\nTime4 = ";
   time4.displayMilitaryTime();

   Time time5(8,0);
   cout << "\nTime5 = ";
   cout << time5;
   cout << endl << endl;

   cout << "Adding Time1 to Time2" << endl;
   time5 = time1 + time2;
   cout << time1 << " + " << time2 << " = " << time5 << endl;

   cout << "Adding Time3 to Time4" << endl;
   time5 = time3 + time4;
   cout << time3 << " + " << time4 << " = " << time5 << endl;
   
   cout << "\nTime5 = ";
   time5.displayMilitaryTime(DISPLAY_SECONDS);

   cout << "\nNow let's add to Time5\n";
   
   secInput = getInt("\nNumber of seconds to add: ","Invalid Seconds value!");
   time5.addSeconds(secInput);
   cout << "Adding " << secInput << " seconds to Time5 = ";
   time5.displayMilitaryTime(DISPLAY_SECONDS);

   minInput = getInt("\nNumber of minutes to add: ","Invalid Minutes value!");
   time5.addMinutes(minInput);
   cout << "Adding " << minInput << " minutes to Time5 = ";
   time5.displayMilitaryTime(DISPLAY_SECONDS);

   hourInput = getInt("\nNumber of hours to add: ","Invalid hours value!");
   int day = time5.addHours(hourInput);
   cout << "Adding " << hourInput << " hours to Time5 = ";
   time5.displayMilitaryTime(DISPLAY_SECONDS);
   cout << "\nDays carried over: " << day << endl;
   cout << endl;
  
   if (time1 < time2)
   {
      cout << time1 << " is less than " << time2 << endl;
   }

   if (time1 > time2)
   {
      cout << time1 << " is greater than " << time2 << endl;
   }
   
   if (time2 == time3)
   {
      cout << time2 << " is equal " << time3 << endl;
   }
   
   if (time3 <= time4)
   {
      cout << time3 << " is less or equal to " << time4 << endl;
   }
   
   if (time4 >= time5)
   {
      cout << time4 << " is greater or equal to " << time5 << endl;
   }

   Time time6(7,40,35);
   Time time7(9,20,40);
   if (time6 < time7)
   {
      time6.displayMilitaryTime(DISPLAY_SECONDS);
      cout << " is less than ";
      time7.displayMilitaryTime(DISPLAY_SECONDS);
      cout << endl;
   }
   else
   {
      time6.displayMilitaryTime(DISPLAY_SECONDS);
      cout << " is greater or equal to ";
      time7.displayMilitaryTime(DISPLAY_SECONDS);
      cout << endl;
   }

   time6 = Time(8,30,15);
   time7 = Time(8,20,15);
   if (time6 <= time7)
   {
      time6.displayMilitaryTime(DISPLAY_SECONDS);

      cout << " is less than or equal ";
      time7.displayMilitaryTime(DISPLAY_SECONDS);
      cout << endl;
   }
   else
   {
      time6.displayMilitaryTime(DISPLAY_SECONDS);
      cout << " is greater than ";
      time7.displayMilitaryTime(DISPLAY_SECONDS);
      cout << endl;
   }

   return 0;
}

int getInt(string prompt, string errMsg = "\nValue must be an integer!\n")
{
   int temp;
   cout << "enter interger value";
   cin temp;
   if (cin.fail())
   {
      cin.ignore();
      cin.clear();
      cout << errMsg;
   }
   return temp;
}

Time::Time(int theHour, int theMin, int theSec)
{
   cin >> hour >> min;
}

Time::Time(int theHour, int theMin)
{
   cin >> hour >> min;
}

Time::Time(void)
{
   cin >> hour >> min >> second;
}

void Time::setMinute(int theMinute)
{
   minute = minute % 60;
}

void Time::setHour(int theHour)
{
   hour = hour % 24;
}

void Time::setSecond(int theSecond)
{
   second = second % 60;
}

void Time::addSeconds(int seconds2Add)
{
   seconds2Add = second / 60;
   return seconds2Add;
}

void Time::addMinutes(int minutes2Add)
{
   minutes2Add = minute / 60;
   return minutes2Add;
}


int Time::addHours(int hours2Add)
{
   hours2Add = hours / 24;
   return hours2Add;
}

void Time::displayMilitaryTime(bool displaySeconds)
{
   if (displaySeconds == true)
   {
      time1.addSeconds;
      time1.setSecond;
   }
   time1.addMinutes;
   time1.setMinute;
   time1.addHours;
   time1.setHour;
   cout << hour << min;
   if (displaySeconds == true)
      cout << second << endl;
   else
      cout << endl;
}


void Time::promptForTime(string prompt, bool readSeconds)
{
   cout << prompt;
}

Time::operator + (Time time1)
     {
        time5(second) = time1(second) + time2(second);
        if (second > 59)
        {
           time5(min) = time5(min) + time5(second) / 60;
           time5(second) = time5(second) % 60;
        }
        time5(min) = time1(min) + time2(min);
        if (min > 59)
        {
           time5(hour) = time5(hour) + time5(min) / 60;
           time5(min) = time5(min) % 60;
        }   
     }

bool Time::operator < (Time time1)
  {
     if (time1(hour) < time2(hour))
        return true;
     if (time1(hour) > time2(hour))
        return false;
     if (time1(hour) == time2(hour))
     {
        if (time1(min) < time2(min))
           return true;
        if (time1(min) > time2(min))
           return false;
        if (time1(min) == time2(min))
        {
           if (time1(second) < time2(second))
              return true;
           if (time1(second) > time2(second))
              return false;
           if (time1(second) == time2(second))
              return false;
        }
     }
  }
   bool Time::operator > (Time time1)
   {
     if (time1(hour) > time2(hour))
        return true;
     if (time1(hour) < time2(hour))
        return false;
     if (time1(hour) == time2(hour))
     {
        if (time1(min) > time2(min))
           return true;
        if (time1(min) < time2(min))
           return false;
        if (time1(min) == time2(min))
        {
           if (time1(second) > time2(second))
              return true;
           if (time1(second) < time2(second))
              return false;
           if (time1(second) == time2(second))
              return false;
        }
     }
   }


and my compile errors are the following, it seems like everytime i tried to fix an error five more popped up in it's place, i am very new to classes and i am sitting on the very edge of my breaking point, i don't need help getting rid of every compile error, i just need some advice on how to remove the larger ones and then i believe i can fix the rest on my own. due to limits i can't post the compile summary, comments, or a few of the operator functions, but most of the code is there. the last part of the compile errors i believe i don't need any advice on.
Last edited on
Ok, not using [ code ] tags is one thing, but having everything at half the size really makes it impossible to read anything.
Yes can you please use [code] tags.
Just highlight all your code and click the <> button to the right of the text box.
When you post it it should be in the right format.
Last edited on
I believe one problem would be not separating the parameters in your operator overloads.
bool Time::operator > (Time time1)

should be

bool Time::operator > (Time, time1)

I'm also not sure if the parameters you passed in are correct either. I'm new to operator overloading, but I believe it should look like:

bool Time::operator > (const Time& [value1], const Time& [value2])

Look into declaring const with overloading operators and what arguments to use.

Also your errors aren't showing up, try posting them again. Someone who is more knowledgeable should be able to help.
Topic archived. No new replies allowed.