Multiple Inheritance

For my computer science class we are supposed to write a program with classes that calculates how many seconds, minutes, hours, days, months and years from a given date to the current date. I am able to do one class to class conversion but I'm confused how to do multiple class conversions.
Could you post what you are working on? I don't know what you are referring to by "class conversions".
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
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<iomanip>
#include<cmath>
using namespace std;

ofstream ofs("glavin_lab17_out.txt");

string message = "ENGR CIS 2485 Converting to Julian Dates.";
string fot = "----------------------------End of Data----------------------------";
string no = "EOF MESSAGE - ";
string more = "Amanda Glavin, ";
string hardcoding = "July 28 2015, ";
string of = "Lab 17 ";
string anything = "All Done.";
string fin = "Following Instructions";
string twt = "20%";
string ten = "10%";
string hun = "100%";
string scr = "your score is ----------";
string pts = "70";
string dit = "Does It Run";
string doc = "Correct Doc's";
string frm = "Format";
string str = "Structure";
string nam = "Correct files/names";
string tot = "Total Scores";
string m = "Enter Month: ";
string d = "Enter Day: ";
string y = "Enter Year: ";
string calc = "1. Convert Gregorian Date to Julian Date.";
string over = "2. Quit.";
string select = "Enter your selection. " ;
string invalid = "That is an invalid selection. " ;
string greg = "The Gregorian Date ";
string dash = "/";
string with = " corresponds to the Julian Date ";
string jules = "The Julian Date is ";
string ttl = "|  Date   |   Seconds   |   Minutes   |   Hours   |   Days   |   Months   |   Year to Date   |";
string tt2 = "|         |      	      |             |           |          |            |                  |";
string slash = "|";
string lin = "----------------------------------------------------------------------------------------------";

void header()
{
	ofs << endl;
	ofs << more << message << endl;
	ofs << endl;

}

void title()
{
	ofs << lin << endl;
	ofs << ttl << endl;
	ofs << tt2 << endl;
	ofs << lin << endl;
}

void footer()
{
	ofs << endl;
	ofs << fot << endl;
	ofs << endl;
}

void grading()
{
	ofs << endl;
	ofs << fin << setw(8)  << twt << setw(25) << scr << endl;
	ofs << dit << setw(19) << twt << setw(25) << scr << endl;
	ofs << doc << setw(17) << ten << setw(25) << scr << endl;
	ofs << frm << setw(24) << ten << setw(25) << scr << endl;
	ofs << str << setw(21) << twt << setw(25) << scr << endl;
	ofs << nam << setw(11) << twt << setw(25) << scr << endl;
	ofs << tot << setw(18) << hun << setw(25) << scr << endl;
	ofs << of  << setw(23) << pts << setw(26) << scr << endl;
	ofs << endl;
}

void eofmsg()
{
	ofs << endl;
	ofs << no << more << hardcoding << of << anything << endl;

}

class Years;
class Months;
class Days;
class Hours;
class Minutes;
class Seconds; 

class Date
{
private:
	int month, day, year;
	long temp;
public:
	Date(int=7, int=30, int=2015);
	operator Today();
	void getDate();
};

class Years
{
private:
	int year;
	long temp;
public:
	Years(int=2015);
	operator Today();
	void getYears();
};

class Months
{
private:
	int month;
	long temp;
public:
	Months(int=7);
	operator Today();
	void getMonths();
};

class Days
{
private:
	int day;
	long temp;
public:
	Days(int=30);
	operator Today();
	void getDays();
};

class Hours
{
private:
	int hour;
	long temp;
public:
	Hours(int=12);
	operator Today();
	void getHours();
};

class Minutes
{
private:
	int minute;
	long temp;
public:
	Minutes(int=60);
	operator Today();
	void getMinutes();
};

class Seconds
{
private:
	int second;
	long temp;
public:
	Seconds(int=60);
	operator Today();
	void getSeconds();
};

class Today
{
private:
	long p;
public:
	Today (long=0);
	void showTime();
};

Date::Date(int mm, int dd, int yyyy)
{
	month = mm;
	day =  dd;
	year = yyyy;
}

Years::operator Today()
{
	int YP;

	YP = 2015 - year;
	return (Today(YP));
}

Months::operator Today()
{
	int MP;

	MP = abs(7-month);
	return (Today(MP));
}

Days::operator Today()
{
	int DP;

	DP = abs(28-day);
	return (Today(DP));
}

Hours::operator Today()
{
	int HP;

	HP = abs(12-hour);
	return (Today(HP));
}

Minutes::operator Today()
{
	int min;

	min = abs(60-min);
	return (Today(min));
}

Seconds::operator Today()
{
	int sec;

	sec = abs(60-sec);
	return (Today(sec));
}

void Years::getYears()
{
	ofs << year;
}

void Months::getMonths()
{
	ofs << month;
}

void Today::showTime()
{
	int menuSelection;
	int month, day, year;
	int quit=0;

	while (quit != 1)
	{
	
	cout << calc << endl;
	cout << over << endl;
	cout << endl;
	cout << select << endl;
	cin >> menuSelection;

	while (menuSelection < 1 || menuSelection > 3)
	{
		cout << invalid << endl;
		cin >> menuSelection;
	}
	switch (menuSelection)
	{
		case 1:
			{
				cout << m << endl;
				cin >> month;
				cout << d << endl;
				cin >> day;
				cout << y << endl;
				cin >> year;
				Date a(month, day, year);
				a.getDate();
				Today b;
				b=Today(a);
				Today c;
				c=Today(a);
				ofs << slash << setw(6) << month << dash << day << dash << year << setw(6) << slash << setw(11);
				b.showTime();
				ofs << setw(7) << slash << endl;
				break;
				cin >> menuSelection;
			}
			
		case 2:
				quit = 1;
				break;
	}
	}
}

int main()
{
	header();
	title();
	footer();
	grading();
	eofmsg();
	return 0;
}


I have to make it calculate the amount of time in years, months, days, ect. from a date I enter to the current date
Hi,

So the code doesn't do anything except print the strings you hard coded at the start ..... forgive me for asking, but you wanted help with what ? Is this a deliberate exercise in obfuscation?

Why do you go to the trouble of having all those user defined conversion constructors, when you could just have 1 class that has members for all the components of a date/time and some function/ operator that computes the difference?

In case you are not trolling, std::chrono has facilities for dealing with this stuff - or you could just calculate it manually.

This bit was cute:

ofs << no << more << hardcoding << of << anything << endl;

Have you got any reasons as to why we shouldn't report you?
Your code appears to be more complicated than it needs to be. I think you can do this with one class: Date.

Create a default constructor that sets the date to today. A second constructor takes the month/day/year.

Can you use the chrono facilities? That would make life a whole lot easier.

When computing the number of hours, minutes and seconds between dates, should those be the numbers between the same time on each of the dates?

Now here's the big question: just how accurate does your professor want these answers:
- should it account for the Gregorian change of 1582, when the day after October 4 was October 15?
- should it account for leap seconds?
- Should it account for daylight savings time? Some days have 23 hours and others have 25.

Ask your professor. I suspect that he/she wants you to ignore these details and only wants you to deal with leap years.
Ok I've changed my code so now it is:

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
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<iomanip>
#include<cmath>
using namespace std;

ofstream ofs("glavin_final_out.txt");

string message = "ENGR CIS 2485 Calaculating time to Current Date.";
string fot = "----------------------------End of Data----------------------------";
string no = "EOF MESSAGE - ";
string more = "Amanda Glavin, ";
string hardcoding = "July 30 2015, ";
string of = "Final ";
string anything = "All Done.";
string fin = "Following Instructions";
string twt = "20%";
string ten = "10%";
string hun = "100%";
string scr = "your score is ----------";
string pts = "100";
string dit = "Does It Run";
string doc = "Correct Doc's";
string frm = "Format";
string str = "Structure";
string nam = "Correct files/names";
string tot = "Total Scores";
string m = "Enter Month: ";
string d = "Enter Day: ";
string y = "Enter Year: ";
string calc = "1. Calculate time to Current Date.";
string over = "2. Quit.";
string select = "Enter your selection. " ;
string invalid = "That is an invalid selection. " ;
string dash = "/";
string ttl = "|  Date   |   Seconds   |   Minutes   |   Hours   |   Days   |   Months   |   Year to Date   |";
string tt2 = "|         |      	      |             |           |          |            |                  |";
string slash = "|";
string lin = "----------------------------------------------------------------------------------------------";

void header()
{
	ofs << endl;
	ofs << more << message << endl;
	ofs << endl;

}

void title()
{
	ofs << lin << endl;
	ofs << ttl << endl;
	ofs << tt2 << endl;
	ofs << lin << endl;
}

void footer()
{
	ofs << endl;
	ofs << fot << endl;
	ofs << endl;
}

void grading()
{
	ofs << endl;
	ofs << fin << setw(8)  << twt << setw(25) << scr << endl;
	ofs << dit << setw(19) << twt << setw(25) << scr << endl;
	ofs << doc << setw(17) << ten << setw(25) << scr << endl;
	ofs << frm << setw(24) << ten << setw(25) << scr << endl;
	ofs << str << setw(21) << twt << setw(25) << scr << endl;
	ofs << nam << setw(11) << twt << setw(25) << scr << endl;
	ofs << tot << setw(18) << hun << setw(25) << scr << endl;
	ofs << of  << setw(23) << pts << setw(26) << scr << endl;
	ofs << endl;
}

void eofmsg()
{
	ofs << endl;
	ofs << no << more << hardcoding << of << anything << endl;

}

class Today;

class Date
{
private:
	int month, day, year;
	long temp;
public:
	Date(int=7, int=30, int=2015);
	operator Today();
	void getDate();
};

class Today
{
private:
	int ye, mo;
	long da, ho, mi, se;
public:
	Today (int, int, long, long, long, long);
	void showTime();
};

Date::Date(int mm, int dd, int yyyy)
{
	month = mm;
	day =  dd;
	year = yyyy;
}

Date::operator Today()
{
	int YP, MP;
	long DP, HP, min, sec;

	YP = 2015 - year;

	MP = year * 12 + abs(7-month);

	DP = YP * 365 + MP * 31 + abs(30-day);

	HP = DP * 24;

	min = HP * 60;

	sec = min * 60;
	return (Today(YP, MP, DP, HP, min, sec));
}

void Today::showTime()
{
	ofs << slash << ye << slash << mo << slash << da << slash << ho << slash << mi << slash << se;
}

Today::Today(int nYear, int nMonth, long nDay, long nHour, long nMin, long nSec) 
{

	ye = nYear;
	mo = nMonth;
	da = nDay;
	ho = nHour;
	mi = nMin;
	se = nSec;
}

void Date::getDate()
{
	int menuSelection;
	int month, day, year;
	int quit=0;

	while (quit != 1)
	{
	
	cout << calc << endl;
	cout << over << endl;
	cout << endl;
	cout << select << endl;
	cin >> menuSelection;

	while (menuSelection < 1 || menuSelection > 3)
	{
		cout << invalid << endl;
		cin >> menuSelection;
	}
	switch (menuSelection)
	{
		case 1:
			{
				cout << m << endl;
				cin >> month;
				cout << d << endl;
				cin >> day;
				cout << y << endl;
				cin >> year;
				Date a(month, day, year);
				a.getDate();
				Today b;
				b=Today(a);
				ofs << slash << setw(6) << month << dash << day << dash << year << setw(6) << slash << setw(11);
				b.showTime();
				ofs << setw(7) << slash << endl;
				break;
				cin >> menuSelection;
			}
			
		case 2:
				quit = 1;
				break;
	}
	}
}

int main()
{
	header();
	title();
	Date a(7,30,2015);
	a.getDate();
	footer();
	grading();
	eofmsg();
	return 0;
}


But now I am getting and error that says 'Today' has no appropriate default constructor.
Never mind I figured it out!
Never mind I figured it out!


Ah good !

I hope you spotted the potential for stack overflow, and have magically fixed many other things.

Topic archived. No new replies allowed.