Timetible in C++ code

Please help me with this project...
I have to structure a school timetable in C++ code. The user has to put the day and the time and the program has to say where should the student be. The program has to say the class after that found the student should be too.
Please, tell me the code example...
Thank you...
I think you should read this first.
http://www.cplusplus.com/forum/beginner/1/
Are you willing to program this on Win32 API or just in general character mode programming.[On seeing the answer to your question I am quiet unsure of your expectation so why I am asking this question]

If not Windows I could help you with your project :)
I have a decent knowledge in general C++ I could help you.Feel free t ask me

In general programming code please...
Thank you so much 😀
Looking forward to your answer... @V07
Last edited on
My answers will be split-ted since my code is long.

Explanation of my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Classes, Timetable assumed of my own since you have not provided in your question.[\CODE]

If you want to change the classes just change it in the global variable.I did this to avoid confusion to you.

To avoid too much complexity I used strlen because different days has different length.except monday& friday + saturday and thursday for that I used simple comparison.You can refer my code.

[CODE]
OUTPUT of program:
Enter the time:
9
Enter the Day:
saturday

Programming 
Maths 

NOTE: Code is 100% working :)
Last edited on
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
//SOURCE CODE PART 1
#include<iostream>
#include<conio.h>
#include<ctime>
#include<string.h>
#include<cstring>
using namespace std;

