Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Timetable/Timetable.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
170 lines (165 sloc)
4.1 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string> | |
#include<time.h> | |
#include<stdlib.h> | |
using namespace std; | |
struct modules{ | |
string mod_no; | |
}; | |
struct classes{ | |
string sub; | |
}; | |
struct students{ | |
string name; | |
}; | |
struct lecturers{ | |
string name; | |
string sub[2]; //each teacher can teach a maximum of two subjects | |
}; | |
struct rooms{ | |
string room_no; | |
int capacity; | |
}; | |
struct period | |
{ | |
int period_no; | |
string mod; | |
string sub; | |
string lec; | |
string time; | |
}; | |
struct time_table | |
{ | |
string day; | |
period p[3]; | |
}; | |
string assign_mod(string,int); //to assign which module to be taught in which period | |
void assign_days(); //to assign the day of time_table struct | |
void generate(string); //to automate the generation of time table | |
void print_table(); // to print the time table | |
//initializing the structure arrays with values | |
struct modules m[8]={{"OOP1"},{"OOP2"},{"DBS1"},{"DBS2"},{"CSAL1"},{"CSAL2"},{"LAB1"},{"LAB2"}}; | |
struct classes c[4]={{"Object Oriented Programmings"},{"Computer Science Activity Led"},{"Database system"},{"C++ Lab"}}; | |
struct rooms r[4]={{"101",15},{"102",15},{"103",15},{"104",10}}; | |
struct lecturers l[3]={{"Dr Simon Billing",{"CSAL"}},{"Mr David Croft",{"OOP","LAB"}},{"Ms Diana Hintea",{"DBS"}}}; | |
struct time_table tt[5]; | |
void generate(string maj) | |
{ | |
assign_days(); | |
time_t t1; | |
srand((unsigned) time(&t1)); | |
for(int i=0;i<4;i++) //this loops assigns period no., subject, module of first four days | |
{ | |
tt[i].p[0].period_no=1; | |
tt[i].p[0].sub=maj; | |
tt[i].p[1].period_no=2; | |
tt[i].p[1].sub=c[(rand()%2)+1].sub; | |
tt[i].p[2].sub=tt[i].p[1].sub; | |
tt[i].p[2].period_no=3; | |
while(tt[i].p[2].sub==tt[i].p[1].sub) | |
{ | |
tt[i].p[2].sub=c[(rand()%2)+1].sub; | |
} | |
if(i%2==0) | |
{ | |
tt[i].p[0].mod=m[0].mod_no; | |
} | |
else | |
tt[i].p[0].mod=m[1].mod_no; | |
} | |
for(int i=0;i<2;i++) | |
{ | |
tt[4].p[i].period_no=i+1; | |
tt[4].p[i].sub=c[3].sub; | |
} | |
for(int i=0;i<5;i++) //to assign time | |
{ | |
tt[i].p[0].time="7.30 am - 9.30 am"; | |
tt[i].p[1].time="10.00 am - 12.00 pm"; | |
tt[i].p[2].time="12.30 pm - 2.30 pm"; | |
} | |
for(int i=0;i<5;i++) // to assign lecturer | |
{ | |
if(i<4) | |
{ | |
for(int j=1;j<3;j++) | |
{ | |
tt[i].p[j].mod=assign_mod(tt[i].p[j].sub,i); | |
for(int k=0;k<3;k++) | |
{ | |
if(tt[i].p[j].mod.substr(0,3)==l[k].sub[0]) | |
{ | |
tt[i].p[j].lec=l[k].name; | |
} | |
} | |
} | |
} | |
else | |
for(int j=0;j<2;j++) | |
{ | |
tt[i].p[j].mod=assign_mod(tt[i].p[j].sub,j); | |
tt[i].p[j].lec=l[1].name; | |
} | |
} | |
} | |
string assign_mod(string subj,int i) | |
{ | |
if(subj==c[1].sub) | |
{ | |
if(i%2==0) | |
return m[4].mod_no; | |
else | |
return m[5].mod_no; | |
} | |
if(subj==c[2].sub) | |
{ | |
if(i%2==0) | |
return m[2].mod_no; | |
else | |
return m[3].mod_no; | |
} | |
if(subj==c[3].sub) | |
{ | |
if(i%2==0) | |
return m[6].mod_no; | |
else | |
return m[7].mod_no; | |
} | |
} | |
void assign_days() | |
{ | |
tt[0].day="Monday"; | |
tt[1].day="Tuesday"; | |
tt[2].day="Wednesday"; | |
tt[3].day="Thursday"; | |
tt[4].day="Friday"; | |
} | |
void print_table() | |
{ | |
for(int i=0;i<5;i++) | |
{ | |
cout<<tt[i].day<<"---> "; | |
for(int j=0;j<3;j++) | |
{ | |
if(i==4&&j==2) | |
{ | |
cout<<" "; | |
} | |
else | |
cout<<tt[i].p[j].time<<" "<<tt[i].p[j].period_no<<" "<<tt[i].p[j].sub<<" "<<tt[i].p[j].mod<<" "<<tt[i].p[j].lec<<" |"; | |
} | |
cout<<"\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"; | |
} | |
} | |
int main() //driver 'main' function | |
{ | |
generate("Object Oriented Programmings"); | |
cout<<"The generated time table is printed below:\n\n"; | |
cout<<"***********************************************************************************************************************************************************************\n\n"; | |
cout<<"Day"<<"---> "<<"Time"<<" "<<"Period"<<" "<<"Subject"<<" "<<"Module"<<" "<<"Lecturer"<<" |"; | |
cout<<"Time"<<" "<<"Period"<<" "<<"Subject"<<" "<<"Module"<<" "<<"Lecturer"<<" |"; | |
cout<<"Time"<<" "<<"Period"<<" "<<"Subject"<<" "<<"Module"<<" "<<"Lecturer"<<" |\n\n"; | |
cout<<"************************************************************************************************************************************************************************\n\n"; | |
print_table(); | |
return 0; | |
} | |