Month Schedule

I'm trying to make a scheduling program that schedules person A,B,C and D to work on specific days of the week.

1. Person C cannot work on Tuesdays and Thurdays, and it cannot work on AM Sunday, but it can work on PM Sunday
2. No one can do and AM or PM shift on a weekend except on Saturday
3. Person A and B alternate weekends, so if person A does a Saturday AM shift then he also does the PM shift and the Sunday AM shift
4. Person A and D are a pair and so is B and C for rule 3.

My code is as follows:
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;
}


I have most of what I want, but now I want it in a month format, so I had this code made to organize it.
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
#include <iostream>
#include <string>
using namespace std;

void displayCal(const string &month, int daysInMonth);

int main()
{
	string month, firstDay;
	int daysInMonth;

	month = "May";
	daysInMonth = 31;
	displayCal(month, daysInMonth);
}

void displayCal(const string &month, int dayOne, int daysInMonth)
{
	static const int daysPerWeek = 7;
	static const string dayStr[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thurdsay", "Friday", "Saturday"};

	int day, w;
	day = 1;

	cout << endl << month << endl;
	cout << endl << string(3 * dayOne++, ' ');
	w = dayOne;
	do {
		cout << day++;
		if (w++ == daysPerWeek) 
		{
			cout << endl;
			w = 1;
		}
	}
	while (day <= daysInMonth);
	cout << endl;
}


Now I'm very much lost.

I think what I really need is just a way to organize the former code into the latter code to look like a month in a calendar
Last edited on
Topic archived. No new replies allowed.