int Time[8] = { 8,9,10,11,12,2,3,4 };
string Day[6] = { "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };
string Monday[8] = { "Physics","Chemistry","Maths","English","Programming","French","ECA","Reference" };
string Tuesday[8] = { "English","Maths","Chemistry","Physics","Reference","French","ECA","Programming" };
string Wednesday[8] = { "Physics","ECA","Maths","English","Programming","French","Chemistry","Reference" };
string Thursday[8] = { "Chemistry","Physics","Maths","English","Programming","Reference","ECA","French" };
string Friday[8] = { "Reference","Chemistry","Maths","English","Programming","French","ECA","Physics" };
string Saturday[8] = { "Physics","Programming","Maths","English","Chemistry","French","ECA","Reference" };


int time(int var1);
int main()
{
	int var1;
	int var2;
	int var3;
	cout << "Enter the Time" << endl;
	cin >> var1;
	char day[15];
	if (var1 == Time[0])
	{
		cout << "Enter the day";
		cin>>day;
		var2 = strlen(day);
        if(strlen(day)==6)
        {
            if(day[1]=='o'){
            cout<<Monday[0]<<endl;;
            cout<<Monday[1];
            }
            else
            {
                cout<<Friday[0]<<endl;
                cout<<Friday[1];
            }
        }
        if(strlen(day)==7)
        {
            cout<<Tuesday[0]<<endl;;
            cout<<Tuesday[1];

        }
         if(strlen(day)==9)
        {
            cout<<Wednesday[0]<<endl;;
            cout<<Wednesday[1];

        }
        if(strlen(day)==8)
        {
            if(day[1]=='h'){
            cout<<Thursday[0]<<endl;;
            cout<<Thursday[1];
            }
            else
            {

                cout<<Saturday[0]<<endl;
                cout<<Saturday[1];
            }
        }
	}
	if (var1 == Time[1])
	{
        		cout << "Enter the day";
		cin>>day;
		var2 = strlen(day);
        if(strlen(day)==6)
        {
            if(day[1]=='o'){
            cout<<Monday[1]<<endl;;
            cout<<Monday[2];
            }
            else
            {
                cout<<Friday[1]<<endl;
                cout<<Friday[2];
            }
        }
        if(strlen(day)==7)
        {
            cout<<Tuesday[1]<<endl;;
            cout<<Tuesday[2];

        }
         if(strlen(day)==9)
        {
            cout<<Wednesday[1]<<endl;;
            cout<<Wednesday[2];

        }
        if(strlen(day)==8)
        {
            if(day[1]=='h'){
            cout<<Thursday[1]<<endl;;
            cout<<Thursday[2];
            }
            else
            {

                cout<<Saturday[1]<<endl;
                cout<<Saturday[2];
            }
        }
	}
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
//SOURCE CODE PART II
if (var1 == Time[2])
	{
        cout << "Enter the day";
		cin>>day;
		var2 = strlen(day);
        if(strlen(day)==6)
        {
            if(day[1]=='o'){
            cout<<Monday[2]<<endl;;
            cout<<Monday[3];
            }
            else
            {
                cout<<Friday[2]<<endl;
                cout<<Friday[3];
            }
        }
        if(strlen(day)==7)
        {
            cout<<Tuesday[2]<<endl;;
            cout<<Tuesday[3];

        }
         if(strlen(day)==9)
        {
            cout<<Wednesday[2]<<endl;;
            cout<<Wednesday[3];

        }
        if(strlen(day)==8)
        {
            if(day[1]=='h'){
            cout<<Thursday[2]<<endl;;
            cout<<Thursday[3];
            }
            else
            {

                cout<<Saturday[2]<<endl;
                cout<<Saturday[3];
            }
        }
	}
	if (var1 == Time[3])
	{
         cout << "Enter the day";
		cin>>day;
		var2 = strlen(day);
        if(strlen(day)==6)
        {
            if(day[1]=='o'){
            cout<<Monday[3]<<endl;;
            cout<<Monday[4];
            }
            else
            {
                cout<<Friday[3]<<endl;
                cout<<Friday[4];
            }
        }
        if(strlen(day)==7)
        {
            cout<<Tuesday[3]<<endl;;
            cout<<Tuesday[4];

        }
         if(strlen(day)==9)
        {
            cout<<Wednesday[3]<<endl;;
            cout<<Wednesday[4];

        }
        if(strlen(day)==8)
        {
            if(day[1]=='h'){
            cout<<Thursday[3]<<endl;;
            cout<<Thursday[4];
            }
            else
            {

                cout<<Saturday[3]<<endl;
                cout<<Saturday[4];
            }
        }
	}
	if (var1 == Time[4])
	{
        cout << "Enter the day";
		cin>>day;
		var2 = strlen(day);
        if(strlen(day)==6)
        {
            if(day[1]=='o'){
            cout<<Monday[4]<<endl;;
            cout<<Monday[5];
            }
            else
            {
                cout<<Friday[4]<<endl;
                cout<<Friday[5];
            }
        }
        if(strlen(day)==7)
        {
            cout<<Tuesday[4]<<endl;;
            cout<<Tuesday[5];

        }
         if(strlen(day)==9)
        {
            cout<<Wednesday[4]<<endl;;
            cout<<Wednesday[5];

        }
        if(strlen(day)==8)
        {
            if(day[1]=='h'){
            cout<<Thursday[4]<<endl;;
            cout<<Thursday[5];
            }
            else
            {

                cout<<Saturday[4]<<endl;
                cout<<Saturday[5];
            }
        }
	}
	if (var1 == Time[5])
	{
         cout << "Enter the day";
		cin>>day;
		var2 = strlen(day);
        if(strlen(day)==6)
        {
            if(day[1]=='o'){
            cout<<Monday[5]<<endl;;
            cout<<Monday[6];
            }
            else
            {
                cout<<Friday[5]<<endl;
                cout<<Friday[6];
            }
        }
        if(strlen(day)==7)
        {
            cout<<Tuesday[5]<<endl;;
            cout<<Tuesday[6];

        }
         if(strlen(day)==9)
        {
            cout<<Wednesday[5]<<endl;;
            cout<<Wednesday[6];

        }
        if(strlen(day)==8)
        {
            if(day[1]=='h'){
            cout<<Thursday[5]<<endl;;
            cout<<Thursday[6];
            }
            else
            {

                cout<<Saturday[5]<<endl;
                cout<<Saturday[6];
            }
        }
	}
	if (var1 == Time[6])
	{
        cout << "Enter the day";
		cin>>day;
		var2 = strlen(day);
        if(strlen(day)==6)
        {
            if(day[1]=='o'){
            cout<<Monday[6]<<endl;;
            cout<<Monday[7];
            }
            else
            {
                cout<<Friday[6]<<endl;
                cout<<Friday[7];
            }
        }
        if(strlen(day)==7)
        {
            cout<<Tuesday[6]<<endl;;
            cout<<Tuesday[7];

        }
         if(strlen(day)==9)
        {
            cout<<Wednesday[6]<<endl;;
            cout<<Wednesday[7];

        }
        if(strlen(day)==8)
        {
            if(day[1]=='h'){
            cout<<Thursday[6]<<endl;;
            cout<<Thursday[7];
            }
            else
            {

                cout<<Saturday[6]<<endl;
                cout<<Saturday[7];
            }
        }
	}
	if (var1 == Time[7])
	{
           cout << "Enter the day";
		cin>>day;
		var2 = strlen(day);
        if(strlen(day)==6)
        {
            if(day[1]=='o'){
            cout<<Monday[7]<<endl;;
            cout<<Monday[8];
            }
            else
            {
                cout<<Friday[7]<<endl;
                cout<<Friday[8];
            }
        }
        if(strlen(day)==7)
        {
            cout<<Tuesday[7]<<endl;;
            cout<<Tuesday[8];

        }
         if(strlen(day)==9)
        {
            cout<<Wednesday[7]<<endl;;
            cout<<Wednesday[8];

        }
        if(strlen(day)==8)
        {
            if(day[1]=='h'){
            cout<<Thursday[7]<<endl;;
            cout<<Thursday[8];
            }
            else
            {

                cout<<Saturday[7]<<endl;
                cout<<Saturday[8];
            }
        }
	}
	if (var1 == Time[8])
	{
        cout << "Enter the day";
		cin>>day;
		var2 = strlen(day);
        if(strlen(day)==6)
        {
            if(day[1]=='o'){
            cout<<Monday[8]<<endl;;
            cout<<Monday[8];
            }
            else
            {
                cout<<Friday[8]<<endl;
                cout<<Friday[8];
            }
        }
        if(strlen(day)==7)
        {
            cout<<Tuesday[8]<<endl;;
            cout<<Tuesday[8];

        }
         if(strlen(day)==9)
        {
            cout<<Wednesday[8]<<endl;;
            cout<<Wednesday[8];

        }
        if(strlen(day)==8)
        {
            if(day[1]=='h'){
            cout<<Thursday[8]<<endl;;
            cout<<Thursday[8];
            }
            else
            {

                cout<<Saturday[8]<<endl;
                cout<<Saturday[8];
            }
        }
	}

	getch();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Sunday is considered to be a holiday

//12 to 1 is considered to be a break

/*
My assumption on classes
class1 : Physics
class2 : Chemistry
class3 : Maths
class4 : English
class5 : Programming class
class6 : French
class7 : Extra Curricular Activitiies (ECA) this includes games, sports etc.,
class8 : Reference class which include library, discussion, etc.,
*/
A hundred times thank you!
You're very kind...
Wish you all the best! 😃
Wow - that code seems horrendously long. Something needs a rethink, I'd suggest.
@Chervil
Thank you for your suggestion

Of course this can be done using functions,(Structures which I did prefer to create the whole student database) but here are my considerations,

1. Though this code is big but not complex so a beginner can digest easily.
2. He have not added enough details in his questions like when will the classes get started, ends when will be the lunch break, or one sitting classes(Till the noon), Subjects(How many and what).
For solving this I have made several global variables by changing the subjects and time the entire program gets changed according to his wish.
If I have did something like this in function and looping statements then he needs to change almost all to make the program to work according to his wish.

Still there is a way kindly suggest me so that I can change it ! :)
Kindly excuse my bad English :)
Cheers,
V07
I didn't thoroughly check this, it may contain bugs. However, based on your data tables, this might be an alternative way of thinking of things:
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
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;

int Time[8] = { 8,9,10,11,12,2,3,4 };
string Day[6] = { "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };

string Monday[8] = { "Physics","Chemistry","Maths","English","Programming","French","ECA","Reference" };
string Tuesday[8] = { "English","Maths","Chemistry","Physics","Reference","French","ECA","Programming" };
string Wednesday[8] = { "Physics","ECA","Maths","English","Programming","French","Chemistry","Reference" };
string Thursday[8] = { "Chemistry","Physics","Maths","English","Programming","Reference","ECA","French" };
string Friday[8] = { "Reference","Chemistry","Maths","English","Programming","French","ECA","Physics" };
string Saturday[8] = { "Physics","Programming","Maths","English","Chemistry","French","ECA","Reference" };

int main()
{
    int time;
    string day;

    cout << "Enter the Time" << endl;
    cin  >> time;

    cout << "Enter the day";
    cin  >> day;


    bool foundday = false;
    bool foundtime = false;
    int timesub = 0;
    int daysub  = 0;

    for (timesub = 0; timesub < 8; timesub++)
    {
        if (Time[timesub] == time)
        {
            foundtime = true;
            break;
        }
    }

    for (daysub = 0; daysub < 6; daysub++)
    {
        if (Day[daysub] == day)
        {
            foundday = true;
            break;
        }
    }

    if (!foundday || !foundtime)
    {
        cout << "no activity found for that time and day\n";
        getch();
        return 0;
    }

    string activity;
    string next;

    switch (daysub)
    {
        case 0: activity = Monday   [timesub]; if (timesub < 7) next = Monday   [timesub+1]; break;
        case 1: activity = Tuesday  [timesub]; if (timesub < 7) next = Tuesday  [timesub+1]; break;
        case 2: activity = Wednesday[timesub]; if (timesub < 7) next = Wednesday[timesub+1]; break;
        case 3: activity = Thursday [timesub]; if (timesub < 7) next = Thursday [timesub+1]; break;
        case 4: activity = Friday   [timesub]; if (timesub < 7) next = Friday   [timesub+1]; break;
        case 5: activity = Saturday [timesub]; if (timesub < 7) next = Saturday [timesub+1]; break;
        default: activity = "Day Not found";   break;
    }

    cout << activity << "  " << next << '\n';

    getch();
}

I post this as part of the discussion of ideas, not necessarily as a recommendation.
Last edited on
@Chervil,
Thank you
Simple checking by building an executable would give that the program is is not giving output to any of the inputs but as you mentioned above in your reply(This may contain bugs) so I am not going to speak about it.

I am here to ask you a little question on seeing a glance at your code,

Consider The output of your program,
Enter the Time:
9
Enter the Day:
_ //--------------------------Here is my doubt

My doubt is everyone has their own style of entering a data
some will type monday some MONDAY and some Monday some may with a small typo mondty and so on will your code satisfies it? I mean will understand the user and give the out put

If not how will you do that? :)

I will use this little trick:
Though there are many styles to type "Monday" like MONDAY or monday all have the same length 6 so compare values using length.
I will make use of arrays and nested if's(in some cases) if some words has the same length.

Thank you for sharing your ideas with me
Last edited on
Simple checking by building an executable would give that the program is is not giving output to any of the inputs but as you mentioned above in your reply(This may contain bugs) so I am not going to speak about it.

It's true that I barely tested the code. But it did work for me.
See link:
https://ideone.com/ZcoorW

Note: for the version on ideone I removed conio.h and getch(), that's all.

I'm wondering which compiler you are using. That might be a reason for the difference.


everyone has their own style of entering a data
some will type monday some MONDAY and some Monday some may with a small typo mondty and so on will your code satisfies it?

Currently, no. The user must type the day exactly, including uppercase first letter.

How would I deal with it?
A first thought might be to convert all strings to lowercase before starting to compare. If the user were to type "mondty", one possibility is to ask for the day to be entered again. Another idea is to ask for only the first three letters, "mon", "tue", "wed" etc. The user may still make a typo, but it is a little easier. Or one might ask the user to select from a menu, where each day is given a number from 1 to 7, and then the user must type just a single character. The less typing the better, and the user will be less irritated if they do happen to make an error.

My personal opinion, testing the length of the name, though workable, is counter-intuitive, and I would prefer a more direct approach.


