1. // This is a .cpp file run this with a C++ code editor
  2.  
  3. #include <iostream>
  4. #include <conio.h>
  5. #include <fstream>
  6. #include <stdio.h>
  7. #include <string.h>
  8.  
  9. //////// MADE BY- PRANAV BHILE
  10. //////// 2019B5PS0818G
  11.  
  12. using namespace std;
  13.  
  14. void screen();
  15. void patient();
  16. void doctor();
  17.  
  18.  
  19. struct meds{
  20. char name[100];
  21. char id;
  22. int quantity;
  23. float cost;
  24.  
  25. public:
  26.  
  27. void disp(){
  28. if (quantity >0 ){
  29. cout<<"\nName : "<<name;
  30. cout<<"\nCost : "<<cost;
  31. }
  32. else {
  33. cout<<"\n"<<name<<"is out of stock";
  34. }
  35. }
  36. void inp(){
  37. cout<<"\nEnter name of medicine ";
  38. scanf( "%s",name);
  39. cout<<"\nEnter cost ";
  40. cin>> cost;
  41. cout<<"\nEnter quantity available";
  42. cin>> quantity;
  43. cout<<"\nEnter your id ";
  44. cin>> id;
  45. }
  46.  
  47. }meds[100];
  48.  
  49. class doc {
  50. char pass[50];
  51.  
  52. public:
  53. char name[50];
  54. int experience;
  55. char address[1000];
  56. char spec[50];
  57. void input();
  58. int login();
  59.  
  60. }obj;
  61.  
  62. void doc::input(){
  63. ofstream file_obj;
  64.  
  65. file_obj.open("doc.txt", ios::app);
  66.  
  67. cout<<"Enter name ";
  68. scanf( "%s",obj.name);
  69. cout<<"Enter password ";
  70. scanf( "%s",obj.pass);
  71. cout<<"Enter years of experience ";
  72. cin >> obj.experience;
  73. cout<<"Enter address/ locality of clinic ";
  74. scanf( "%s",obj.address);
  75. cout<<"Enter specialization ";
  76. scanf( "%s",obj.spec);
  77.  
  78. file_obj.write((char*)&obj, sizeof(obj));
  79. file_obj.close();
  80.  
  81. }
  82.  
  83. int doc::login()
  84. {
  85. int id =0;
  86. ifstream file_obj;
  87. file_obj.open("doc.txt", ios::in);
  88.  
  89. int flag =1;
  90. char nam[50];
  91. char pas[50];
  92.  
  93. cout<<"Enter name\n";
  94. cin >> nam;
  95. cout<<"Enter pass\n";
  96. cin >> pas;
  97.  
  98. while (!file_obj.eof() && flag ==1) {
  99.  
  100. file_obj.read((char*)&obj, sizeof(obj));
  101.  
  102. if ((!strcmp(nam,obj.name))&&(!strcmp(pas,obj.pass))){
  103. flag = 0;
  104. }
  105.  
  106. id++;
  107.  
  108. }
  109. if (flag==1){
  110. cout<<"Not found ";
  111. return -1;
  112. }
  113. if (flag==0){
  114. cout<<"found "<<id;
  115. return id;
  116. }
  117. file_obj.close();
  118.  
  119. }
  120.  
  121. void doctor(){
  122.  
  123. char c ='y';
  124.  
  125. int k = -2;
  126. int i;
  127. doc obj;
  128. while (c == 'y'){
  129. cout<<"a. Register\n";
  130. cout<<"b. Login\n";
  131. cin >> c;
  132.  
  133. switch (c)
  134. {
  135. case 'a':obj.input();
  136. break;
  137. case 'b':k = obj.login();
  138. break;
  139. }
  140. }
  141.  
  142. if (k >=0)
  143. {
  144. char f ='n';
  145. do{
  146. cout<<"\nDo you want to add medicine? (y/n)";
  147. cin >>f;
  148. if (f == 'y'){
  149. cout<<"\nEnter medicine id ";
  150. cin >>i;
  151. meds[i].inp();
  152.  
  153. }
  154. }while(f != 'n');
  155. }
  156. }
  157.  
  158. void disp(){
  159. cout<<"\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t";
  160. cout<<"\t\tMediServ\n\n";
  161. cout<<"\t\t\t\t\t\t\t -By Pranav Bhile\n\n\n";
  162.  
  163. }
  164.  
  165. void screen(){
  166. int c = 0;
  167. while (c == 0){
  168. cout<<"Login as (Enter the number next to choice)\n";
  169. cout<<"1. Patient\n";
  170. cout<<"2. Doctor \n";
  171. cout<<"3. Chemist\n";
  172. cout<<"4. Quit\n";
  173. cin >>c;
  174. switch (c)
  175. {
  176. case 1: patient();
  177. break;
  178. case 2:
  179. case 3: doctor();
  180. break;
  181. case 4:
  182. break;
  183. default:cout<<"Invalid entry\n";
  184. c=0;
  185.  
  186. }
  187. cout<<"\nPress 0 to do again";
  188. cin >> c;
  189.  
  190. if (c!=0){
  191. cout <<"\n\n\n\n\n\t\t\t\t\tMADE BY PRANAV ARVIND BHILE";
  192.  
  193. }
  194. }
  195.  
  196. }
  197.  
  198. void appoi(){
  199.  
  200. int flag =1;
  201. char c[100];
  202. ifstream file_obj;
  203. file_obj.open("doc.txt");
  204.  
  205. cout<<"What type of doctor do you need?";
  206. scanf("%s", c);
  207.  
  208. while ((!file_obj.eof())&& flag == 1) {
  209. file_obj.read((char*)&obj, sizeof(obj));
  210.  
  211. if (!strcmp(obj.spec,c))
  212. {
  213. flag = 0;
  214. cout<<"\nName of the doctor is"<<obj.name;
  215. cout<<"\nLocation of the clinic is"<<obj.address;
  216. }
  217. }
  218. if (flag==1){
  219. cout<<"No Doctor found with specifics";
  220. }
  221.  
  222. }
  223.  
  224. void buy(){
  225.  
  226. int flag = 1;
  227. char na[100];
  228. cout<<"Enter the name of medicine that you need.";
  229. scanf("%s", na);
  230. int i;
  231. for (i =0;i<=100;i++){
  232. if (!strcmp(meds[i].name,na)){
  233. meds[i].disp();
  234. flag = 0;
  235.  
  236. }
  237. }
  238. if (flag==1){
  239. cout<<"\nOut of stock";
  240. }
  241. }
  242.  
  243. void patient(){
  244. char c1;
  245. int c2 =0;
  246. char address[1000];
  247. cout <<"Enter location\n";
  248. cin >> address;
  249. cout<<"\nIs this an emergency(y/n) ";
  250. cin>> c1;
  251. if (c1=='y') {
  252. cout<<"\nCalling for medical services";
  253. c2=1;
  254. }
  255.  
  256. while(!c2)
  257. {
  258. cout<<"\n1.Do you want to make an appointment?";
  259. cout<<"\n2.Do you want to buy medicine?";
  260. cin >>c2;
  261.  
  262. switch (c2){
  263. case 1: appoi();
  264. break;
  265. case 2: buy();
  266. break;
  267. default : cout<<"\nInvalid entry ";
  268. c2 =0;
  269. break;
  270. }
  271. }
  272. }
  273.  
  274.  
  275. int main()
  276. {
  277. disp();
  278. screen();
  279. return 0;
  280. }