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
|
#include <iostream>
#include <string>
using namespace std;
void print(int x);
int checkC(int x);
int consecutive(int x);
bool weekends(int x);
int consWeekends(int x, int y);
#define n 28
int day[n]; //current day
int doc=0; //Keeps track of Person A,B,C
const int DocA=1; //PersonA
const int DocB=2; //PersonB
const int DocC=3; //PersonC
string ok[]={"S", "M", "T", "W", "T", "F", "S",
"S", "M", "T", "W", "T", "F", "S",
"S", "M", "T", "W", "T", "F", "S",
"S", "M", "T", "W", "T", "F", "S"};
int main()
{
for(int i=0; i<n; i++) //Cycles through days 1-28
{
doc=doc+1; //Starts doc at Doctor A
if(doc==1) //If doc equals A
{
day[i]=1; //Schedule Doctor A on current day.
consecutive(i); //Checks to see if Doctor A is going to be scheduled consecutively, if so schedule current day to Doctor B
}
if(doc==2) //If doc equals B
{
day[i]=2; //Schedule Doctor B on current day.
consecutive(i); //Checks to see if Doctor B is going to be scheduled consecutively, if so schedule current day to Doctor C
}
if(doc==3) //If doc equals C
{
day[i]=3; //Schedule Doctor C on current day.
checkC(i);
consecutive(i); //Checks to see if Doctor C is going to be scheduled consecutively, if so schedule current day to Doctor A
doc=0;
}
consWeekends(i,doc);
if(i==27)
{
day[i]=DocC;
}
print(i); //Prints Schedule
}
return 0;
}
int consecutive(int i) //Checks to see if Doctors are scheduled consecutively
{
if(day[i]==day[i+1] || day[i]==day[i-1]) //Check to see if current day has the same Doctor as previous and next days
{
if(day[i]==1) //If Doctor A is consecutive
{
day[i]=2; //Then schedule Doctor B for current day
return day[i];
}
if(day[i]==2) //If Doctor B is consecutive
{
day[i]=3; //Then schedule Doctor C for current day
return day[i];
}
if(day[i]==3) //If Doctor C is consecutive
{
day[i]=1; //Then schedule Doctor A for current day
return day[i];
}
}
return 0;
}
void print(int i)
{
if(day[i]==1) //If current day scheduled Doctor A
{
cout << "Day (AM)" << ok[i] << ": A" << endl; //Print day for Doctor A
}
if(day[i]==2) //If current day scheduled Doctor B
{
cout << "Day (PM) " << ok[i] << ": B" << endl; //Print schduled Day for Doctor B
}
if(day[i]==3) //If current day scheduled Doctor C
{
cout << "Day " << ok[i] << ": C" << endl; //Print schduled Day for Doctor C
}
}
int checkC(int i) //Checks to see if Doctor C is scheduled on Tuesdays and Saturdays
{
if(i==0 || i==4 ||
i==7 || i==11||
i==14|| i==18||
i==21|| i==25)
day[i]=DocB; //If Doctor C is scheduled on Tuesdays and Saturdays, schedule Doctor B instead of C
return day[i];
}
int consWeekends(int i, int y)
{
for(i; i<n; i++)
{
if(i==4 || i==5 )
{
day[i]=DocA;
if(day[i]==DocA)
{
day[i-2]=doc+1;
day[i-1]=doc+1;
}
return day[i];
}
if(i==11 || i==12)
{
day[i-1]=doc+1;
day[i]=DocB;
return day[i];
}
if(i==18 || i==19)
{
day[i-1]=doc+3;
day[i]=DocA;
return day[i];
}
if(i==25 || i==26)
{
day[i-1]=doc;
day[i]=DocB;
return day[i];
}
}
}
bool weekends(int i)
{
if(i==4 || i==5 )
{
day[i]=DocA;
}
if(i==11 || i==12)
{
day[i]=DocB;
}
if(i==18 || i==19)
{
day[i]=DocA;
}
if(i==25 || i==26)
{
day[i]=DocB;
}
return true;
}
|