Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <cstring>
  5.  
  6. const int D_ID = 3;
  7. #define FIRST 8
  8. #define LAST 11
  9. #define NAME 15
  10. #define CITY 10
  11. #define SPEC 8
  12. const int MAXPAC = 100;
  13.  
  14. using namespace std;
  15.  
  16. struct doctor {
  17.     char id[D_ID];
  18.     char firstname[FIRST];
  19.     char lastname[LAST];
  20.     char name[NAME]; //name of hospital, where this doc is working
  21.     char city[CIT];
  22.     char specialization[SPEC];
  23.     int queue;
  24.     char opinion;
  25.     char firstname2[FIRST];
  26.     char lastname2[LAST];
  27. };
  28.  
  29. void menu( doctor D[], int how_many_docs );
  30. void menumain( int choice );
  31. void menu_search( doctor D[], const int how_many_docs );
  32. void menu_delete();
  33. void add_doc( doctor D[], int & how_many_docs );
  34. void delete_doc( doctor D[], int & how_many_docs );
  35. int ID( doctor D[], const int how_many_docs, char ID[]);
  36. void search_ID( doctor D[], const int how_many_docs );
  37. void list_head();
  38. void list_doc( doctor D[] );
  39. void lista_alldoc( doctor D[], const int how_many_docs );
  40. void add_opinion(doctor D[], int&how_many_docs);
  41. void add (const doctor doc);
  42. void inizialize (doctor D[], int &how_many_docs)
  43.  
  44. int main()
  45. {
  46.     doctor * D;
  47.     int how_many_docs, how_many_docs2;
  48.  
  49.     how_many_docs2 = how_many_docs;
  50.  
  51.     D = new doctor[ how_many_docs ];
  52.  
  53.     menu( D, how_many_docs );
  54.  
  55.     delete[] D;
  56.  
  57. }
  58.  
  59. void menumain ( int choice )
  60. {
  61.     switch( choice )
  62.     {
  63.         case 1: {
  64.             cout << endl;
  65.             cout << "DATABASE" << endl;
  66.             cout << "------------------------" << endl;
  67.             cout << "MENU MAIN :" << endl;
  68.             cout << "------------------------" << endl;
  69.             cout << "1 - Add doc" << endl;
  70.             cout << "2 - delete doc" << endl;
  71.             cout << "3 - Edit doc" << endl;
  72.             cout << "4 - search doc" << endl;
  73.             cout << "5 - list doc" << endl;
  74.             cout << "0 - exit" << endl;
  75.             cout << ">>";
  76.             break;
  77.         }
  78.         case 2: {
  79.             cout << endl;
  80.             cout << "MENU SEARCH : " << endl;
  81.             cout << "------------------------" << endl;
  82.             cout << "1 - search doc (lastname)" << endl;
  83.             cout << "2 - search doc (specialization)" << endl;
  84.             cout << "3 - search doc by hospital" << endl;
  85.             cout << "4 - search doc by lowest queue" << endl;
  86.             cout << "5 - search doc by id" << endl;
  87.             cout << "0 - comeback to main menu" << endl;
  88.             cout << ">>";
  89.             break;
  90.         }
  91.         case 3: {
  92.             cout << endl;
  93.             cout << "MENU DELETE : " << endl;
  94.             cout << "------------------------" << endl;
  95.             cout << "1 - delete doc by id" << endl;
  96.             cout << "0 - comeback" << endl;
  97.             cout << ">>";
  98.             break;
  99.         }
  100.     }
  101. }
  102.  
  103. void menu( doctor D[], int how_many_docs )
  104. {
  105.     int menu_option;
  106.  
  107.     do {
  108.         menumain( 1 );
  109.         cin >> menu_option;
  110.         switch( menu_option )
  111.         {
  112.             case 1: add_doc( D, how_many_docs );
  113.                 break;
  114.             case 2: menu_delete();
  115.                 break;
  116.                 //case 3: menu_edit();
  117.                 //break;
  118.             case 4: menu_search( D, how_many_docs );
  119.                 break;
  120.             case 5: list_alldocs( D, how_many_docs );
  121.                 break;
  122.         }
  123.  
  124.     } while( menu_option != 0 );
  125.  
  126. }
  127. void menu_search( doctor D[], const int how_many_docs )
  128. {
  129.     int menu_option;
  130.     do {
  131.         menumain( 2 );
  132.         cin >> menu_option;
  133.         switch( menu_option )
  134.         {
  135.             case 1:;
  136.                 break;
  137.             case 2:;
  138.                 break;
  139.             case 3:;
  140.                 break;
  141.             case 4:;
  142.                 break;
  143.             case 5: search_ID( D, how_many_docs );
  144.                 break;
  145.         }
  146.     } while( menu_option != 0 );
  147.  
  148. }
  149.  
  150. void menu_delete()
  151. {
  152.     int menu_option;
  153.     do {
  154.         menumain( 3 );
  155.         cin >> menu_option;
  156.         switch( menu_option )
  157.         {
  158.             case 1:;
  159.                 break;
  160.             case 2:;
  161.                 break;
  162.         }
  163.     } while( menu_option != 0 );
  164.  
  165. }
  166.  
  167. //-----------FUNKCJE GLOWNE---------------
  168.  
  169. void add_doc( doctor D[], int & how_many_docs )
  170. {
  171.     int n;
  172.     cout << "how many docs to add : ";
  173.     cin >> n;
  174.     string id;
  175.  
  176.     if (how_many_docs<MAXPAC)
  177.     {
  178.         for( int i = 0; i < n; i++ )
  179.         {
  180.             cout << "ID : ";
  181.             cin >> id;
  182.             if (L[i].id!=id)
  183.             {
  184.             L[i].id==id;
  185.             cout << "firstname : ";
  186.             cin >> L[ i ].firstname;
  187.             cout << "lastname : ";
  188.             cin >> L[ i ].lastname;
  189.             cout << "hospital : ";
  190.             cin >> L[ i ].name;
  191.             cout << "city where hospital is ";
  192.             cin >> L[ i ].city;
  193.             cout << "Specialization : ";
  194.             cin >> L[ i ].specialization;
  195.             cout << "how many patient in the queue : ";
  196.             cin >> L[ i ].queue;
  197.             how_many_docs++;
  198.             }
  199.         }
  200.     }
  201. }
  202. void add (const doctor doc)
  203. {
  204.     cout << setw(sizeof(doc.id)+2)            << doc.id;
  205.     cout << setw(sizeof(doc.firstname)+2)          << doc.firstname;
  206.     cout << setw(sizeof(doc.lastname)+2)      << doc.lastname;
  207.     cout << setw(sizeof(doc.name)+2)         << doc.name;
  208.     cout << setw(sizeof(doc.city)+2)        << doc.city;
  209.     cout << setw(sizeof(doc.specialization)+2)   << doc.specialization;
  210.     cout << setw(sizeof(doc.queue)+2)       << doc.queue;
  211.     cout << setw(sizeof(doc.opinion)+2)        << doc.opinion;
  212.     cout << setw(sizeof(doc.firstname2)+2)         << doc.firstname2;
  213.     cout << setw(sizeof(doc.lastname2)+2)     << doc.lastname2;
  214.     cout << endl;
  215. }
  216. //---------------SEARCH-----------------
  217.  
  218. int ID( doctor D[], const int how_many_docs, char id[] )
  219. {
  220.     for( int i = 0; i < how_many_docs; i++ )
  221.         if( strcmp( L[ i ].id, id ) == 0 ) return( i );
  222.  
  223.     return( - 1 );
  224. }
  225.  
  226. void search_ID( doctor D[], const int how_many_docs )
  227. {
  228.     char id[D_ID];
  229.     int ind;
  230.  
  231.     cout << "ID : ";
  232.     cin >> id;
  233.     if(( ind = ID( L, how_many_docs, id ) ) != - 1 )
  234.     {
  235.         list_head();
  236.         list_doc( D + ind );
  237.     }
  238.     else
  239.     {
  240.         cout << "person with this id isn't exist'" << id << endl;
  241.         system( "pause" );
  242.     }
  243. }
  244.  
  245.  
  246. //---------------LIST------------------------
  247.  
  248. void list_head()
  249. {
  250.     cout << endl;
  251.     cout << "|ID |  fname   |  lname  | hospital | city | specialization | queue | " << endl;
  252.     cout << "______________________________________________________________________" << endl;
  253.  
  254. }
  255.  
  256. void list_doc( doctor D[] )
  257. {
  258.     cout << D->id;
  259.     cout << setw( 10 ) << D->firstname;
  260.     cout << setw( 15 ) << D->lastname;
  261.     cout << setw( 10 ) << D->name;
  262.     cout << setw( 10 ) << D->city;
  263.     cout << setw( 15 ) << D->specialization;
  264.     cout << setw( 10 ) << D->queue;
  265.     cout << endl;
  266. }
  267.  
  268. void list_alldoc( doctor D[], const int how_many_docs )
  269. {
  270.     list_head();
  271.     for( int i = 0; i < how_many_docs; i++ )
  272.         list_doc( L + i );
  273.  
  274.     cout << "________________________________________________________________" << endl;
  275.     cout << "hwo many docs : " << how_many_docs << endl;
  276.     cout << endl;
  277.  
  278.     char ans;
  279.     char yes;
  280.     int i;
  281.     cout<<"wanna know sth more about any doc y/n ";
  282.     cin>>ans;
  283.     if (ans==yes)
  284.     {
  285.         cout<<"type id ";
  286.         cin>>i;
  287.         system ("cls");
  288.         cout<<L[i].opinion<<L[i].firstname2<<L[i].lastname2;
  289.     }
  290.     else system ("cls");
  291. }
  292.  
  293. void add_opinion(doctor D[], int&how_many_docs)
  294. {
  295.     string lastname;
  296.     cout<<"type lastname of doc";
  297.     cin>> lastname;
  298.     for (int i=0; i<how_many_docs; i++)
  299.     {
  300.         if (L[i].lastname!=lastname)
  301.         {
  302.             cout<<"type opinion ";
  303.             cin>> L[i].opinion;
  304.  
  305.             cout<<"type your firstname: ";
  306.             cin>> L[i].firstname2;
  307.  
  308.             cout<<"type your lastname: ";
  309.             cin>> L[i].lastname2;
  310.         }
  311.     }
  312. }
  313. void inicialize(doctor D[], int &how_many_docs)
  314. {
  315.     strcpy(L[0].id,"001");
  316.     strcpy(L[0].firstname,"John");
  317.     strcpy(L[0].lastname,"Doe");
  318.     strcpy(L[0].name,"st. patrick hospital");
  319.     strcpy(L[0].city,"Cork");
  320.     strcpy(L[0].specialization,"surgery");
  321.     strcpy(L[0].queue,2);
  322.     strcpy(L[0].opinion,"nice one, he knows everything!");
  323.     strcpy(L[0].firstname2,"John");
  324.     strcpy(L[0].lastname2,"Snow");
  325.  
  326.  
  327.     how_many_docs=1;
  328. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement