Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdlib.h>
- #include <time.h>
- char *names[] = { "Denise", "Inja", "Jane", "Karen", "Maggie", "Margaret", "MJ", "Queen", "Sherri", NULL }; //ptr for names, 9 nurses
- const char days[5][10] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
- int randomNurse();
- #define total_nurses 9 //number of nurses on staff
- #define days_in_week 5 //number of work days in a week
- int main() {
- srand(time(NULL));
- int day, pos, candidate, i, j;
- int slackers[4] = { 1, 1, 1, 1 }; //array that holds the selections for who isn't working
- char **name_ptr = names;
- /*0 = Denise, 1 = Inja, 2 = Jane, 3 = Karen, 4 = Maggie, 5 = Margaret, 6 = MJ, 7 = Queen, 8 = Sherri*/
- int avail_nurses[total_nurses] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; //holds the status of each nurse, 0 = unavailable, 1 = available
- /*prints names */
- int temp_counter = 1; //counter
- while (*name_ptr) {
- printf("%i) %s\n", temp_counter, *name_ptr);
- name_ptr++;
- temp_counter++;
- }
- /*this assumes that no more than FOUR nurses will be away on any given week*/
- printf("\nEnter numbers that correspond to the nurses who won't be available for the week.\nType up to four numbers, each separated by a space.\n");
- printf("When you are done, press \"Enter\".\n");
- printf("If less than four nurses will be on leave, type a \"0\" in place of a selection.\n");
- printf("Example: 1 2 5 0\n\n\n");
- /*week selection of unavailable nurses*/
- do {
- printf("Who won't be here? ");
- } while (scanf("%i %i %i %i", &slackers[0], &slackers[1], &slackers[2], &slackers[3]) != 4);
- /*checks the selections made, and sets the available nurses to the correct value, zero if they are slacking||vacationing*/
- for (int n = 0; n < 4; n++) {
- int slacker = slackers[n];
- if (slacker >= 1 && slacker <= 9)
- avail_nurses[slacker] = 0; //set to zero since that nurse isn't working
- }
- /*-----WEEKLY_ASSIGNMENT-----*/
- int pos_per_day[days_in_week] = { 5, 9, 9, 8, 5 }; //number of nurses needed each day
- int selection[days_in_week][total_nurses]; //the selected nurses per day
- for (i = 0; i < days_in_week; i++) {
- for (j = 0; j < total_nurses; j++) {
- selection[i][j] = -1; //initialize to -1 which means no nurse is selected
- }
- }
- //fill all the days of week
- for (day = 0; day < days_in_week; day++) {
- for (pos = 0; pos < pos_per_day[day]; pos++) { //for every position needed that day
- do {
- candidate = randomNurse();
- } while (!avail_nurses[candidate]); //looks for available nurses (phrasing)
- avail_nurses[candidate] = 0; //change nurses status to not available
- selection[day][pos] = candidate; //fill the output array with appropriate nurse
- }
- for (i = 0; i < total_nurses; i++) {
- avail_nurses[i] = 1; //initialize the nurses status for next day use
- }
- for (int n = 0; n < 4; n++) { //make sure we shame the slackers...
- int slacker = slackers[n];
- if (slacker >= 1 && slacker <= 9)
- avail_nurses[slacker] = 0;
- }
- }
- /*-----PRINTS SCHEDULE FOR WEEK-----*/
- for (i = 0; i < days_in_week; i++) {
- printf("%-10s: ", days[i]);
- for (j = 0; j < total_nurses; j++) {
- if (selection[i][j] != -1)
- printf("%-10s ", names[selection[i][j]]);
- }
- printf("\n");
- }
- return 0;
- }
- /*function to generate random nurse*/
- int randomNurse() {
- return rand() % 9; //random number 0-8, to pick nurse
- }
Advertisement
Add Comment
Please, Sign In to add comment