Waste less time on Facebook — follow Brilliant.
×

Debug my program : Solution unknown

I got a problem in which i have to assign 6 subject and 12 teachers to 6 sections on condition where -

Every class should study different subject for particular hour.

Lunch will be between 12-3, and each section is provided with 1 hr gap.

No teacher can take more than three lecture in a day

I designed the solution but after certain value of subject it repeats the subject, while the teacher code is work perfectly Can you find the bug -

// * SECTION ASSIGNING FUNCTION *

int timetable::assign() {

int i=0,j,k,c;
if(cop==0)                                                                       // IF SECTION ==NULL
{
                 section[i].name=sec_code[i];
                 for(j=i,k=0;k<6 && sub_code[j]<=205;j++,k++)                     // CONDITION1
                 {
                                        section[i].subject[k]=sub_code[j];
                                        if(fac_code[j].coun<3)                    // CONDITION 3
                                        {
                                                section[i].faculty[k]=fac_code[j].fac_cod;
                                                fac_code[j].coun++;
                                        }
                                        else
                                        {
                                                section[i].faculty[k]=fac_code[j+6].fac_cod;
                                                fac_code[j+6].coun++;
                                        }
                 }
                 cop=1;
}                                                                               //for second loop;
else
{
    for(int i=1;i<6;i++)
    {
                 section[i].name=sec_code[i];
                 for(int j=i,k=0;k<6;j++,k++)
                 {       
                         section[i].subject[k]=sub_code[j];                  // problem is here
                         if(fac_code[j].coun<3)
                         {
                                                section[i].faculty[k]=fac_code[j].fac_cod;
                                                fac_code[j].coun++;
                         }
                         else
                         {
                             section[i].faculty[k]=fac_code[j+6].fac_cod;
                             fac_code[j+6].coun++;
                         }   
                 }
      }                                                                            //break IF >205 ::: CONDITION 2
      for(int i=1;i<6;i++)
      {
                 for(int j=0,k=0;k<6;k++)
                 {       
                         if(section[i].subject[k]<=205 && section[i].subject[k]>=200)
                         {        
                         }
                         else
                         {
                             section[i].subject[k]=sub_code[j];
                             if(fac_code[j].coun<3)                              //IF FACULTY ASSIGNED TO MORE THAN THREE
                             {
                                                section[i].faculty[k]=fac_code[j].fac_cod;
                                                fac_code[j].coun++;
                             }
                             else
                             {
                                                section[i].faculty[k]=fac_code[j+6].fac_cod;
                                                fac_code[j+6].coun++;
                              }
                              j++;
                         }
                 }
      }
}

}

//THE DISPLAY TERMINAL CONTAINS THE LUNCH PART


Please comment the solution here.

Note by Tanmay Baranwal
2 years, 9 months ago

No vote yet
1 vote

Comments

There are no comments in this discussion.

×

Problem Loading...

Note Loading...

Set Loading...