C + + implementation of hospital inspection Department scheduling program

Source: Internet
Author: User
Tags benchmark ming


C + + implementation of hospital inspection Department scheduling program

1. Background:Hospital Emergency Laboratory Department 24hx7x365 on duty, staff fixed. Take a shift system to ensure that 24h is manned. This article through the implementation of C + + programming automatic scheduling, and can be converted to Excel printing.
2, emergency Inspection Department scheduling overview (oral consultation after finishing):1), the number of inspection Department: 7 people. 2), the type of work: "Night Shift", "urinate", "rest", "emergency", "acute value", "emergency", a total of 5. 3), working hours: Each person fixed weekly rest 2 days, but two days for any two days within a week. 4), who will schedule: the director is responsible for scheduling. 5), scheduling principle: New colleagues 1 people, not on the night shift. New colleagues have exactly the same type of work each week. The director does not change the type of work week. In addition to new colleagues and the Director of other colleagues, to take shift system. 6), Shift principle: In addition to the Director and new colleagues outside the four colleagues work week-on-day type: Abcd,bcda,cdab,dabc,abcd .... poll in turn, change once a week ....
3, refine the demand:1) Implement automatic scheduling program. 2) Enter: Year 2015, and one-month benchmark schedule (provided by the inspection section). 3) Output: 1-year schedule, in weeks, including: The current year of the week, Day of the week, date, Inspector name, schedule. Output form: console, TXT document, Excel document (can be used to print).
4. Self-Analysis:1) Due to the regularity of scheduling, it can be achieved through the program. 2) in weeks to achieve, only need to store the number of days of the year, such as 2015 years 365 days, and then 7 days per week for printing. 3) Excel natively supports TXT documents, only the output specification TXT document, import Excel to meet the requirements.
5. Program Operation:


6, the source code implementation (VS2010 implementation):

