Guest User

NurseScheduler

a guest
Aug 2nd, 2014
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.35 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. char *names[] = { "Denise", "Inja", "Jane", "Karen", "Maggie", "Margaret", "MJ", "Queen", "Sherri", NULL }; //ptr for names, 9 nurses
  6. const char days[5][10] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
  7. int randomNurse();
  8. #define total_nurses 9 //number of nurses on staff
  9. #define days_in_week 5 //number of work days in a week
  10.  
  11.  
  12. int main() {
  13.  
  14.     srand(time(NULL));
  15.     int day, pos, candidate, i, j;
  16.     int slackers[4] = { 1, 1, 1, 1 }; //array that holds the selections for who isn't working
  17.     char **name_ptr = names;
  18.     /*0 = Denise, 1 = Inja, 2 = Jane, 3 = Karen, 4 = Maggie, 5 = Margaret, 6 = MJ, 7 = Queen, 8 = Sherri*/
  19.     int avail_nurses[total_nurses] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; //holds the status of each nurse, 0 = unavailable, 1 = available
  20.  
  21.     /*prints names */
  22.     int temp_counter = 1; //counter
  23.     while (*name_ptr) {
  24.         printf("%i) %s\n", temp_counter, *name_ptr);
  25.         name_ptr++;
  26.         temp_counter++;
  27.     }
  28.  
  29.     /*this assumes that no more than FOUR nurses will be away on any given week*/
  30.     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");
  31.     printf("When you are done, press \"Enter\".\n");
  32.     printf("If less than four nurses will be on leave, type a \"0\" in place of a selection.\n");
  33.     printf("Example: 1 2 5 0\n\n\n");
  34.    
  35.     /*week selection of unavailable nurses*/
  36.         do {
  37.             printf("Who won't be here?  ");
  38.         } while (scanf("%i %i %i %i", &slackers[0], &slackers[1], &slackers[2], &slackers[3]) != 4);
  39.  
  40.     /*checks the selections made, and sets the available nurses to the correct value, zero if they are slacking||vacationing*/
  41.     for (int n = 0; n < 4; n++) {
  42.         int slacker = slackers[n];
  43.         if (slacker >= 1 && slacker <= 9)
  44.             avail_nurses[slacker] = 0; //set to zero since that nurse isn't working
  45.     }
  46.  
  47.  
  48.     /*-----WEEKLY_ASSIGNMENT-----*/
  49.     int pos_per_day[days_in_week] = { 5, 9, 9, 8, 5 }; //number of nurses needed each day
  50.  
  51.     int selection[days_in_week][total_nurses]; //the selected nurses per day
  52.  
  53.     for (i = 0; i < days_in_week; i++) {
  54.         for (j = 0; j < total_nurses; j++) {
  55.             selection[i][j] = -1; //initialize to -1 which means no nurse is selected
  56.         }
  57.     }
  58.  
  59.     //fill all the days of week
  60.     for (day = 0; day < days_in_week; day++) {
  61.         for (pos = 0; pos < pos_per_day[day]; pos++) { //for every position needed that day
  62.             do {
  63.                 candidate = randomNurse();
  64.             } while (!avail_nurses[candidate]); //looks for available nurses (phrasing)
  65.  
  66.             avail_nurses[candidate] = 0;  //change nurses status to not available
  67.             selection[day][pos] = candidate;  //fill the output array with appropriate nurse
  68.         }
  69.         for (i = 0; i < total_nurses; i++) {
  70.             avail_nurses[i] = 1; //initialize the nurses status for next day use
  71.         }
  72.         for (int n = 0; n < 4; n++) { //make sure we shame the slackers...
  73.             int slacker = slackers[n];
  74.             if (slacker >= 1 && slacker <= 9)
  75.                 avail_nurses[slacker] = 0;
  76.         }
  77.     }
  78.  
  79.     /*-----PRINTS SCHEDULE FOR WEEK-----*/
  80.     for (i = 0; i < days_in_week; i++) {
  81.         printf("%-10s: ", days[i]);
  82.         for (j = 0; j < total_nurses; j++) {
  83.             if (selection[i][j] != -1)
  84.                 printf("%-10s ", names[selection[i][j]]);
  85.         }
  86.         printf("\n");
  87.     }
  88.     return 0;
  89. }
  90.  
  91. /*function to generate random nurse*/
  92. int randomNurse() {
  93.  
  94.     return rand() % 9; //random number 0-8, to pick nurse
  95. }
Advertisement
Add Comment
Please, Sign In to add comment