@Chervil
Sorry for the bad English
In my compiler also the executable works but when entering the day it gives the same output like this,
because I entered 11 monday
no activity found for that time and day

so why I have asked your opinion in entering the day.


Though my code using strlen works 100% as expected by the inquirer it is not possible for big projects so I asked your suggestion from your expirence.


Thank you for your opinion
Last edited on
Though my code using strlen works 100% as expected by the inquirer

Does it? It doesn't really behave as I expect if I enter sunday... or tomorrow or 123456 or any number of other things.
@ cire,
I have already mentioned that in my answer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2. He have not added enough details in his questions like when will the classes get started, ends when will be the lunch break, or one sitting classes(Till the noon), Subjects(How many and what).
For solving this I have made several global variables by changing the subjects and time the entire program gets changed according to his wish.
If I have did something like this in function and looping statements then he needs to change almost all to make the program to work according to his wish.
[\CODE]

School means it has a holiday since he didn't say which day is holiday I assumed it as sunday.He have not even mentioned the school timings so my own.

This in my code expains that stuffs:
[CODE]
//Sunday is considered to be a holiday

//12 to 1 is considered to be a break

/*
My assumption on classes
class1 : Physics
class2 : Chemistry
class3 : Maths
class4 : English
class5 : Programming class
class6 : French
class7 : Extra Curricular Activitiies (ECA) this includes games, sports etc.,
class8 : Reference class which include library, discussion, etc.,
*/ 

So it works according to his question.If any concerns please clarify me
Thank you for testing my program :) @cire
@ cire,
I have already mentioned that in my answer

The fact that you mentioned (one of) them in your answer has no bearing on the fact that the program doesn't behave as one might expect when entering things that are unexpected by the program. Such was the basis of the justification of your approach over Chervil's.

Personally, I would rather have something fail spectacularly than quietly give me Monday's schedule when I asked for Sunday's, or misspelled Monday and it quietly gave me Friday's.
@ cire,

As far as I understood your English(Because my English is bad)
you have spotted two bugs

Bug 1 : Monday's schedule when I asked for Sunday's.

This occurs because because both monday and sunday have same length 6.
Generally speaking, a student should know sunday is a holiday.But technically it is my mistake
Here is an update:

1
2
3
4
5
6
7
8
9
10
11
12
 if(day[1]=='o'){
            cout<<Monday[0]<<endl;;
            cout<<Monday[1];
            }
            if(day[1]=='r')
            {
                cout<<Friday[0]<<endl;
                cout<<Friday[1];
            }
            else{
                cout<<"Sunday is a holiday"<<endl;
            }//I am not willing to dump the entire code again.It is a small updated snippet 


Bug 2: misspelled Monday and it quietly gave me Friday's.

Well, Monday must be misspelled as Mrnday so while checking the string it will give the Friday's timetable.

I agree with you. But bug 2 is an indirect dependent on bug 1 in my code

I considered using this for the style(refer my reply to Chervil) of various students
like monday , Monday and with fewer misspells .

So my answer:
These types of bugs can be solved only by creating AI which I consider more than for a school time table or by setting default statements.

However this could increase the stability
1
2
3
4
5
6
7
8
9
  if(day[1]=='r')
            {
                if(day[2]=='i')
                {
                    cout<<Friday[0]<<endl;
                cout<<Friday[1];
                }
            else
                cout<<"Oops something went wrong"<<endl;

But these type of mistakes are rare
Thank you for bug spotting.
Any suggestions are welcome
If any concerns please clarify me

Last edited on
These types of bugs can be solved only by creating AI

My initial comment was that the code was extremely long. Now you propose fixing its defects by adding even more complexity. Seriously, the length wasn't my real meaning, is was that your code was excessively complex and unwieldy, hard to read, hard to maintain. Since it is clear that it is also flawed, it hardly adds support for sticking with that design.
Topic archived. No new replies allowed.