Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.84 KB | None | 0 0
  1. /*
  2. Project: Dentists appointment system
  3. Purpose: Use a random access file to store patients and use a serial access file to store appointments
  4. Author: JT
  5. Ver: 1.0
  6. Date: 02/12/2016
  7.  
  8. */
  9.  
  10. //includes
  11. #include <conio.h>
  12. #include <fstream.h>
  13. #include <iostream.h>
  14. #include <clx.h>
  15. #include <string.h>
  16. #pragma hdrstop
  17.  
  18. // Customer file definitions
  19. char FileName1[200]="PatientFile";
  20. typedef struct tag_cr{
  21.         char patNo[4];
  22.         char patFName[15];
  23.         char patSName[15];
  24.         char patNum[12];
  25.         char patBday[12];
  26.         char patDateJoin[12];
  27.         char addLine1[30];
  28.         char addLine2[30];
  29.         char city[15];
  30.         char postcode[9];
  31.         char flag[2];
  32. } PATIENT_RECORD;
  33. int patNo;
  34. PATIENT_RECORD a_pat;
  35.  
  36. //Global Variables for sequentialfileaccess
  37. char appFile[200] = "Appointment File";        // Name of data file
  38. char appPatNo[200][4];                         //
  39. char appNo[200][4];                            //
  40. char appDay[200][12];                          //
  41. char appTime[200][6];                          //
  42. char appDenName[200][25];                      //
  43. char appReason[200][30];                       //
  44. int nai;                                       //
  45. char nac[4];                                   //
  46.  
  47. //Function Declaration
  48. int mainMenu();                                // User Interface
  49. int newApp();                                  // New appointment
  50. int findApp();                                 // Find appointment
  51. int delApp();                                  // Delete appointment
  52. int reWriteAppFile();                          // Write the appointment file
  53. int readBackAppFile();                         // Read the appointment file
  54. int newPat();                                  // Register a patient
  55. int delPat();                                  // Delete patient record
  56. int updPat();                                  // Update patient record
  57. int createEmptyFileV();                        // Verify if the user wants to create empty file for data
  58. int createEmptyFile();                         // Create empty file for data
  59. //---------------------------------------------------------------------------
  60.  
  61. #pragma argsused
  62. int main(int argc, char* argv[])
  63. {
  64.         int mainStatus=0;
  65.         while (mainStatus != 8)
  66.         {
  67.                 mainStatus=mainMenu();
  68.         }
  69. }
  70.  
  71. int mainMenu()
  72. {
  73. int choice;
  74. cout<<"\nMain Menu";
  75. cout<<"\n======================================================================= \n";
  76. cout<<"\n1. Register a new patient";
  77. cout<<"\n2. Update a patient's details";
  78. cout<<"\n3. Delete a patient's detials";
  79. cout<<"\n4. Make a new appointment";
  80. cout<<"\n5. Find a patient's appointment(s)";
  81. cout<<"\n6. Cancel/Delete or change an appointment";
  82. cout<<"\n7. Create Patient file (Only on first time running \ndoing it any other time will erase ALL date)";
  83. cout<<"\n8. Exit";
  84. cout<<"\nEnter Choice: \n";
  85. cin>>choice;
  86. switch(choice)
  87. {
  88.         case 1:
  89.         {
  90.         clrscr();
  91.         newPat();
  92.          break;
  93.         }
  94.         case 2:
  95.         {
  96.         clrscr();
  97.         updPat();
  98.          break;
  99.         }
  100.         case 3:
  101.         {
  102.         clrscr();
  103.         delPat();
  104.          break;
  105.         }
  106.         case 4:
  107.         {
  108.          clrscr();
  109.          newApp();
  110.          break;
  111.         }
  112.         case 5:
  113.         {
  114.          clrscr();
  115.          findApp();
  116.          break;
  117.         }
  118.         case 6:
  119.         {
  120.          clrscr();
  121.          delApp();
  122.          break;
  123.         }
  124.         case 7:
  125.         {
  126.         clrscr();
  127.          createEmptyFileV();
  128.          break;
  129.         }
  130.         case 8:
  131.         {
  132.          break;
  133.         }
  134.         default:
  135.         {
  136.          cout<<"\nOptions 1-8 only please";
  137.         }
  138.         }
  139.         return choice;
  140. }
  141.  
  142. int newApp()
  143. {
  144. int compare;
  145. cout<< "\nAdd a new appointment";
  146. cout << "\nEnter patient number ";
  147. cin>>patNo;
  148. ifstream fin(FileName1, ios::binary);
  149. fin.seekg(patNo * sizeof (a_pat));
  150. fin.read((char*)&a_pat,sizeof(a_pat));
  151. fin.close();
  152. compare = strcmpi(a_pat.flag, "0");
  153. if(compare != 0)
  154. {
  155.         readBackAppFile();
  156.         cin.get();
  157.         cout << "\nEnter the appointment number ";
  158.         cin.getline(appNo[nai], sizeof(appNo));
  159.         cout << "\nEnter the date of the appointment ";
  160.         cin.getline(appDay[nai], sizeof(appDay));
  161.         cout << "\nEnter the time of the appointment ";
  162.         cin.getline(appTime[nai], sizeof(appTime));
  163.         cout << "\nEnter the dentists name ";
  164.         cin.getline(appDenName[nai], sizeof(appDenName));
  165.         cout << "\nAppointment reason ";
  166.         cin.getline(appReason[nai], sizeof(appReason));
  167.         sprintf(appPatNo[nai], "%d", patNo);
  168.         nai=nai+1;
  169.         itoa(nai, nac, 10);
  170.         reWriteAppFile();
  171. }  else  {
  172.  cout << "\nNo patient found";
  173. }
  174. return 0;
  175. }
  176.  
  177. int findApp()
  178. {
  179. int compare;
  180. string patno;
  181. cout<< "\nFind a patients appointments";
  182. cout << "\nEnter patient number ";
  183. cin >> patno;
  184. readBackAppFile();
  185. cin.get();
  186. for(int i = 0; i < nai;i++)
  187. {
  188.         if(appPatNo[i] == patno)
  189.         {
  190.         cout << "\n" << "Appoint number " << i << "\n" << appDay[i] << "\n" << appTime[i] << "\n" << appDenName[i] << "\n" << appReason[i] << endl;
  191.         }
  192. }
  193. return 0;
  194. }
  195.  
  196. int delApp()
  197. {
  198.         return 0;
  199. }
  200.  
  201. int newPat()
  202. {
  203.         int compare;
  204.         cout << "\nAdd a new patient";
  205.         cout << "\nEnter patient number ";
  206.         cin>>patNo;
  207.         ifstream fin(FileName1, ios::binary);
  208.         fin.seekg(patNo * sizeof (a_pat));
  209.         fin.read((char*)&a_pat,sizeof(a_pat));
  210.         fin.close();
  211.         compare = strcmpi(a_pat.flag, "0");
  212.         if (compare == 0)
  213.         {
  214.                 ofstream fout(FileName1, ios::in);
  215.                 fout.seekp(patNo * sizeof(a_pat));
  216.                 cin.get();
  217.                 cout << "\nEnter patients first name ";
  218.                 cin.getline(a_pat.patFName, sizeof(a_pat.patFName));
  219.                 cout << "\nEnter patients surname ";
  220.                 cin.getline(a_pat.patSName, sizeof(a_pat.patSName));
  221.                 cout << "\nEnter patients phone number ";
  222.                 cin.getline(a_pat.patNum, sizeof(a_pat.patNum));
  223.                 cout << "\nEnter patients birthday ";
  224.                 cin.getline(a_pat.patBday, sizeof(a_pat.patBday));
  225.                 cout << "\nEnter todays date ";
  226.                 cin.getline(a_pat.patDateJoin, sizeof(a_pat.patDateJoin));
  227.                 cout << "\nEnter patients address line 1 ";
  228.                 cin.getline(a_pat.addLine1, sizeof(a_pat.addLine1));
  229.                 cout << "\nEnter patients address line 2 ";
  230.                 cin.getline(a_pat.addLine2, sizeof(a_pat.addLine2));
  231.                 cout << "\nEnter patients city ";
  232.                 cin.getline(a_pat.city, sizeof(a_pat.city));
  233.                 cout << "\nEnter patients postcode ";
  234.                 cin.getline(a_pat.postcode, sizeof(a_pat.postcode));
  235.                 strcpy(a_pat.flag, "1");
  236.                 sprintf(a_pat.patNo, "%d", patNo);
  237.                 fout.write((char*) &a_pat, sizeof(a_pat));
  238.                 clrscr();
  239.                 cout << "Patient added\n";
  240.                 fout.close();
  241.         }  else {
  242.                 cout << "\nPatient number is taken";
  243.         }
  244.         return 0;
  245. }
  246.  
  247. int delPat()
  248. {
  249.         int compare;
  250.         cout<<"\nUpdating a patient";
  251.         cout<<"\nEnter patient number";
  252.         cin>>patNo;
  253.         ifstream fin(FileName1, ios::binary);
  254.         fin.seekg(patNo*sizeof(a_pat));
  255.         fin.get((char*)&a_pat,sizeof(a_pat));
  256.         fin.close();
  257.         compare=strcmpi(a_pat.flag,"0");
  258.         if (compare != 0)
  259.         {
  260.                 ofstream fout(FileName1, ios::in);
  261.                 fout.seekp(patNo * sizeof (a_pat));
  262.                 strcpy(a_pat.flag, "0");
  263.                 fout.write((char*) &a_pat, sizeof (a_pat));
  264.                 fout.close();
  265.                 cout << "\nPatient deleted";
  266.                 fout.close();
  267.         }
  268.         return 0;
  269. }
  270.  
  271. int updPat()
  272. {
  273.         int compare;
  274.         cout<<"\nUpdating a patient";
  275.         cout<<"\nEnter patient number";
  276.         cin>>patNo;
  277.         ifstream fin(FileName1, ios::binary);
  278.         fin.seekg(patNo*sizeof(a_pat));
  279.         fin.get((char*)&a_pat,sizeof(a_pat));
  280.         fin.close();
  281.         compare=strcmpi(a_pat.flag,"0");
  282.         if (compare != 0)
  283.         {
  284.                 ofstream fout(FileName1, ios::in);
  285.                 fout.seekp(patNo * sizeof(a_pat));
  286.                 cin.get();
  287.                 cout << "\nEnter patients first name ";
  288.                 cin.getline(a_pat.patFName, sizeof(a_pat.patFName));
  289.                 cout << "\nEnter patients surname ";
  290.                 cin.getline(a_pat.patSName, sizeof(a_pat.patSName));
  291.                 cout << "\nEnter patients phone number ";
  292.                 cin.getline(a_pat.patNum, sizeof(a_pat.patNum));
  293.                 cout << "\nEnter patients birthday ";
  294.                 cin.getline(a_pat.patBday, sizeof(a_pat.patBday));
  295.                 cout << "\nEnter todays date ";
  296.                 cin.getline(a_pat.patDateJoin, sizeof(a_pat.patDateJoin));
  297.                 cout << "\nEnter patients address line 1 ";
  298.                 cin.getline(a_pat.addLine1, sizeof(a_pat.addLine1));
  299.                 cout << "\nEnter patients address line 2 ";
  300.                 cin.getline(a_pat.addLine2, sizeof(a_pat.addLine2));
  301.                 cout << "\nEnter patients city ";
  302.                 cin.getline(a_pat.city, sizeof(a_pat.city));
  303.                 cout << "\nEnter patients postcode ";
  304.                 cin.getline(a_pat.postcode, sizeof(a_pat.postcode));
  305.                 strcpy(a_pat.flag, "1");
  306.                 fout.write((char*) &a_pat, sizeof(a_pat));
  307.                 clrscr();
  308.                 cout << "Patient Updated\n";
  309.                 fout.close();
  310.         }  else {
  311.                 cout << "\nNo patient to update";
  312.         }
  313.        return 0;
  314. }
  315.  
  316. int createEmptyFileV()
  317. {
  318.         char option;
  319.         cout << "Are you sure you want to create empty file? This will erase ALL data! Y/N" << endl;
  320.         cin >> option;
  321.         if (option == 'Y')
  322.         {
  323.                 createEmptyFile();
  324.         }
  325.         else
  326.         {
  327.                 mainMenu();
  328.         }
  329.         return 0;
  330. }
  331.  
  332. int createEmptyFile()
  333. {
  334.         ofstream fout(FileName1,ios::binary);
  335.         strcpy(a_pat.flag,"0");
  336.  
  337.         for(patNo=0;patNo<200;patNo++)
  338.         {
  339.                 fout.write((char*)&a_pat,sizeof(a_pat));
  340.         }//endfor
  341.         fout.close();
  342.         cout << "File created";
  343.         return 0;
  344. }
  345.  
  346. int reWriteAppFile()
  347. {
  348. int count;
  349. ofstream fout(appFile, ios::binary);
  350. fout.write((char*) &nac, sizeof (nac));
  351. for (count = 0; count < nai; count++)
  352. {
  353.         fout.write((char*) &appNo[count], strlen(appNo[count]));
  354.         fout.write("\n", 1);
  355.         fout.write((char*) &appPatNo[count], strlen(appPatNo[count]));
  356.         fout.write("\n", 1);
  357.         fout.write((char*) &appDay[count], strlen(appDay[count]));
  358.         fout.write("\n", 1);
  359.         fout.write((char*) &appTime[count], strlen(appTime[count]));
  360.         fout.write("\n", 1);
  361.         fout.write((char*) &appDenName[count], strlen(appDenName[count]));
  362.         fout.write("\n", 1);
  363.         fout.write((char*) &appReason[count], strlen(appReason[count]));
  364.         fout.write("\n", 1);
  365.  
  366. }//endfor
  367. fout.close();
  368. return 0;
  369. }
  370.  
  371. int readBackAppFile()
  372. {
  373. int count;
  374. ifstream fin(appFile,ios::binary);
  375. fin.read((char*)&nac,sizeof(nac));
  376. sscanf(&nac[0],"%d",&nai);
  377. for( count=0;count<nai;count++)
  378. {
  379.         fin.getline(appNo[count],sizeof(appNo[count]));
  380.         fin.getline(appPatNo[count],sizeof(appPatNo[count]));
  381.         fin.getline(appDay[count],sizeof(appDay[count]));
  382.         fin.getline(appTime[count],sizeof(appTime[count]));
  383.         fin.getline(appDenName[count],sizeof(appDenName[count]));
  384.         fin.getline(appReason[count],sizeof(appReason[count]));
  385. }//endfor
  386. fin.close();
  387. return 0;
  388. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement