Click here to Skip to main content
15,174,500 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying to create a program that somehow makes a time table, for example, assign a subject to a certain classroom and say "Classroom assigned to X subject", or if it is already assigned say "This classroom is already assigned"

What I have tried:

I've already tried to make structures for classrooms, teachers and students and functions like add students, add teachers, add rooms, list, delete, etc... But I don't understand how I can associate what I've already done with the timetable that the teacher asks me to do
Updated 8-Jul-21 6:44am
jeron1 7-Jul-21 19:37pm
Can you do this on paper?

It's very unlikely that anyone here will do your homework for you. This probably won't be the only response that tells you that. In fact, by the time I finish typing this, someone might have already said it.

It's also hard to answer your question because you haven't specified much about what your program is supposed to do. We can make assumptions, but they could be wrong.

That said, it looks like you have the right ideas in mind. As far as a timetable goes, there will be many instances: one for each classroom (which teacher and subject at which time), one for each teacher (which classroom and subject at which time, with a list of the students), and one for each student (which classroom, subject, and teacher at which time). You can start making these assignments once you have a list of the teachers and the subjects that they're teaching, the students and the subjects that they're taking, and the classrooms. The classrooms and subjects may also have maximum sizes.

The general version of this is a complex problem, although you may be given assumptions that help make it easier. But in the general case, there may not even be a solution that satisfies all of the inputs, because you can't double-book a classroom, teacher, or student. Then the goal is to try to minimize the number of students who can't be scheduled for all of their subjects. (In fact, there were times when I deliberately signed up for subjects that I knew would create a scheduling conflict, knowing that the school would then be happy to let me figure out my own schedule!)

Depending on what you're expected to do, you might want to search online for articles on this problem.

EDIT: I would do this in C++, not C, because the C++ standard library provides various container classes that I'd otherwise have to implement myself.

And to show how complicated this can get, there might be a list of the subjects that each teacher can teach, so that you can also assign teachers to subjects!
This is a complicated piece of homework - it's not a trivial job to do a timetable application properly unless all school groups have the same lessons each time.
This may help - though it won't give you any usable code: ASP.NET Timetable Tutorial (C#, VB.NET, SQL Server) | DayPilot Code[^]
You must expands your structs with members of other structs, so the class room gets owner.

struct ClassRoom {
// your data
Teacher *owner; // set this value to 0 at creation

bool assign(ClaasRoom *classRoom, Teacher *teacher) {

 if( classRoom->owner != 0 ) {
   return false;// already assigned
 // you need some memory managment here
  classRoom->owner = teacher;
 return true;

But my best guess is that every ClassRoom may have an array for the timetable, so this function needs some additional parameter for which Course it is. I would use an index for it,and the Teacher belongs to the Course.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900