• Source
    1. #include <iostream>
    2. #include <fstream>
    3. #include <cstring>
    4. #include <process.h>
    5. using namespace std;
    6. char ch, pass[20];
    7. void PAT();
    8. struct address //for address
    9. {
    10. char addr[60], district[20], state[30], country[20];
    11. };
    12. class patient //class containing patient info
    13. {
    14. char name[40];
    15. int age;
    16. char gender[10];
    17. int nods;
    18. char fname[40];
    19. int phoneno;
    20. char naphy[40];
    21. int roomno;
    22. char bgroup[4];
    23. int chargep;
    24. char attendant[40];
    25. char dept[40];
    26. address ap;
    27. public:
    28. int pid;
    29. void padd();
    30. void pview();
    31. void pviewf();
    32. void pmodify();
    33. }p, t, s, u, a;
    34. void patient::padd() //funtion to add a patient record
    35. {
    36. cout<<"\nEnter password to add:"; cin.getline(pass, 20);
    37. if (strcmp(pass, "vampuhi")==0)
    38. {
    39. cout<<"\nEnter patient ID:"; cin>>pid;
    40. cin.get(ch);
    41. cout<<"\nEnter name of the patient:"; cin.getline(name, 40);
    42. cout<<"\nEnter age of the patient:"; cin>>age;
    43. cin.get(ch);
    44. cout<<"\nGender of patient:"; cin.getline(gender, 10);
    45. cout<<"\nNumber of days stayed:"; cin>>nods;
    46. cin.get(ch);
    47. cout<<"\nEnter the patient's father name:"; cin.getline(fname, 40);
    48. cout<<"\nEnter address:";
    49. cout<<"\n\tStreet:"; cin.getline(ap.addr, 60);
    50. cout<<"\n\tDistrict:"; cin.getline(ap.district, 20);
    51. cout<<"\n\tState:"; cin.getline(ap.state, 30);
    52. cout<<"\n\tCountry:"; cin.getline(ap.country, 20);
    53. cout<<"\nEnter phone number:"; cin>>phoneno;
    54. cin.get(ch);
    55. cout<<"\nEnter name of physician:"; cin.getline(naphy, 40);
    56. cout<<"\nEnter room number:"; cin>>roomno;
    57. cin.get(ch);
    58. cout<<"\nBlood Group:"; cin.getline(bgroup, 4);
    59. cout<<"\nEnter charge per day:"; cin>>chargep;
    60. cin.get(ch);
    61. cout<<"\nEnter attendant:"; cin.getline(attendant, 40);
    62. cout<<"\nEnter department in which admitted:"; cin.getline(dept, 40);
    63. }
    64. else
    65. {
    66. cout<<"\nGoing back to patients menu!";
    67. PAT();
    68. }
    69. }
    70. void patient::pview() //function to view one patient record
    71. {
    72. cin.get(ch);
    73. cout<<"\nEnter password to view full information:"; cin.getline(pass, 20);
    74. if (strcmp(pass, "vampuhi")==0)
    75. {
    76. cout<<"\nPatient ID:"<<pid;
    77. cout<<"\nName:"<<name;
    78. cout<<"\nAge:"<<age;
    79. cout<<"\nGender:"<<gender;
    80. cout<<"\nNo. of days stayed:"<<nods;
    81. cout<<"\nFather's name:"<<fname;
    82. cout<<"\nAddress:"<<"\t"<<ap.addr<<"\t"<<ap.district<<"\t"<<ap.state<<"\t"<<ap.country;
    83. cout<<"\nPhone number:"<<phoneno;
    84. cout<<"\nPhysician:"<<naphy;
    85. cout<<"\nRoom number:"<<roomno;
    86. cout<<"\nBlood Group:"<<bgroup;
    87. cout<<"\nTotal charge:"<<chargep*nods;
    88. cout<<"\nAttendant:"<<attendant;
    89. cout<<"\nDepartment in which admitted:"<<dept;
    90. }
    91. else
    92. { cout<<"\nGoing back to patients menu!";
    93. PAT();
    94. }
    95. }
    96. void patient::pviewf() //function to view all patient record
    97. {
    98. cout<<"\n\nPateint ID:"<<pid;
    99. cout<<"\nName:"<<name;
    100. cout<<"\nAge:"<<age;
    101. cout<<"\nGender:"<<gender;
    102. cout<<"\nTotal charge:"<<chargep*nods;
    103. cout<<"\nPhysician:"<<naphy;
    104. cout<<"\nDepartment in which admitted:"<<dept;
    105. }
    106. void patient::pmodify() //function to modify a patient record
    107. {
    108. address apm;
    109. int ag, n, ph, rno;
    110. char nphy[40], depart[40];
    111. cin.get(ch);
    112. cout<<"\nEnter password to modify:"; cin.getline(pass, 20);
    113. if (strcmp(pass, "vampuhi")==0)
    114. {
    115. cout<<"\nPatient ID:"<<pid;
    116. cout<<"\nName of patient:"<<name;
    117. cout<<"\nEnter new age (enter -1 to keep it same):"; cin>>ag;
    118. age=ag;
    119. cout<<"\nEnter new no. of days stayed (enter -2 to keep it same):"; cin>>n;
    120. nods=n;
    121. cout<<"\nEnter new address (enter addno to keep it same):";
    122. cin.getline(apm.addr, 60);
    123. if ((strcmp(apm.addr, "addno")!=0)|(strcmp(apm.addr, "Addno")!=0))
    124. {
    125. cin.getline(apm.district, 20);
    126. cin.getline(apm.state, 30);
    127. cin.getline(apm.country, 20);
    128. strcpy(ap.addr, apm.addr);
    129. strcpy(ap.district, apm.district);
    130. strcpy(ap.state, apm.state);
    131. strcpy(ap.country, apm.country);
    132. }
    133. cout<<"\nEnter new phone no. (enter -3 to keep it same):"; cin>>ph;
    134. phoneno=ph;
    135. cout<<"\nEnter new room number (enter -4 to keep it same):"; cin>>rno;
    136. roomno=rno;
    137. cout<<"\nEnter name of new physician (enter phyno to keep it same):"; cin.getline(nphy, 40);
    138. if(strcmp(nphy, "phyno")!=0)
    139. strcpy(naphy, nphy);
    140. cout<<"\nEnter new department (enter depno to keep it same):"; cin.getline(depart, 40);
    141. if(strcmp(depart, "depno")!=0)
    142. strcpy(dept, depart);
    143. }
    144. else
    145. {
    146. cout<<"\nGoing back to patients menu!";
    147. PAT();
    148. }
    149. }
    150. int main()
    151. {
    152. PAT();
    153. return 0;
    154. }
    155. void PAT() //Patients menu!!
    156. {
    157. int choice, cs, id;
    158. long pos;
    159. char c='y', found='f', f='f';
    160. cout<<"\n\n";
    161. for (int i=0;i<10;i++)
    162. cout<<"-";
    163. cout<<"PATIENT MENU";
    164. for (int i=0;i<10;i++)
    165. cout<<"-";
    166. cout<<"\n\n\t1. Add a patient record.";
    167. cout<<"\n\t2. View a patient record.";
    168. cout<<"\n\t3. View all patients records.";
    169. cout<<"\n\t4. Modify a patient record.";
    170. cout<<"\n\t5. Delete a patient record.";
    171. cout<<"\n\t6. Exit.";
    172. cout<<"\n\t7. Return to main menu.";
    173. cout<<"\n\nEnter your choice (1-7):"; cin>>choice;
    174. cin.get(ch);
    175. switch (choice)
    176. {
    177. case 1:
    178. {
    179. cout<<"\n\n\nNote: Password is Required!\n";
    180. ofstream fout("Patients.txt", ios::app);
    181. while (c=='y'||c=='Y')
    182. {
    183. p.padd();
    184. fout.write((char *)&p, sizeof(p));
    185. cout<<"\nRecord added to file.";
    186. cout<<"\nWant to add more patient records?";
    187. cin>>c;
    188. }
    189. cout<<"\nWanna go to patients menu or to main menu?";
    190. cout<<"\n\t1. Patients menu.";
    191. cout<<"\n\t2. Main menu.";
    192. cout<<"\nEnter choice (1 or 2):";
    193. cin>>cs;
    194. if (cs==1) PAT();
    195. else main();
    196. fout.close();
    197. break;
    198. }
    199. case 2:
    200. {
    201. cout<<"\n\n\nNote: Password is Required!";
    202. cout<<"\n\nEnter ID of the patient to be viewed:";
    203. cin>>id;
    204. ifstream fi("Patients.txt");
    205. while (!fi.eof())
    206. {
    207. fi.read((char *)&t, sizeof(t));
    208. if (t.pid==id)
    209. {
    210. t.pview();
    211. f='t';
    212. break;
    213. }
    214. }
    215. if(f=='f')
    216. cout<<"\nID not found!!";
    217. fi.close();
    218. cout<<"\n\nWanna go to patients menu or to main menu?";
    219. cout<<"\n\t1. Patients menu.";
    220. cout<<"\n\t2. Main menu.";
    221. cout<<"\nEnter choice (1 or 2):";
    222. cin>>cs;
    223. if (cs==1) PAT();
    224. else main();
    225. break;
    226. }
    227. case 3:
    228. {
    229. ifstream fin("Patients.txt", ios::in);
    230. while (!fin.eof())
    231. {
    232. fin.read((char *)&u, sizeof(u));
    233. u.pviewf();
    234. }
    235. fin.close();
    236. cout<<"\n\nWanna go to patients menu or to main menu?";
    237. cout<<"\n\t1. Patients menu.";
    238. cout<<"\n\t2. Main menu.";
    239. cout<<"\nEnter choice (1 or 2):";
    240. cin>>cs;
    241. if (cs==1) PAT();
    242. else main();
    243. break;
    244. }
    245. case 4:
    246. {
    247. fstream fio("Patients.txt");
    248. cout<<"\n\n\nNote: Password is Required!";
    249. cout<<"\n\nEnter ID of the patient to be modified:";
    250. cin>>id;
    251. while (fio.read((char *)&s, sizeof(s)))
    252. {
    253. pos=fio.tellg();
    254. if(s.pid==id)
    255. {
    256. s.pmodify();
    257. fio.seekg(pos);
    258. fio.write((char *)&s, sizeof(s));
    259. }
    260. else
    261. cout<<"\nID not found!!";
    262. }
    263. fio.close();
    264. cout<<"\nWanna go to patients menu or to main menu?";
    265. cout<<"\n\t1. Patients menu.";
    266. cout<<"\n\t2. Main menu.";
    267. cout<<"\nEnter choice (1 or 2):";
    268. cin>>cs;
    269. if (cs==1) PAT();
    270. else main();
    271. break;
    272. }
    273. case 5:
    274. {
    275. ifstream fi("Patients.txt", ios::in);
    276. ofstream fo("temp.txt", ios::out);
    277. cout<<"\n\n\nNote: Password is Required!";
    278. cout<<"\nEnter password to delete:"; cin.getline(pass, 20);
    279. if (strcmp(pass, "vampuhi")==0)
    280. {
    281. cout<<"\n\nEnter ID of the patient to be deleted:";
    282. cin>>id;
    283. while (fi.read((char *)&a, sizeof(a)))
    284. {
    285. if(a.pid==id)
    286. {
    287. a.pviewf();
    288. found='t';
    289. cout<<"\n\nAre you sure you want to delete this patient record?(y/n)";
    290. cin>>c;
    291. if (c!='y'||c!='Y')
    292. fo.write((char *)&a, sizeof(a));
    293. }
    294. else
    295. fo.write((char *)&a, sizeof(a));
    296. }
    297. if (found=='f')
    298. cout<<"\n\nID not found!!";
    299. }
    300. fi.close();
    301. fo.close();
    302. remove ("Patients.txt");
    303. rename ("temp.txt", "Patients.txt");
    304. cout<<"\nWanna go to patients menu or to main menu?";
    305. cout<<"\n\t1. Patients menu.";
    306. cout<<"\n\t2. Main menu.";
    307. cout<<"\nEnter choice (1 or 2):";
    308. cin>>cs;
    309. if (cs==1) PAT();
    310. else main();
    311. break;
    312. }
    313. case 6:
    314. {
    315. cout<<"\n\n";
    316. for (int k=0; k<20; k++)
    317. cout<<"-";
    318. cout<<"Thank You for using our Software!!";
    319. for (int k=0; k<20; k++)
    320. cout<<"-";
    321. exit(0);
    322. break;
    323. }
    324. case 7:
    325. {
    326. cout<<"\n\nGoing back to main menu!!";
    327. int main();
    328. break;
    329. }
    330. default:
    331. {
    332. cout<<"\n\nWrong choice!!\nGoing back to patients menu!!";
    333. PAT();
    334. break;
    335. }
    336. }
    337. }