WorkOrderDemo.cpp: Defines the entry point of the console application. #include "stdafx.h" #include <iostream>using namespace std; #include <stdio.h> #include <stdlib.h># Include <iomanip> #include <assert.h> #include <vector> #include <fstream> #include < assert.h> #define EQUAL ' = ' #define SPACE ' #define STARBAR ' * ' typedef unsigned int UINT32; #define Max_name_len 100// Maximum name length # define Max_span_len 9//Interval character length # max_weeks_cnt 52//365/7 or 366/7 weeks # # MAX_CYC_WEEK_CNT 6//MAX Cycles #define MAX_MONTH_CNTS_IN_YEAR 12//1 Month # define This_year 2015//Current year const char* Pszoutfile = "E:\\workt Able.txt "; ofstream g_foutfile (Pszoutfile); Open file for write, if file does not exist create it//week sequence typedef enum WEEK_DAY{MONDAY = 0,tuesday,wednesday,thursday,friday,satuday,sunday,max_ Work_days//Count with}weekday;//Duty Inspector name typedef enum INSPECTOR_YANTAI{WANG_XIN_PING = 0,fu_tian = 1,zhao_ji_juan = 2,//0zhao_ YU_XIANG,ZHANG_XIA,WANG_XIAO_FEI,ZHU_HONG_JING,MAX_INSPECTOR_CNT//Count with}inspector;//duty type typedef ENUM work_types{night_work = 0,//night Shift after_night_work,//urinate sleep,//Rest urgent_diagnose,//Emergency urgent_work,//Urgent Value Urgent_diagnose_afternon,//emergency afternoon work_cnts//7 count with}work_type;char g_pszinspectorarr[max_inspector_cnt][max_ Name_len] = {"Wang * ping", "Pay * Ming", "Zhao * Juan", "Zhao * xiang", "Zhang * yu", "Wang * fei", "Zhu * jing"};char G_worktypename[work_cnts][max_name_len] = {"Night Shift", "urinate", "Rest", "emergency", "acute value", "Emergency Afternoon"};char G_weekdayname[max_work_days][max_name_len] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};//Pro When stored work_type g_tmpdaywork[max_work_days] = {Night_work}; Work_type G_weekworktable[max_inspector_cnt][max_work_days] = {Night_work};  Work_type G_weekworktablebak[max_inspector_cnt][max_work_days] = {Night_work};  Benchmark table, January immutable//Store formatted date format vector<char* > g_daysvector;/*** @brief: Print character formatting with * * @param: ch character, num number * * @return: null. */  void Print_n_char (char ch, int num) {int count = 0;for (count = 0; count < num; count++) {cout << ch; G_foutfile << SPACE;}} /*** @brief: Returns the day of the week on the date of year * * @param: UINT32 iyear, UINT32 imonth month, UINT32 iday Day * * @return: Days of the week. */int Returnweekday (UINT32 iyear, UINT32 imonth, UINT32 iday) {int iweek = 0;  UINT32 y = 0, c = 0, m = 0, D = 0;if (Imonth = = 1 | | imonth = = 2) {c = (iYear-1)/100;  y = (iYear-1)% 100;  m = imonth + 12; d = iday;}  else{C = iyear/100;  y = iyear% 100;  m = imonth; d = iday;}    Iweek = y + y/4 + C/4-2 * C + + * (M + 1)/+ d-1; Caille Formula Iweek = Iweek >= 0?    (Iweek% 7): (Iweek% 7 + 7); Iweek for negative time modulo if (Iweek = = 0)//Sunday not as the first day of the week {iweek = 7;} return Iweek;} /*** @brief: Returns formatting weeks * * @param: int iweekday Day of the week * * @return: Formatting weeks. */char* getweekname (int iweekday) {assert (Iweekday > 0) ; return g_weekdayname[iweekday-1];} /*** @brief: Initialize the baseline worksheet to a week of May 11 (set to January 1) * * @param: null * * @return: None */void Initworktablebakfun () {//0 wang_xin_pingg_ Weekworktablebak[wang_xin_ping][monday] = Urgent_diagnose;g_weekworktablebak[wang_xin_ping][tuesday] = URGENT_WORK ; G_weekworktablebak[wang_xin_ping][wednesday] = Urgent_diagnose_aftErnon;g_weekworktablebak[wang_xin_ping][thursday] = Night_work;g_weekworktablebak[wang_xin_ping][friday] = AFTER_ Night_work;g_weekworktablebak[wang_xin_ping][satuday] = Sleep;g_weekworktablebak[wang_xin_ping][sunday] = SLEEP;// 1 Fu_tiang_weekworktablebak[fu_tian][monday] = Urgent_diagnose_afternon;g_weekworktablebak[fu_tian][tuesday] = Urgent_diagnose;g_weekworktablebak[fu_tian][wednesday] = Sleep;g_weekworktablebak[fu_tian][thursday] = URGENT_ Diagnose;g_weekworktablebak[fu_tian][friday] = Urgent_diagnose;g_weekworktablebak[fu_tian][satuday] = SLEEP;g_ Weekworktablebak[fu_tian][sunday] = URGENT_DIAGNOSE;//2 Zhao_ji_juang_weekworktablebak[zhao_ji_juan][monday] = Night_work;g_weekworktablebak[zhao_ji_juan][tuesday] = after_night_work;g_weekworktablebak[zhao_ji_juan][ Wednesday] = Sleep;g_weekworktablebak[zhao_ji_juan][thursday] = Sleep;g_weekworktablebak[zhao_ji_juan][friday] = After_night_work;g_weekworktablebak[zhao_ji_juan][satuday] = urgent_diagnose;g_weekworktablebak[zhao_ji_juan][ SUNDay] = NIGHT_WORK;//3 Zhao_yu_xiangg_weekworktablebak[zhao_yu_xiang][monday] = Urgent_work;g_weekworktablebak[zhao_ Yu_xiang][tuesday] = Night_work;g_weekworktablebak[zhao_yu_xiang][wednesday] = After_night_work;g_weekworktablebak [Zhao_yu_xiang] [Thursday] = sleep;g_weekworktablebak[zhao_yu_xiang][friday] = urgent_work;g_weekworktablebak[zhao_yu_xiang][ Satuday] = Urgent_diagnose_afternon;g_weekworktablebak[zhao_yu_xiang][sunday] = SLEEP;//4 ZHANG_XIAg_ Weekworktablebak[zhang_xia][monday] = Sleep;g_weekworktablebak[zhang_xia][tuesday] = URGENT_DIAGNOSE_AFTERNON;g_ Weekworktablebak[zhang_xia][wednesday] = Night_work;g_weekworktablebak[zhang_xia][thursday] = AFTER_NIGHT_WORK;g_ Weekworktablebak[zhang_xia][friday] = Sleep;g_weekworktablebak[zhang_xia][satuday] = URGENT_WORK;g_ Weekworktablebak[zhang_xia][sunday] = URGENT_WORK;//5 Wang_xiao_feig_weekworktablebak[wang_xiao_fei][monday] = Sleep;g_weekworktablebak[wang_xiao_fei][tuesday] = Sleep;g_weekworktablebak[wang_xiao_fei][wednesday] = URGENT_Work;g_weekworktablebak[wang_xiao_fei][thursday] = urgent_diagnose_afternon;g_weekworktablebak[wang_xiao_fei][ FRIDAY] = Night_work;g_weekworktablebak[wang_xiao_fei][satuday] = After_night_work;g_weekworktablebak[wang_xiao_ Fei][sunday] = URGENT_DIAGNOSE_AFTERNON;//6 Zhu_hong_jingg_weekworktablebak[zhu_hong_jing][monday] = SLEEP;g_ Weekworktablebak[zhu_hong_jing][tuesday] = Sleep;g_weekworktablebak[zhu_hong_jing][wednesday] = URGENT_DIAGNOSE;g_ Weekworktablebak[zhu_hong_jing][thursday] = Urgent_work;g_weekworktablebak[zhu_hong_jing][friday] = URGENT_ Diagnose_afternon;g_weekworktablebak[zhu_hong_jing][satuday] = night_work;g_weekworktablebak[zhu_hong_jing][ SUNDAY] = after_night_work;} /* * @brief: Determines whether the year is leap years. * * @param: iyear Current year. * * @return: true, leap years; False, Common year. */bool Isleapyear (UINT32 iyear) {if (iyear%4 = = 0 && iyear%100! = 0) | |  (iyear%400 = = 0))  {return true;  } else {return false; }}/*** @brief: Initialize worksheet (consistent with Datum table) * * @param: null * * @return: None */void Initworktablefun () {//-align with datum foR (int inspector = 0; Inspector < max_inspector_cnt; ++inspector) {for (int curday = 0; curday < max_work_days; ++c  Urday) {G_weekworktable[inspector][curday] = G_weekworktablebak[inspector][curday]; }}}/*** @brief: Returns the starting position in the vector array, printed with * * @param: Ncurweek Current Week * * @return: return pos*/int Getbeginofdaysvector (UINT32 Ncurweek) {//Get the date format of the week//return as first week: January 1, January 2, ... January 7assert (ncurweek >= 0 && ncurweek <= 1 + max_weeks_cnt); int ibegin = (nCurWeek-1) * 7;return Ibegin;} /*** @brief: Print a schedule for the week * * @param: Iweek Current Week * * @return: None */void printcurworktable (int iweek) {char sztmpformat[max_name_ LEN] = {0};for (int curday = 0; curday < 1 + max_work_days; ++curday) {if (0 = = curday) {cout << std::right   << STD::SETW (Max_span_len) << "";  G_foutfile << std::right << std::setw (max_span_len) << "";   } else {cout << std::right << std::setw (Max_span_len) << g_weekdayname[curday-1]; G_foutfile << Std::right << sTD::SETW (Max_span_len) << g_weekdayname[curday-1]; }}cout << endl;g_foutfile << endl;int ndaysofyear = 0;//printing Date week format: 1-1int ibegin = 0;int Iweeklen = 7;if (iwee  K <= max_weeks_cnt) {ibegin = Getbeginofdaysvector (Iweek);  cout << std::right << std::setw (max_span_len) << "";  G_foutfile << std::right << std::setw (max_span_len) << ""; for (int i = ibegin; I < Ibegin + Iweeklen; ++i) {cout << std::right << std::setw (Max_span_len) <&lt ;   G_daysvector[i];  G_foutfile << std::right << std::setw (Max_span_len) << g_daysvector[i];  } cout << Endl; G_foutfile << Endl;}  else{if (Isleapyear (this_year)) {ndaysofyear = 366;  } else {ndaysofyear = 365;  }//last week alone processing Iweeklen = Ndaysofyear-(max_weeks_cnt) *7;  Ibegin = getbeginofdaysvector (1 + max_weeks_cnt); for (int i = ibegin; I < Ibegin + Iweeklen; ++i) {cout << std::right << std::setw (Max_span_len) &Lt;< G_daysvector[i];  G_foutfile << std::right << std::setw (Max_span_len) << g_daysvector[i];  } cout << Endl; G_foutfile << Endl;} for (int curday = 0; curday < 1 + max_work_days; ++curday) {if (0 = = curday) {cout << std::right << St   D::SETW (Max_span_len) << "";  G_foutfile << std::right << std::setw (max_span_len) << "";   } for (int j = 0; j < max_span_len-1; ++j) {cout << '-';  G_foutfile << "; }}cout << endl;//g_foutfile << endl;int curworktype = 0;for (int inspector = 0; Inspector < Max_inspector_ CNT;  ++inspector) {sprintf_s (Sztmpformat, "%d%s", Inspector, G_pszinspectorarr[inspector]);  cout << std::left << std::setw (max_span_len) << Sztmpformat;  G_foutfile << std::right << std::setw (max_span_len) << Sztmpformat; for (int curday = 0; curday < max_work_days; ++curday) {curworktype = (int) (G_weekworktable[inspectoR][curday]);   cout << std::right << std::setw (Max_span_len) << G_worktypename[curworktype];  G_foutfile << std::right << std::setw (Max_span_len) << G_worktypename[curworktype];  } cout << Endl; G_foutfile << Endl;}} /*** @brief: Test Print Date format * * @param: null * * @return: None */void Testweekdayofdata () {int iyear = 2015;int Imonth = 6;int Iday = 1;for (i Day = 1; Iday <= 30;  ++iday) {int iweekday = Returnweekday (Iyear, Imonth, iday);  cout << iweekday << getweekname (iweekday) << "\ T";  if (iday% 7 = = 0) {cout << Endl; }}}/*** @brief: Schedule According to the basis week * * @param: Nweek Current Week * * @return: None */void Exchangework (UINT32 nweek) {assert (Nweek >= 0  && Nweek <= max_inspector_cnt-2);       0-5//0 1th Week unchanged: Shift Order 0 1 2 3 4 5 6;//1 2nd week: Shift order 0 1 3 4 5 6 2;//2 3rd week: Scheduling order 0 1 4 5 6 2 3;//3 4th week: Scheduling 0 1 5 6 2 3 4;//4 5th week: Shift Order 0 1 6 2 3 4 5; cyclic termination//5 6th week: Shift Order 0 1 2 3 4 5 6; change from base week to first week/each time if (0 = = Nweek  ){(void) Initworktablefun ();}   else{(void) initworktablefun (); 1-6 6 persons, line No. 0 always unchanged without scheduling for (int iinspector = 2; iinspector < max_inspector_cnt; ++iinspector) {int ineworder = i   Inspector + Nweek;   if (Ineworder > (max_inspector_cnt-1)) {Ineworder = (iinspector + nweek)% (max_inspector_cnt-2);   } if (0 = = Ineworder) {ineworder = 5;   }//cout << "Ineworder =" << ineworder << Endl;   ASSERT (Ineworder = = 3 | | ineworder = = 4 | | ineworder = = 5 | | ineworder = = 6 | | ineworder = 2); Monday to Sunday for (int curday = 0; curday < max_work_days; ++curday)//0-6 7 days {if (2 = = Iinspector) {G_tm  Pdaywork[curday] = G_weekworktable[nweek][curday];   } G_weekworktable[iinspector][curday] = G_weekworktablebak[ineworder][curday]; }//end for Curday}//end for iinspector}//end else}/*** @brief: schedules for the week of the year * * @param: Nweek current Week of the year * * @return: None */void Curwe Ekworkorder (UINT32 Nweek) {assert (Nweek <= max_weeks_cnt);//annual turnover to regular week UINT32 NORderweek = nweek% (max_inspector_cnt-2), assert (norderweek >= 0 && Norderweek < (max_inspector_cnt-2)); /cout << "Nweek =" << nweek << "Norderweek =" << norderweek << Endl; (void) exchangework (nOr Derweek);} /* * @brief: Determines the number of days in a certain year. * * @param: iyear current year, imonth current month; * * @return: The number of days in the current year and month. */unsigned int daysinmonth (UINT32 nyear,  UINT32 nmonth) {assert (Nmonth >=1 && nmonth <= max_month_cnts_in_year);  int ndaysinmonth = 0;    Switch (nmonth) {case 1:case 3:case 5:case 7:case 8:case 10:case 12:ndaysinmonth = 31;  Break    Case 4:case 6:case 9:case 11:ndaysinmonth = 30;  Break    Case 2:if (Isleapyear (nyear)) {ndaysinmonth = 29;    } else {ndaysinmonth = 28;  } break;    Default:cout << "Error month!!" << Endl;  Break  } return ndaysinmonth; }/* * * @brief: Build Formatted Date * * @param: Nyear Year of Year * * @return: None */void Builddayofmonth (UINT32 nyear) {UINT32 ndaysofyear = 0;if (IsLeApyear (Nyear)) {ndaysofyear = 366;} else{ndaysofyear = 365;} for (int imonth = 1, imonth <= max_month_cnts_in_year; ++imonth) {for (int iday = 1; iday <= (int) (DaysInMonth (Nyea R, Imonth));   ++iday) {Char *pszdataformat = (char*) malloc (20);   memset (Pszdataformat, 0, 20);   sprintf_s (Pszdataformat, "%d months%d days", Imonth, Iday);   cout << pszdataformat << "\ t";  G_daysvector.push_back (Pszdataformat); }//end for Iday//cout << Endl;} End for imonth}/* * * @brief: Free Memory * * @param: null * * @return: None */void Releasedaysvector () {int ivectorsize = G_daysvector.size ( );//cout << "ivectorsize =" << ivectorsize << endl;for (int i = 0; i < ivectorsize;   ++i) {if (NULL! = G_daysvector[i]) {free (g_daysvector[i]);  G_daysvector[i] = NULL;  }}}/* * * @brief: Test Print Annual Date format * * @param: Current Year * * @return: None */void Testprintdaysbyweek (UINT32 nyear) {int iweeklen = 7; Seven days per week int ndaysofyear = 0;if (Isleapyear (nyear)) {ndaysofyear = 366;} else{ndaysofyear = 365;} cout &Lt;< Endl;int ibegin = 0;for (int iweek = 1; iweek <= max_weeks_cnt; ++iweek) {ibegin = Getbeginofdaysvector (IWeek)  ;  for (int i = ibegin; I < Ibegin + Iweeklen; ++i) {cout << g_daysvector[i] << "\ t"; } cout << Endl;}  The last week is handled separately Iweeklen = ndaysofyear-(max_weeks_cnt) *7;ibegin = getbeginofdaysvector (1 + max_weeks_cnt); for (int i = Ibegin; I < Ibegin + Iweeklen; ++i) {cout << g_daysvector[i] << "\ t";} cout << Endl;} void Testprintvectordays () {int ivectorsize = G_daysvector.size ();//cout << "ivectorsize =" << ivectorsize &l t;< endl;for (int i = 0; i < ivectorsize; ++i) {cout << g_daysvector[i] << "\ t";}}  int _tmain (int argc, _tchar* argv[]) {(void) initworktablebakfun (); Baseline initialization (void) builddayofmonth (this_year);//(void) Testprintdaysbyweek (this_year);//Initialize Write file if (!g_foutfile) {cout << "Open file" << pszoutfile << "failed!" << Endl;} Char szdateformat[128] = {0};//Prints the annual schedule for (int iweek = 1; Iweek <= max_weeks_cnt;  ++iweek) {Print_n_char (Starbar, 28);  sprintf_s (Szdateformat, "%d weeks%d", this_year, Iweek);  cout << Szdateformat;  G_foutfile << Szdateformat;  Print_n_char (Starbar, 28);  cout << Endl;  G_foutfile << Endl;  Monthly Shifts (void) curweekworkorder (iWeek-1); (void)   Printcurworktable (Iweek);   cout << Endl << Endl; G_foutfile << Endl << Endl;} (void) Releasedaysvector (); G_foutfile.close (); GetChar (); return 0;}


7. Concluding remarks1) This kind of problem is relatively simple, the implementation of the logic of the details of complex, on paper simulation of the program run several times, straighten out the logic is very important. 2) The law is a breach, others are assisted to complete. 3) Repeated testing, on each interface to write corresponding to the demo test interface.

2015-6-6 pm18:09 at home in front of the bed, time consuming 9h

Ming Yi World

Reprint please indicate source, original address: http://blog.csdn.net/laoyang360/article/details/46390293

If you feel this article is helpful, please click on the ' top ' support, your support is I insist on writing the most power, thank you!


C + + implementation of hospital inspection Department scheduling program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.