Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <cstring>
- const int D_ID = 3;
- #define FIRST 8
- #define LAST 11
- #define NAME 15
- #define CITY 10
- #define SPEC 8
- const int MAXPAC = 100;
- using namespace std;
- struct doctor {
- char id[D_ID];
- char firstname[FIRST];
- char lastname[LAST];
- char name[NAME]; //name of hospital, where this doc is working
- char city[CIT];
- char specialization[SPEC];
- int queue;
- char opinion;
- char firstname2[FIRST];
- char lastname2[LAST];
- };
- void menu( doctor D[], int how_many_docs );
- void menumain( int choice );
- void menu_search( doctor D[], const int how_many_docs );
- void menu_delete();
- void add_doc( doctor D[], int & how_many_docs );
- void delete_doc( doctor D[], int & how_many_docs );
- int ID( doctor D[], const int how_many_docs, char ID[]);
- void search_ID( doctor D[], const int how_many_docs );
- void list_head();
- void list_doc( doctor D[] );
- void lista_alldoc( doctor D[], const int how_many_docs );
- void add_opinion(doctor D[], int&how_many_docs);
- void add (const doctor doc);
- void inizialize (doctor D[], int &how_many_docs)
- int main()
- {
- doctor * D;
- int how_many_docs, how_many_docs2;
- how_many_docs2 = how_many_docs;
- D = new doctor[ how_many_docs ];
- menu( D, how_many_docs );
- delete[] D;
- }
- void menumain ( int choice )
- {
- switch( choice )
- {
- case 1: {
- cout << endl;
- cout << "DATABASE" << endl;
- cout << "------------------------" << endl;
- cout << "MENU MAIN :" << endl;
- cout << "------------------------" << endl;
- cout << "1 - Add doc" << endl;
- cout << "2 - delete doc" << endl;
- cout << "3 - Edit doc" << endl;
- cout << "4 - search doc" << endl;
- cout << "5 - list doc" << endl;
- cout << "0 - exit" << endl;
- cout << ">>";
- break;
- }
- case 2: {
- cout << endl;
- cout << "MENU SEARCH : " << endl;
- cout << "------------------------" << endl;
- cout << "1 - search doc (lastname)" << endl;
- cout << "2 - search doc (specialization)" << endl;
- cout << "3 - search doc by hospital" << endl;
- cout << "4 - search doc by lowest queue" << endl;
- cout << "5 - search doc by id" << endl;
- cout << "0 - comeback to main menu" << endl;
- cout << ">>";
- break;
- }
- case 3: {
- cout << endl;
- cout << "MENU DELETE : " << endl;
- cout << "------------------------" << endl;
- cout << "1 - delete doc by id" << endl;
- cout << "0 - comeback" << endl;
- cout << ">>";
- break;
- }
- }
- }
- void menu( doctor D[], int how_many_docs )
- {
- int menu_option;
- do {
- menumain( 1 );
- cin >> menu_option;
- switch( menu_option )
- {
- case 1: add_doc( D, how_many_docs );
- break;
- case 2: menu_delete();
- break;
- //case 3: menu_edit();
- //break;
- case 4: menu_search( D, how_many_docs );
- break;
- case 5: list_alldocs( D, how_many_docs );
- break;
- }
- } while( menu_option != 0 );
- }
- void menu_search( doctor D[], const int how_many_docs )
- {
- int menu_option;
- do {
- menumain( 2 );
- cin >> menu_option;
- switch( menu_option )
- {
- case 1:;
- break;
- case 2:;
- break;
- case 3:;
- break;
- case 4:;
- break;
- case 5: search_ID( D, how_many_docs );
- break;
- }
- } while( menu_option != 0 );
- }
- void menu_delete()
- {
- int menu_option;
- do {
- menumain( 3 );
- cin >> menu_option;
- switch( menu_option )
- {
- case 1:;
- break;
- case 2:;
- break;
- }
- } while( menu_option != 0 );
- }
- //-----------FUNKCJE GLOWNE---------------
- void add_doc( doctor D[], int & how_many_docs )
- {
- int n;
- cout << "how many docs to add : ";
- cin >> n;
- string id;
- if (how_many_docs<MAXPAC)
- {
- for( int i = 0; i < n; i++ )
- {
- cout << "ID : ";
- cin >> id;
- if (L[i].id!=id)
- {
- L[i].id==id;
- cout << "firstname : ";
- cin >> L[ i ].firstname;
- cout << "lastname : ";
- cin >> L[ i ].lastname;
- cout << "hospital : ";
- cin >> L[ i ].name;
- cout << "city where hospital is ";
- cin >> L[ i ].city;
- cout << "Specialization : ";
- cin >> L[ i ].specialization;
- cout << "how many patient in the queue : ";
- cin >> L[ i ].queue;
- how_many_docs++;
- }
- }
- }
- }
- void add (const doctor doc)
- {
- cout << setw(sizeof(doc.id)+2) << doc.id;
- cout << setw(sizeof(doc.firstname)+2) << doc.firstname;
- cout << setw(sizeof(doc.lastname)+2) << doc.lastname;
- cout << setw(sizeof(doc.name)+2) << doc.name;
- cout << setw(sizeof(doc.city)+2) << doc.city;
- cout << setw(sizeof(doc.specialization)+2) << doc.specialization;
- cout << setw(sizeof(doc.queue)+2) << doc.queue;
- cout << setw(sizeof(doc.opinion)+2) << doc.opinion;
- cout << setw(sizeof(doc.firstname2)+2) << doc.firstname2;
- cout << setw(sizeof(doc.lastname2)+2) << doc.lastname2;
- cout << endl;
- }
- //---------------SEARCH-----------------
- int ID( doctor D[], const int how_many_docs, char id[] )
- {
- for( int i = 0; i < how_many_docs; i++ )
- if( strcmp( L[ i ].id, id ) == 0 ) return( i );
- return( - 1 );
- }
- void search_ID( doctor D[], const int how_many_docs )
- {
- char id[D_ID];
- int ind;
- cout << "ID : ";
- cin >> id;
- if(( ind = ID( L, how_many_docs, id ) ) != - 1 )
- {
- list_head();
- list_doc( D + ind );
- }
- else
- {
- cout << "person with this id isn't exist'" << id << endl;
- system( "pause" );
- }
- }
- //---------------LIST------------------------
- void list_head()
- {
- cout << endl;
- cout << "|ID | fname | lname | hospital | city | specialization | queue | " << endl;
- cout << "______________________________________________________________________" << endl;
- }
- void list_doc( doctor D[] )
- {
- cout << D->id;
- cout << setw( 10 ) << D->firstname;
- cout << setw( 15 ) << D->lastname;
- cout << setw( 10 ) << D->name;
- cout << setw( 10 ) << D->city;
- cout << setw( 15 ) << D->specialization;
- cout << setw( 10 ) << D->queue;
- cout << endl;
- }
- void list_alldoc( doctor D[], const int how_many_docs )
- {
- list_head();
- for( int i = 0; i < how_many_docs; i++ )
- list_doc( L + i );
- cout << "________________________________________________________________" << endl;
- cout << "hwo many docs : " << how_many_docs << endl;
- cout << endl;
- char ans;
- char yes;
- int i;
- cout<<"wanna know sth more about any doc y/n ";
- cin>>ans;
- if (ans==yes)
- {
- cout<<"type id ";
- cin>>i;
- system ("cls");
- cout<<L[i].opinion<<L[i].firstname2<<L[i].lastname2;
- }
- else system ("cls");
- }
- void add_opinion(doctor D[], int&how_many_docs)
- {
- string lastname;
- cout<<"type lastname of doc";
- cin>> lastname;
- for (int i=0; i<how_many_docs; i++)
- {
- if (L[i].lastname!=lastname)
- {
- cout<<"type opinion ";
- cin>> L[i].opinion;
- cout<<"type your firstname: ";
- cin>> L[i].firstname2;
- cout<<"type your lastname: ";
- cin>> L[i].lastname2;
- }
- }
- }
- void inicialize(doctor D[], int &how_many_docs)
- {
- strcpy(L[0].id,"001");
- strcpy(L[0].firstname,"John");
- strcpy(L[0].lastname,"Doe");
- strcpy(L[0].name,"st. patrick hospital");
- strcpy(L[0].city,"Cork");
- strcpy(L[0].specialization,"surgery");
- strcpy(L[0].queue,2);
- strcpy(L[0].opinion,"nice one, he knows everything!");
- strcpy(L[0].firstname2,"John");
- strcpy(L[0].lastname2,"Snow");
- how_many_docs=1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement