Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Project: Dentists appointment system
- Purpose: Use a random access file to store patients and use a serial access file to store appointments
- Author: JT
- Ver: 1.0
- Date: 02/12/2016
- */
- //includes
- #include <conio.h>
- #include <fstream.h>
- #include <iostream.h>
- #include <clx.h>
- #include <string.h>
- #pragma hdrstop
- // Customer file definitions
- char FileName1[200]="PatientFile";
- typedef struct tag_cr{
- char patNo[4];
- char patFName[15];
- char patSName[15];
- char patNum[12];
- char patBday[12];
- char patDateJoin[12];
- char addLine1[30];
- char addLine2[30];
- char city[15];
- char postcode[9];
- char flag[2];
- } PATIENT_RECORD;
- int patNo;
- PATIENT_RECORD a_pat;
- //Global Variables for sequentialfileaccess
- char appFile[200] = "Appointment File"; // Name of data file
- char appPatNo[200][4]; //
- char appNo[200][4]; //
- char appDay[200][12]; //
- char appTime[200][6]; //
- char appDenName[200][25]; //
- char appReason[200][30]; //
- int nai; //
- char nac[4]; //
- //Function Declaration
- int mainMenu(); // User Interface
- int newApp(); // New appointment
- int findApp(); // Find appointment
- int delApp(); // Delete appointment
- int reWriteAppFile(); // Write the appointment file
- int readBackAppFile(); // Read the appointment file
- int newPat(); // Register a patient
- int delPat(); // Delete patient record
- int updPat(); // Update patient record
- int createEmptyFileV(); // Verify if the user wants to create empty file for data
- int createEmptyFile(); // Create empty file for data
- //---------------------------------------------------------------------------
- #pragma argsused
- int main(int argc, char* argv[])
- {
- int mainStatus=0;
- while (mainStatus != 8)
- {
- mainStatus=mainMenu();
- }
- }
- int mainMenu()
- {
- int choice;
- cout<<"\nMain Menu";
- cout<<"\n======================================================================= \n";
- cout<<"\n1. Register a new patient";
- cout<<"\n2. Update a patient's details";
- cout<<"\n3. Delete a patient's detials";
- cout<<"\n4. Make a new appointment";
- cout<<"\n5. Find a patient's appointment(s)";
- cout<<"\n6. Cancel/Delete or change an appointment";
- cout<<"\n7. Create Patient file (Only on first time running \ndoing it any other time will erase ALL date)";
- cout<<"\n8. Exit";
- cout<<"\nEnter Choice: \n";
- cin>>choice;
- switch(choice)
- {
- case 1:
- {
- clrscr();
- newPat();
- break;
- }
- case 2:
- {
- clrscr();
- updPat();
- break;
- }
- case 3:
- {
- clrscr();
- delPat();
- break;
- }
- case 4:
- {
- clrscr();
- newApp();
- break;
- }
- case 5:
- {
- clrscr();
- findApp();
- break;
- }
- case 6:
- {
- clrscr();
- delApp();
- break;
- }
- case 7:
- {
- clrscr();
- createEmptyFileV();
- break;
- }
- case 8:
- {
- break;
- }
- default:
- {
- cout<<"\nOptions 1-8 only please";
- }
- }
- return choice;
- }
- int newApp()
- {
- int compare;
- cout<< "\nAdd a new appointment";
- cout << "\nEnter patient number ";
- cin>>patNo;
- ifstream fin(FileName1, ios::binary);
- fin.seekg(patNo * sizeof (a_pat));
- fin.read((char*)&a_pat,sizeof(a_pat));
- fin.close();
- compare = strcmpi(a_pat.flag, "0");
- if(compare != 0)
- {
- readBackAppFile();
- cin.get();
- cout << "\nEnter the appointment number ";
- cin.getline(appNo[nai], sizeof(appNo));
- cout << "\nEnter the date of the appointment ";
- cin.getline(appDay[nai], sizeof(appDay));
- cout << "\nEnter the time of the appointment ";
- cin.getline(appTime[nai], sizeof(appTime));
- cout << "\nEnter the dentists name ";
- cin.getline(appDenName[nai], sizeof(appDenName));
- cout << "\nAppointment reason ";
- cin.getline(appReason[nai], sizeof(appReason));
- sprintf(appPatNo[nai], "%d", patNo);
- nai=nai+1;
- itoa(nai, nac, 10);
- reWriteAppFile();
- } else {
- cout << "\nNo patient found";
- }
- return 0;
- }
- int findApp()
- {
- int compare;
- string patno;
- cout<< "\nFind a patients appointments";
- cout << "\nEnter patient number ";
- cin >> patno;
- readBackAppFile();
- cin.get();
- for(int i = 0; i < nai;i++)
- {
- if(appPatNo[i] == patno)
- {
- cout << "\n" << "Appoint number " << i << "\n" << appDay[i] << "\n" << appTime[i] << "\n" << appDenName[i] << "\n" << appReason[i] << endl;
- }
- }
- return 0;
- }
- int delApp()
- {
- return 0;
- }
- int newPat()
- {
- int compare;
- cout << "\nAdd a new patient";
- cout << "\nEnter patient number ";
- cin>>patNo;
- ifstream fin(FileName1, ios::binary);
- fin.seekg(patNo * sizeof (a_pat));
- fin.read((char*)&a_pat,sizeof(a_pat));
- fin.close();
- compare = strcmpi(a_pat.flag, "0");
- if (compare == 0)
- {
- ofstream fout(FileName1, ios::in);
- fout.seekp(patNo * sizeof(a_pat));
- cin.get();
- cout << "\nEnter patients first name ";
- cin.getline(a_pat.patFName, sizeof(a_pat.patFName));
- cout << "\nEnter patients surname ";
- cin.getline(a_pat.patSName, sizeof(a_pat.patSName));
- cout << "\nEnter patients phone number ";
- cin.getline(a_pat.patNum, sizeof(a_pat.patNum));
- cout << "\nEnter patients birthday ";
- cin.getline(a_pat.patBday, sizeof(a_pat.patBday));
- cout << "\nEnter todays date ";
- cin.getline(a_pat.patDateJoin, sizeof(a_pat.patDateJoin));
- cout << "\nEnter patients address line 1 ";
- cin.getline(a_pat.addLine1, sizeof(a_pat.addLine1));
- cout << "\nEnter patients address line 2 ";
- cin.getline(a_pat.addLine2, sizeof(a_pat.addLine2));
- cout << "\nEnter patients city ";
- cin.getline(a_pat.city, sizeof(a_pat.city));
- cout << "\nEnter patients postcode ";
- cin.getline(a_pat.postcode, sizeof(a_pat.postcode));
- strcpy(a_pat.flag, "1");
- sprintf(a_pat.patNo, "%d", patNo);
- fout.write((char*) &a_pat, sizeof(a_pat));
- clrscr();
- cout << "Patient added\n";
- fout.close();
- } else {
- cout << "\nPatient number is taken";
- }
- return 0;
- }
- int delPat()
- {
- int compare;
- cout<<"\nUpdating a patient";
- cout<<"\nEnter patient number";
- cin>>patNo;
- ifstream fin(FileName1, ios::binary);
- fin.seekg(patNo*sizeof(a_pat));
- fin.get((char*)&a_pat,sizeof(a_pat));
- fin.close();
- compare=strcmpi(a_pat.flag,"0");
- if (compare != 0)
- {
- ofstream fout(FileName1, ios::in);
- fout.seekp(patNo * sizeof (a_pat));
- strcpy(a_pat.flag, "0");
- fout.write((char*) &a_pat, sizeof (a_pat));
- fout.close();
- cout << "\nPatient deleted";
- fout.close();
- }
- return 0;
- }
- int updPat()
- {
- int compare;
- cout<<"\nUpdating a patient";
- cout<<"\nEnter patient number";
- cin>>patNo;
- ifstream fin(FileName1, ios::binary);
- fin.seekg(patNo*sizeof(a_pat));
- fin.get((char*)&a_pat,sizeof(a_pat));
- fin.close();
- compare=strcmpi(a_pat.flag,"0");
- if (compare != 0)
- {
- ofstream fout(FileName1, ios::in);
- fout.seekp(patNo * sizeof(a_pat));
- cin.get();
- cout << "\nEnter patients first name ";
- cin.getline(a_pat.patFName, sizeof(a_pat.patFName));
- cout << "\nEnter patients surname ";
- cin.getline(a_pat.patSName, sizeof(a_pat.patSName));
- cout << "\nEnter patients phone number ";
- cin.getline(a_pat.patNum, sizeof(a_pat.patNum));
- cout << "\nEnter patients birthday ";
- cin.getline(a_pat.patBday, sizeof(a_pat.patBday));
- cout << "\nEnter todays date ";
- cin.getline(a_pat.patDateJoin, sizeof(a_pat.patDateJoin));
- cout << "\nEnter patients address line 1 ";
- cin.getline(a_pat.addLine1, sizeof(a_pat.addLine1));
- cout << "\nEnter patients address line 2 ";
- cin.getline(a_pat.addLine2, sizeof(a_pat.addLine2));
- cout << "\nEnter patients city ";
- cin.getline(a_pat.city, sizeof(a_pat.city));
- cout << "\nEnter patients postcode ";
- cin.getline(a_pat.postcode, sizeof(a_pat.postcode));
- strcpy(a_pat.flag, "1");
- fout.write((char*) &a_pat, sizeof(a_pat));
- clrscr();
- cout << "Patient Updated\n";
- fout.close();
- } else {
- cout << "\nNo patient to update";
- }
- return 0;
- }
- int createEmptyFileV()
- {
- char option;
- cout << "Are you sure you want to create empty file? This will erase ALL data! Y/N" << endl;
- cin >> option;
- if (option == 'Y')
- {
- createEmptyFile();
- }
- else
- {
- mainMenu();
- }
- return 0;
- }
- int createEmptyFile()
- {
- ofstream fout(FileName1,ios::binary);
- strcpy(a_pat.flag,"0");
- for(patNo=0;patNo<200;patNo++)
- {
- fout.write((char*)&a_pat,sizeof(a_pat));
- }//endfor
- fout.close();
- cout << "File created";
- return 0;
- }
- int reWriteAppFile()
- {
- int count;
- ofstream fout(appFile, ios::binary);
- fout.write((char*) &nac, sizeof (nac));
- for (count = 0; count < nai; count++)
- {
- fout.write((char*) &appNo[count], strlen(appNo[count]));
- fout.write("\n", 1);
- fout.write((char*) &appPatNo[count], strlen(appPatNo[count]));
- fout.write("\n", 1);
- fout.write((char*) &appDay[count], strlen(appDay[count]));
- fout.write("\n", 1);
- fout.write((char*) &appTime[count], strlen(appTime[count]));
- fout.write("\n", 1);
- fout.write((char*) &appDenName[count], strlen(appDenName[count]));
- fout.write("\n", 1);
- fout.write((char*) &appReason[count], strlen(appReason[count]));
- fout.write("\n", 1);
- }//endfor
- fout.close();
- return 0;
- }
- int readBackAppFile()
- {
- int count;
- ifstream fin(appFile,ios::binary);
- fin.read((char*)&nac,sizeof(nac));
- sscanf(&nac[0],"%d",&nai);
- for( count=0;count<nai;count++)
- {
- fin.getline(appNo[count],sizeof(appNo[count]));
- fin.getline(appPatNo[count],sizeof(appPatNo[count]));
- fin.getline(appDay[count],sizeof(appDay[count]));
- fin.getline(appTime[count],sizeof(appTime[count]));
- fin.getline(appDenName[count],sizeof(appDenName[count]));
- fin.getline(appReason[count],sizeof(appReason[count]));
- }//endfor
- fin.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement