بسم الله الرحمن الرحيم
قوه شلونكم شخباركم
انا عندي مشكله و ابي احد يساعدني بفكرة حل انا مابي برنامج كامل لان ادري محد عنده وقت او له خلق
البرنامج شوي معقد و فيه تحدي من الدكتور لنا !!! :"(
البرنامج عباره عن نظام لوزارة الصحه احنا سوينا منه نسختين نسخه باللنك لست و الثانيه بال binary search trees و كان كل شي اوكيك
بس الحيين الدكتور يبي البرنامج بال hash !!! انا اول مره اخذ الهاش و ماعرفله كلش كلش
بكتب نص السؤال و محاولاتي فيه و نسخه البرنامج اللي باللنك لست !! انا مابي حل و السلام انا اعرف ابرمج بس مشكلتي ان الهاش محد علمني علييه
repeat programming assigment-2 by using hash -table instead of every linked list
hence ,you will have atotal of 6 different hash tables ,separate hash table for
clinic,doctor,nurses,staff members ,service companies, and patient
-use 4 different hash tfunctions of your choice
-use linear proping collision resolution for clinic hash table
-use chaining collisin resolution for doctors hashtable
-use chaininh with BST collision resolution for the patient hash table
-use dynamic hashing for the nurses hash table
-use rehashing collision resolution for staff members hash table
-use quadratic probing collision resolution for service companies hash table>
و يبينا نحلل time & space complexity لل برامج الثلاثه الترييز و الهاش و اللنك لست !!!!
هذا السؤال وانا اول مره اسمع بالهاش !!!!!!
:::::::::::::::::::::::::::::::::::::::::::::::::::::هذي محاولاتي الفاشله
#include<stdio.h>
#include<string.h>
#define MAX_CHAR 10 /*max number of characters in an identifier*/
#define TABLE_SIZE 13 /*max table size=prime number*/
#define IS_FULL(ptr) (!(ptr))
typedef struct{
char key[MAX_CHAR];/*other fields*/
}element;
element hash_table[TABLE_SIZE];
typedef struct list *list_pointer;
typedef struct list{
element item;
list_pointer link;
};
list_pointer hash_table[TABLE_SIZE];
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void init_table(element ht[])
{
int i;
for(i = 0; i < TABLE_SIZE; i++)
ht.key[0] = NULL;
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
int transform(char *key)
{/*simple additive approach to create a natural number that
is within the integer range */
int number =0;
while(*key)
number += *key++;
return number;
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
int hash(char *key)
{/* transform key to a natrual number , and return this
result modulus the table size*/
return (transform(key) % TABLE_SIZE);
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void linear_insert(element item, element ht[])
{/*insert the key into the table using the linear proping
teachique, exit the function if the table is full*/
int i, hash_value;
hash_value = hash(item.key);
i= hash_value;
while(strlen(ht.key)){
if(!strcmp(ht.key,item.key)){
printf("\n:::DUPLICATE ENTRY:::\n");
exit(1);
}
i=(i+1)%TABLE_SIZE;
if(i==hash_value){
printf("\n:::TABLE IS FULL:::\n");
exit(1);
}
}//while
ht=item;
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void chain_insert(element item,list_pointer ht[])
{/* insert the key into the table using chaining*/
list_pointer ptr,trail,lead;
int hash_value ;
hash_value= hash(item.key);
trail=NULL;
lead=ht[hash_value];
for(; lead;trial=lead,lead=lead->link)
if(!strcmp(lead->item.key,item.key)){
printf("\n:::THE KEY IS IN THE TABLE:::\n");
exit(1);
}
ptr=(list_pointer)malloc(sizeof(list));
if(IS_FULL(ptr)){
printf("\n:::NO MEMORY:::\n");
exit(1);
}
ptr->item=item;
ptr->link=NULL;
if(trial)
trial->link=ptr;
else
ht[hash_value]=ptr;
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
هذا برنامج شغال باللنك لست انا خليته اهنيه عشان الملف كبير حيل و ردو علي بلييز حتى لو بفكرت حل !!!!!بليييييييييييييييييييييييييييييييييييييز
::::::::::::::::::::::::::::::
/*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*
*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct patient{
char fn[10];
char ln[10];
char cid[12];
char app[15];
FILE *cond;
struct patient *next;
}patient;
typedef struct ser{
char cn[10];
char add[10];
char tel[7];
char wh[10];
struct ser *next;
}ser;
typedef struct staff {
char fn[10];
char ln[10];
char add[10];
char tel[7];
char wh[10];
struct staff *next;
}staff;
typedef struct nr {
char fn[10];
char ln[10];
char add[10];
char tel[7];
char wh[10];
struct nr *next;
}nr;
typedef struct dr{
char fn[10];
char ln[10];
char add[10];
char tel[7];
char wh[10];
struct patient *ptr;
struct dr *next;
}dr ;
typedef struct clinic{
char clinic_name[10];
struct dr *drptr;
struct nr *nrptr;
struct staff *stafptr;
struct ser *serptr;
struct clinic *next;
}clinic ;
typedef struct {
char hos[10];
struct clinic *ptr;
}node;
node arr[10];
char name[10], ln[10],fn[10];
int count=0;
//************************************************************************************************
// SEARCHING FUNCTIONS
//************************************************************************************************
int search_hosp (char name [10])
{
int i,j=-1;
for(i=0;i<count;i++)
if((strcmp(arr.hos,name))==0)
{
j=i;
break;
}
return j;
}// end of func
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
clinic * search_clinic (int i,char name[10])
{
clinic *p;
p=arr.ptr;
while(p != NULL)
{
if(strcmp(p->clinic_name,name)==0)
break;
else
p=p->next;
}
return p;
}//end of func
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
dr * search_doc(clinic *p,char name[10],char ln[10])
{
dr * doc ;
doc =p->drptr;
while(doc!=NULL)
{
if(strcmp(doc->fn,name)==0&&strcmp(doc->ln,ln)==0)
return doc;
else
doc=doc->next;
}
return doc;
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
nr * search_nurs (clinic *p,char name[10],char ln[10])
{
nr * nur ;
nur =p->nrptr;
while(nur!=NULL)
{
if(strcmp(nur->fn,name)==0&&strcmp(nur->ln,ln)==0)
break;
else
nur=nur->next;
}
return nur;
}//end
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
staff * search_staff (clinic *p,char name[10],char ln[10])
{
staff * staf ;
staf =p->stafptr;
while(staf!=NULL)
{
if(strcmp(staf->fn,name)==0&&strcmp(staf->ln,ln)==0)
return staf;
else
staf=staf->next;
}
return NULL;
}//end
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ser * search_serv (clinic *p,char name[10])
{
ser * serv ;
serv =p->serptr;
while(serv!=NULL)
{
if(strcmp(serv->cn,name)==0)
break;
else
serv=serv->next;
}
return serv;
}//end
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
patient * search_patient(dr *doc, char name[10], char ln[10])
{
patient *pati;
pati=doc->ptr;
while(pati!=NULL)
{
if(strcmp(pati->fn,name)==0 && strcmp(pati->ln,ln)==0)
break;
else
pati=pati->next;
}
return pati;
}
//**************************************************************************************************
// INSERTION FUNCTIONS
//**************************************************************************************************
void insert_hosp()
{
int i;
char ch;
if(count>=10)
printf(":::ARRAY OF HOSPITAL IS FULL:::\n");
else{
printf("\n::: Enter the name of the hospitals (10 max) ::: \n");
while(count<10 && ch!='n')
{
scanf("%s",name);
i=search_hosp(name);
if(i< 0)
{
strcpy(arr[count].hos,name);
count++;
printf("Do u want to insert anther hospital (y or n) :");
scanf(" %c",&ch);
}
else
{
printf(":::THE HOSPITAL IS ALREADY EXIST:::\n");
break;
}
}}
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void insert_clinic()
{
int i;
clinic *newcli,*p;
printf("Enter hospital to add new clinic to it\n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
printf("Enter the name of the clinic:");
scanf("%s",name);
p=search_clinic(i,name);
if(p== NULL)
{
newcli=(clinic *)malloc(sizeof(clinic));
strcpy(newcli->clinic_name,name);
newcli->drptr=NULL;
newcli->nrptr=NULL;
newcli->serptr=NULL;
newcli->stafptr=NULL;
newcli->next=NULL;
if(arr.ptr == NULL)
{
arr.ptr=newcli;
}//if
else
{
newcli->next=arr.ptr;
arr.ptr=newcli;
}//else
}
else
printf(":::CLINIC IS ALRADY EXIST:::\n");
}
else
printf("\n:::HOSPITAL NOT FOUND:::\n");
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void insert_doc()
{
int i;
dr *newdr,*doc;
clinic *p;
printf("Enter hospital to add a doctor in \n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
printf("Enter clinic to add doctor in \n");
scanf("%s",name);
p=search_clinic(i,name);
if(p==NULL)
printf("\n:::CLINIC NOT FOUND:::\n");
else if(p != NULL)
{
printf("Please enter the doctor's first name:");
scanf("%s",name);
printf("Please enter the doctor's last name :");
scanf("%s",ln);
doc=search_doc(p,name,ln);
if(doc!=NULL)
printf(":::DOCTOR ALREADY EXIST:::\n");
else{
newdr=(dr *)malloc(sizeof(dr));
strcpy(newdr->fn,name);
strcpy(newdr->ln,ln);
printf("Please enter the doctor's address :");
scanf("%s",name);
strcpy(newdr->add,name);
printf("Please enter the doctor's tel. number :");
scanf("%s",name);
strcpy(newdr->tel,name);
printf("Please enter the doctor's working hours :");
scanf("%s",name);
strcpy(newdr->wh,name);
newdr->next=NULL;
newdr->ptr=NULL;
}
}//elseif
if(p->drptr==NULL)
p->drptr=newdr;
else
{
newdr->next=p->drptr;
p->drptr=newdr;
}
}//if
else printf(":::HOSPITAL NOT FOUND:::\n");
}// end
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void insert_nurs()
{
int i;
nr *newnr,*nur;
clinic *p;
printf("Enter hospital to add new nurs to it\n");
scanf("%s",name);
i= search_hosp(name);
if(i>=0)
{
printf("Enter clinic to add a nurs in \n");
scanf("%s",name);
p=search_clinic(i,name);
if(p==NULL)
printf("Clinic not found\n");
else if(p != NULL)
{
printf("Please enter the nurs's first name:");
scanf("%s",name);
printf("Please enter the nurs's last name :");
scanf("%s",ln);
nur=search_nurs(p,name,ln);
if(nur!=NULL)
printf(":::NURSE IS ALREADY EXIST:::\n");
else{
newnr=(nr *)malloc(sizeof(nr));
strcpy(newnr->fn,name);
strcpy(newnr->ln,ln);
printf("Please enter the nurs's address :");
scanf("%s",name);
strcpy(newnr->add,name);
printf("Please enter the nurs's tel. number :");
scanf("%s",name);
strcpy(newnr->tel,name);
printf("Please enter the nurs's working hours :");
scanf("%s",name);
strcpy(newnr->wh,name);
newnr->next=NULL;
}
}//else if
if(p->nrptr==NULL)
p->nrptr=newnr;
else
{
newnr->next=p->nrptr;
p->nrptr=newnr;
}
}//if
else printf(":::HOSPITAL NOT FOUND:::\n");
}// end
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void insert_staff()
{
int i;
staff *newstaf,*staf;
clinic *p;
printf("Enter hospital to add new staff member to it\n");
scanf("%s",name);
i= search_hosp(name);
if(i>=0)
{
printf("Enter clinic to add a staff membr in \n");
scanf("%s",name);
p=search_clinic(i,name);
if(p==NULL)
printf("Clinic not found\n");
else if(p != NULL)
{
printf("Please enter the staff member's first name:");
scanf("%s",name);
printf("Please enter the staff member's last name :");
scanf("%s",ln);
staf=search_staff(p,name,ln);
if(staf!=NULL)
printf(":::STAFF MEMBER IS ALREADY EXIST:::\n");
else{
newstaf=(staff *)malloc(sizeof(staff));
strcpy(newstaf->fn,name);
strcpy(newstaf->ln,ln);
printf("Please enter the staff member's address :");
scanf("%s",name);
strcpy(newstaf->add,name);
printf("Please enter the staff member's tel. number :");
scanf("%s",name);
strcpy(newstaf->tel,name);
printf("Please enter the staff member's working hours :");
scanf("%s",name);
strcpy(newstaf->wh,name);
newstaf->next=NULL;
}
}//else if
if(p->stafptr==NULL)
p->stafptr=newstaf;
else
{
newstaf->next=p->stafptr;
p->stafptr=newstaf;
}
}//if
else printf(":::HOSPITAL NOT FOUND:::\n");
}// end
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void insert_ser()
{
int i;
ser *newser,*serv;
clinic *p;
printf("Enter hospital to add new service company to it\n");
scanf("%s",name);
i= search_hosp(name);
if(i>=0)
{
printf("Enter clinic to add a service company in \n");
scanf("%s",name);
p=search_clinic(i,name);
if(p==NULL)
printf(":::CLINIC NOT FOUND:::\n");
else if(p != NULL)
{
printf("Please enter the name of the company:");
scanf("%s",name);
serv=search_serv(p,name);
if(serv!=NULL)
printf(":::SERVICE COMPANY IS ALREADY EXIST:::\n");
else
{
newser=(ser *)malloc(sizeof(ser));
strcpy(newser->cn,name);
printf("Please enter the service company's address :");
scanf("%s",name);
strcpy(newser->add,name);
printf("Please enter the service company's tel. number :");
scanf("%s",name);
strcpy(newser->tel,name);
printf("Please enter the serice company's working hours :");
scanf("%s",name);
strcpy(newser->wh,name);
newser->next=NULL;
}
}//else if
if(p->serptr==NULL)
p->serptr=newser;
else
{
newser->next=p->serptr;
p->serptr=newser;
}
}//if
else printf(":::HOSPITAL NOT FOUND:::\n");
}// end
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void insert_patient ()
{
clinic *p;
dr *doc;
patient *pat;
int i;
char fname[10],lname[10],date[10],word[100]="nothing";//word to copy in the file word by word
FILE *cond;
printf("In which hospital u want to add patient \n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
printf("In which clinic do u want to add the patient\n");
scanf("%s",name);
p=search_clinic(i,name);
if(p != NULL)
{
printf("To which doctor u want to add the patient(first&last name)\n");
scanf("%s %s",name,ln);
doc=search_doc(p,name,ln);
if(doc != NULL)
{
printf("Enter the patient's first name\n");
scanf("%s",fname);
printf("Enter the patient's last name\n");
scanf("%s",lname);
pat=search_patient(doc,fname,lname);
if(pat==NULL)
{
pat=(patient *)malloc(sizeof(patient));
strcpy(pat->fn,fname);
strcpy(pat->ln,lname);
printf("Enter the patient's civil id :");
scanf("%s",name);
strcpy(pat->cid,name);
printf("Enter the next appointment(date) :");
scanf("%s",date);
strcpy(pat->app,date);
strcat(fname," ");
strcat(fname,lname);
strcat(fname,".txt");
if(!(cond=fopen(fname,"a+")))
printf(":::PATIENT'S CONDITION FILE NOT FOUND:::");
else{
fprintf(cond,"DATE:");
fprintf(cond,"%s",date);
fprintf(cond,"\n");
printf("Enter the medication of the patient:");
fprintf(cond,"The medication:");
gets(name);
gets(word);
fprintf(cond,"%s",word);
fprintf(cond,"\n");
printf("Enter condition of the patient\n");
gets(word);
fprintf(cond,"The condition:");
fprintf(cond,"%s ",word);
fprintf(cond,"\n****************************************************\n");
fclose(cond);
}//else
pat->next=NULL;
if(doc->ptr==NULL)
doc->ptr=pat;
else
{
pat->next=doc->ptr;
doc->ptr=pat;
}//else
}//if
else
printf(":::PATIENT IS ALREADY EXIST:::\n");
}
else
printf(":::DOTOR NOT FOUND:::\n");
}
else
printf(":::CLINIC NOT FOUND:::\n");
}//if
else printf(":::HOSPITAL NOT FOUND:::\n");
}// end
//******************************************************************************
// DELETION FUNCTIONS //
//******************************************************************************
void delete_hosp()
{
int i,j;
printf("Enter the hospital that u want to delete it :");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
for(j=i ;j<=10 &&(strcmp(arr[j].hos,"nothing")!=0) ;j++)
arr[j]=arr[j+1]; //shifting the array
count--;
}
else printf(":::HOSPITAL NOT FOUND:::\n");
}//end
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void delete_clinic()
{
int i;
clinic *p,*prev;
printf("Enter hospital to delete a clinic from it\n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
printf("Enter clinic to delete it\n");
scanf("%s",name);
p=search_clinic(i,name);
if(p!=NULL)
{
prev=arr.ptr;
while(prev !=NULL)
{
if(prev->next==p)
{
prev->next=prev->next;
p->next=NULL;
free(p);
}
else
prev=prev->next;
}//while*/
}//if
else
printf(":::CLINIC NOT FOUND:::\n");
}
else
printf(":::HOSPITAL NOT FOND:::\n");
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void delete_doc()
{
int i;
dr *doc,*prev;
clinic *p;
printf("Enter hospital to delete a doctor from it\n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
printf("Enter clinic to delete a doctor from it\n");
scanf("%s",name);
p=search_clinic(i,name);
if(p!=NULL)
{
printf("Enter doctor's first name to delete him/her \n");
scanf("%s",name);
printf("Enter doctor's last name to delete him/her \n");
scanf("%s",ln);
doc=search_doc(p,name,ln);
if(doc!=NULL)
{
prev =p->drptr;
while(prev !=NULL)
{
if(prev->next==doc)
{
prev=prev->next;
doc->next=NULL;
free(doc);
}
else
prev=prev->next;
}//while
}//if(doc!=NULL)
else
printf(":::DOCTOR NOT FOUND:::\n");
}//if(p!=NULL)
else
printf(":::CLINIC NOT FOUND:::\n");
}//if(i>=0)
else
printf(":::HOSPITAL NOT FOUND:::\n");
}// end
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void delete_nurs()
{
int i;
nr *nur,*prev;
clinic *p;
printf("Enter hospital to delete a nurse from it\n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
printf("Enter clinic to delete a nurse from it\n");
scanf("%s",name);
p=search_clinic(i,name);
prev =p->nrptr;
if(p!=NULL)
{
printf("Enter nurse's first name to delete her/his \n");
scanf("%s",name);
printf("Enter nurse's last name to delete him/her \n");
scanf("%s",ln);
nur = search_nurs(p,name,ln);
if(nur!=NULL)
{
while(prev !=NULL)
{
if(prev->next==nur)
{
prev=prev->next;
nur->next=NULL;
free(nur);
}
else
prev=prev->next;
}//while
}//if(nur!=NULL)
else
printf(":::NURSE NOT FOUND:::\n");
}//if(p!=NULL)
else
printf(":::CLINIC NOT FOUND:::\n");
}//if(i>=0)
else
printf(":::HOSPITAL NOT FOUND:::\n");
}// end
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void delete_staf()
{
int i;
staff *staf,*prev;
clinic *p;
printf("Enter hospital to delete a staff member from it\n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
printf("Enter clinic to delete a staff member from it\n");
scanf("%s",name);
p=search_clinic(i,name);
prev =p->stafptr;
if(p!=NULL)
{
printf("Enter staff member's first name to delete him/her\n");
scanf("%s",name);
printf("Enter staff member's last name to delete him/her\n");
scanf("%s",ln);
staf = search_staff(p,name,ln);
if(staf!=NULL)
{
while(prev !=NULL)
{
if(prev->next==staf)
{
prev=prev->next;
staf->next=NULL;
free(staf);
}
else
prev=prev->next;
}//while
}//if(staf!=NULL)
else
printf(":::STAFF MEMBER NOT FOUND:::\n");
}//if(p!=NULL)
else
printf("Clinic not found\n");
}//if(i>=0)
else
printf(":::HOSPITAL NOT FOUND:::\n");
}// end
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void delete_ser()
{
int i;
ser *serv,*prev;
clinic *p;
printf("Enter hospital to delete service company from it\n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
printf("Enter clinic to delete service company from it\n");
scanf("%s",name);
p=search_clinic(i,name);
prev =p->serptr;
if(p!=NULL)
{
printf("Enter service company's name to delete it \n");
scanf("%s",name);
serv=search_serv(p,name);
if(serv!=NULL)
{
while(prev !=NULL)
{
if(prev->next==serv)
{
prev=prev->next;
serv->next=NULL;
free(serv);
}
else
prev=prev->next;
}//while
}//if(serv!=NULL)
else
printf(":::SERVICE COMPANY NOT FOUND:::\n");
}//if(p!=NULL)
else
printf(":::CLINIC NOT FOUND:::\n");
}//if(i>=0)
else
printf(":::HOSPITAL NOT FOUND:::\n");
}// end
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void delete_patient()
{
int i;
patient *pat,*prev;
dr *doc;
clinic *p;
printf("Enter hospital to delete a patient from it\n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
printf("Enter clinic to delete a patient from it\n");
scanf("%s",name);
p=search_clinic(i,name);
if(p!=NULL)
{
printf("Enter the doctor's first name to delete one of his/her patients \n");
scanf("%s",name);
printf("Enter the doctor's last name to delete one of him/her patients \n");
scanf("%s",ln);
doc = search_doc(p,name,ln);
prev=doc->ptr;
if(doc !=NULL)
{
printf("Enter paitent's first name to delete him/her\n");
scanf("%s",name);
printf("Enter patient's last name\n");
scanf("%s",ln);
pat=search_patient(doc,name,ln);
if(pat!=NULL)
{
while(prev !=NULL)
{
if(prev->next==pat)
{
prev=prev->next;
pat->next=NULL;
free(pat);
}
else
prev=prev->next;
}//while
}//if(pat!=NULL)
else
printf(":::PATIENT NOT FOUND:::\n");
}//if(p!=NULL)
else
printf(":::DOCTOR NOT FOUND:::\n");
}
else
printf(":::CLINIC NOT FOUND:::\n");
}//if(i>=0)
else
printf(":::HOSPITAL NOT FOUND:::\n");
}// end
//******************************************************************************
// PRINTING FUNCTIONS //
//******************************************************************************
void print_hospital()
{
char ch ;
int i;
clinic *p;
do{
printf("1 > Show all hospitals\n");
printf("2 > Show all clinics in a given hospital\n");
printf("E > Exit\n");
printf("You'r choice :");
scanf(" %c",&ch);
if(ch=='1')
{
if(count<=0)
printf(":::THERE ARE NO STORED HOSPITALS:::\n");
else{
printf("The stored hospital:\n");
for(i=0; i<count ;i++)
printf("%s\n",arr.hos);
}
}
else if(ch=='2')
{
printf("Enter the name of the hospital\n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
p=arr.ptr;
if(p == NULL)
printf(":::THERE ARE NO STORED HOSPITALS:::\n");
else{
printf("The stored clinic:\n");
while(p !=NULL)
{
printf("%s\n",p->clinic_name);
p=p->next;
}// while
}
}// if
else
printf(":::HOSPITAL NOT FOUND:::\n");
}// else if
}while(ch!='E' && ch!='e');
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void print_clinic ()
{
char ch='0';
int i;
clinic *p;
dr *doc;
nr *nurs;
ser *serv;
staff *staf;
while(ch!='e' && ch!='E')
{
printf("1 >Print all doctors in a given clinic\n");
printf("2 >Print all nurses in a given clinic\n");
printf("3 >Print all staff members in a given clinic\n");
printf("4 >Print all service company in a given clinic\n");
printf("E >Exit\n");
printf(" You'r choice :");
scanf(" %c",&ch);
if(ch=='e'||ch=='E') break;
printf("Enter the name of the hospital\n");
scanf("%s",name);
i=search_hosp(name);
if(i<0)
printf(":::HOSPITAL NOT FOUND:::\n");
else
{
printf("Enter the name of the clinic\n");
scanf("%s",name);
p=search_clinic(i,name);
if(p ==NULL) printf(":::CLINIC NOT FOUND:::\n");
else //if (p!=NULL)
{
if(ch=='1')
{
doc=p->drptr;
if(doc==NULL) printf(":::THERE ARE NO STORD DOCTORS IN THE CLINIC:::\n");
else{
printf("The stored doctors:\n");
while(doc !=NULL)
{
printf("%s %s\n",doc->fn,doc->ln);
doc=doc->next;
}//while
}
}//if
else if(ch=='2')
{
nurs=p->nrptr;
if(nurs == NULL) printf(":::THERE ARE NO STORED NURSES IN THE CLINIC:::\n");
else{
printf("The stored nurses:\n");
while(nurs != NULL)
{
printf("%s %s\n",nurs->fn,nurs->ln);
nurs=nurs->next;
}//while
}
}//if
else if(ch=='3')
{
staf=p->stafptr;
if(staf == NULL) printf(":::THERE ARE NO STORED STAFF MEMBERS IN THE CLINIC:::\n");
else{
printf("The stored staff members:\n");
while(staf != NULL)
{
printf("%s %s\n",staf->fn,staf->ln);
staf=staf->next;
}//while
}
}//if
else if(ch=='4')
{
serv=p->serptr;
if(serv == NULL) printf(":::THERE ARE NO STORED SERVICE COMPANIES IN THE CLINIC:::\n");
else{
printf("The stored service companies:\n");
while(serv != NULL)
{
printf("%s \n",serv->cn);
serv=serv->next;
}//while
}
}//if
}//while
}
}//if
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void print_doctor( )
{
dr *doc;
patient *pati;
char ch ;
int i;
clinic *p;
do{
printf("1 >Print doctor's address \n");
printf("2 >Print doctor's tel. \n");
printf("3 >Print doctor's working hours\n");
printf("4 >Print doctor's all patients\n");
printf("E >Exit\n");
scanf(" %c",&ch);
if(ch=='E'|| ch=='e')
break;
else if(!(ch=='1' || ch=='2' || ch=='3' ||ch=='4' ||ch=='e' ||ch=='E'))
printf(":::INVALIED CHOICE:::\n");
printf("Enter the name of the hospital\n");
scanf("%s",name);
i=search_hosp(name);
if(!(i>=0)) printf(":::HOSPITAL NOT FOUND:::\n");
else
{
printf("Enter the name of the clinic\n");
scanf("%s",name);
p=search_clinic(i,name);
if(p == NULL) printf(":::CLINIC NOT FOUND::: \n");
else{
printf("Enter the first and the last name of the doctor\n");
scanf("%s %s",name,ln);
doc=search_doc(p,name,ln);
if(doc == NULL) printf(":::DOCTOR NOT FOUND:::\n");
if(doc != NULL)
{
if(ch=='1')
printf("The address :%s\n",doc->add);
else if(ch=='2')
printf("Th tel. number:%s\n",doc->tel);
else if(ch=='3')
printf("The working hours:%s\n",doc->wh);
else if(ch=='4')
{
pati=doc->ptr;
if(pati==NULL) printf(":::THERE ARE NO STORED PATIENTS FOR THIS DOCTOR:::\n");
else{
printf("The stored patients:\n");
while(pati != NULL)
{
printf("%s %s\n",pati->fn,pati->ln);
pati=pati->next;
}//while
}
}//else 4
}//while
}//else
}//else
}while(ch != 'e' && ch !='E');
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void print_nurse ()
{
char ch ;
int i;
clinic *p;
nr *nur;
printf("1 >Print nurse's address \n");
printf("2 >Print nurse's tel. \n");
printf("3 >Print nurse's working hours\n");
printf("E >Exit\n");
scanf(" %c",&ch);
while(ch !='e' && ch!='E')
{
if(!(ch=='1' || ch=='2' || ch=='3' ||ch=='4' ||ch=='e' ||ch=='E'))
printf(":::INVALIED CHOICE:::\n");
printf("Enter the name of the hospital\n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
printf("Enter the name of the clinic\n");
scanf("%s",name);
p=search_clinic(i,name);
if(p==NULL) printf(":::CLINIC NOT FOUND:::\n");
if(p!=NULL)
{
printf("Enter the fist and the last name of the nurse\n");
scanf("%s %s",name,ln);
nur=search_nurs(p,name,ln);
if(nur == NULL) printf(":::NURSES NOT FOUND:::\n");
else if(nur != NULL)
{
if(ch=='1')
printf("The address:%s\n",nur->add);
else if(ch=='2')
printf("Th tel.number:%s\n",nur->tel);
else if(ch=='3')
printf("Th working hours:%s\n",nur->wh);
}//else if
}//if (p!=NULL)
}//if(i>=0)
}
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void print_staff ()
{
char ch;
staff *staf;
int i;
clinic *p;
while(ch !='e' && ch!='E')
{
printf("1 >Print staff member's address \n");
printf("2 >Print staff member's tel. \n");
printf("3 >Print staff member's working hours\n");
printf("E >Exit\n");
scanf(" %c",&ch);
if(!(ch=='1' || ch=='2' || ch=='3' ||ch=='4' ||ch=='e' ||ch=='E'))
printf(":::INVALIED CHOICE:::\n");
printf("Enter the name of the hospital\n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
printf("Enter the name of the clinic\n");
scanf("%s",name);
p=search_clinic(i,name);
if(p==NULL) printf(":::CLINIC NOT FOUND:::\n");
if(p!=NULL)
{
printf("Enter the fist and the last name of the staff member\n");
scanf("%s %s",name,ln);
staf=search_staff(p,name,ln);
if(staf == NULL) printf(":::STAFF MEMBER NOT FOUND:::\n");
else if(staf != NULL)
{
if(ch=='1')
printf("The address:%s\n",staf->add);
else if(ch=='2')
printf("The tel.number:%s\n",staf->tel);
else if(ch=='3')
printf("The working hours:%s\n",staf->wh);
}//else if
}//if (p!=NULL)
}//if(i>=0)
}
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void print_ser()
{
char ch='0' ;
int i;
ser *serv;
clinic *p;
while(ch !='e' && ch!='E')
{
printf("1 >Print service company's address \n");
printf("2 >Print service company's tel. \n");
printf("3 >Print service company's working hours\n");
printf("E >Exit\n");
scanf(" %c",&ch);
if(!(ch=='1' || ch=='2' || ch=='3' ||ch=='4' ||ch=='e' ||ch=='E'))
printf(":::INVALIED CHOICE:::\n");
printf("Enter the name of the hospital\n");
scanf("%s",name);
i=search_hosp(name);
if(i>=0)
{
printf("Enter the name of the clinic\n");
scanf("%s",name);
p=search_clinic(i,name);
if(p==NULL) printf(":::CLINIC NOT FOUND:::\n");
if(p!=NULL)
{
printf("Enter the name of the service company\n");
scanf("%s",name);
serv=search_serv(p,name);
if(serv == NULL) printf(":::SRVICE COMPANY NOT FOUND:::\n");
else if(serv != NULL)
{
if(ch=='1')
printf("The address:%s\n",serv->add);
else if(ch=='2')
printf("The tel. number:%s\n",serv->tel);
else if(ch=='3')
printf("The working hours:%s\n",serv->wh);
}//else if
}//if (p!=NULL)
}//if(i>=0)
}
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void print_patient()
{
char ch='0';
patient *pati;
dr *doc;
clinic *p;
int i;
while(ch !='e' && ch!='E')
{
printf("1 > print patient's civil i.d.\n");
printf("2 > print patient's next appointment \n");
printf("E >Exit\n");
scanf(" %c",&ch);
if(!(ch=='1' || ch=='2' || ch=='3' ||ch=='4' ||ch=='e' ||ch=='E'))
printf(":::INVALIED CHOICE\n");
else{
printf("Enter the name of the hospital where the patient exists\n");
scanf("%s",name);
i=search_hosp(name);
if(i<0) printf(":::HOSPITAL NOT FOUND:::\n");
else
{
printf("Enter the name of the clinic where patient exists\n");
scanf("%s",name);
p=search_clinic(i,name);
if(p==NULL) printf(":::CLINIC NOT FOUND:::\n");
else{
printf("Enter the(first&last)name of the patient's doctor\n");
scanf("%s %s",name,ln);
doc=search_doc(p,name,ln);
if(doc == NULL) printf("DOCTOR NOT FOUND\n");
else{
printf("Enter the(first&last)name of the patient\n");
scanf("%s %s",name,ln);
pati=search_patient(doc,name,ln);
if(pati==NULL) printf("PATIENT NOT FOUND\n");
else{
if(ch=='1') printf("%s\n",pati->cid);
else if(ch=='2') printf("%s\n",pati->app);
}
}
}//else
}//else
}//else
}//while
}
/***************************************************************************************************
menu function prints the options and gets the selected option
****************************************************************************************************/
char menu ()
{
char op;
printf("*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.\n");
printf("\nI > Insert a record. \n");
printf("D > Delete a record.\n");
printf("P > Print and search for any stored info.\n");
printf("F > Find which was working at specific hours.\n");
printf("S > Search for a doctors at a given hour for particular clinic. \n");
printf("Q > Quite the program.\n\n");
printf("Pick one of these options:");
scanf(" %c",&op);
return op;
}/* end function*/
/**************************************************************************************************
the main function calles the seleced function by comparing the
selected code
***************************************************************************************************/
int main ()
{
char ch,c;
int i=0;
char date[10]; //for search for the woriking hour
clinic *p;
dr *doc;
nr *nurs;
staff *staf;
ser *serv;
for(i=0;i<10; strcpy(arr.hos,"nothing"),i++);
ch=menu();
while(ch!='q'&& ch!='Q')
{
if(ch=='I'|| ch=='i')
{
do{
printf("\nwhat do you want to insert : \n");
printf("\n1 > hospital \n");
printf("2 > clinic\n");
printf("3 > doctor\n");
printf("4 > nurse\n");
printf("5 > staff member\n");
printf("6 > Service company \n");
printf("7 > Patient\n");
printf("E > Exit\n");
printf("\nYou'r choice:");
scanf(" %c",&c);
if(c=='1')
insert_hosp();
else if(c=='2')
insert_clinic();
else if(c=='3')
insert_doc();
else if(c=='4')
insert_nurs();
else if(c=='5')
insert_staff();
else if(c=='6')
insert_ser();
else if(c=='7')
insert_patient();
else if(c=='e' || c=='E')
break;
}while(c!='E' && c!='e');
}//if
else if(ch=='D'||ch=='d')
{
do{
printf("\nwhat do you want to delete : \n");
printf("\n1 > hospital \n");
printf("2 > clinic\n");
printf("3 > doctor\n");
printf("4 > nurse\n");
printf("5 > staff member\n");
printf("6 > Service company \n");
printf("7 > Patient\n");
printf("E > Exit\n");
printf("\nYou'r choice:");
scanf(" %c",&c);
if(c=='1')
delete_hosp();
else if(c=='2')
delete_clinic();
else if(c=='3')
delete_doc();
else if(c=='4')
delete_nurs();
else if(c=='5')
delete_staf();
else if(c=='6')
delete_ser();
else if(c=='7')
delete_patient();
}while(c!='E' && c!='e');
}
else if(ch=='P'||ch=='p')
{
do{
printf("\nwhat do you want to print : \n");
printf("\n1 > hospital\n");
printf("2 > clinic\n");
printf("3 > doctor\n");
printf("4 > nurse\n");
printf("5 > staff member\n");
printf("6 > Service company \n");
printf("7 > Patient\n");
printf("E > Exit\n");
printf("\nYou'r choice:");
scanf(" %c",&c);
printf("\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n");
if(c=='1')
print_hospital();
else if(c=='2')
print_clinic();
else if(c=='3')
print_doctor();
else if(c=='4')
print_nurse();
else if(c=='5')
print_staff();
else if(c=='6')
print_ser();
else if(c=='7')
print_patient();
}while(c!='E' && c!='e');
}
else if(ch=='F'||ch=='f')
do{
printf("\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n");
printf("\npick one to identify his/her working hours\n");
printf("1 > doctor\n");
printf("2 > nurse\n");
printf("3 > staff member\n");
printf("4 > Service company \n");
printf("E > Exit\n");
printf("\nYou'r choice:");
scanf(" %c",&c);
if(c=='e'||c=='E')
break;
printf("\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n");
printf("Enter the time:");
scanf("%s",date);
printf("Enter the name of hospital where u want to search in\n");
scanf("%s",name);
i=search_hosp(name);
if(i<0) printf("HOSPITAL NOT FOUND\n");
else{
printf("Enter the name of clinic where u want to search in");
scanf("%s",name);
p=search_clinic(i,name);
if(p==NULL) printf("CLINIC NOT FOUND");
else{
if(c=='1')
{
doc=p->drptr;
while(doc !=NULL)
{
if(strcmp(doc->wh,date)==0)
printf("%s %s\n",doc->fn,doc->ln);
doc=doc->next;
}
}
else if(c=='2')
{
nurs=p->nrptr;
while(nurs !=NULL)
{
if(strcmp(nurs->wh,date)==0)
printf("%s %s\n",nurs->fn,nurs->ln);
nurs=nurs->next;
}
}
else if(c=='3')
{
staf=p->stafptr;
while(staf !=NULL)
{
if(strcmp(staf->wh,date)==0)
printf("%s %s\n",staf->fn,staf->ln);
staf=staf->next;
}
}
else if(c=='4')
{
serv=p->serptr;
while(serv !=NULL)
{
if(strcmp(serv->wh,date)==0)
printf("%s\n",serv->cn);
serv=serv->next;
}
}
}
}
}while(c!='E' && c!='e');
else if(ch=='S'||ch=='s')
{
printf("Enter the time to show doctors that are not working