Vous êtes sur la page 1sur 25

#include <stdio.

h>

#include<stdlib.h>

#include <string.h>

//these are room prices per night

#define size 20

#define single 200

#define singlesea 250

#define duble 350

#define doublesea 400

#define suite 550

#define suitesea 600

#define penthouse 1000

#define penthousesea 1100

struct hotel

int roomNum;

char firstName[size];

char lastName[size];

char roomType[size];

char paymentType[2];

int numberOfNights;

int age;

float amount;

};
int findGross(char type[],int nights)

float gross;

if (strcmp( type,"single")==0)

gross=nights*single;

else

if (strcmp( type,"singlesea")==0)

gross=nights*singlesea;

else

if (strcmp( type,"double")==0)

gross=nights*duble;

else

if (strcmp( type,"doubledsea")==0)

gross=nights*doublesea;

else

if (strcmp( type,"suite")==0)
{

gross=nights*suite;

else

if (strcmp( type,"suitesea")==0)

gross=nights*suitesea;

else

if (strcmp( type,"penthouse")==0)

gross=nights*penthouse;

else

if (strcmp( type,"penthousesea")==0)

gross=nights*penthousesea;

return gross;

int printResults(int roomnum,char fname[],char lname[],char room[],char payment[],int nights,int


age,float amount)

{
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>::>");

printf("\n :: :: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ::");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@ ::");

printf("\n :: :: @ Thier room number is %d ",roomnum);

printf("\n :: :: @ The customers full name is %s %s ",fname,lname);

printf("\n :: :: @ The type of room occupied was a %s ",room);

printf("\n :: :: @ Their payment method was %s ",payment);

printf("\n :: :: @ They stayed at the hotel %d nights ",nights);

printf("\n :: :: @ Their age is %d ",age);

printf("\n :: :: @ Their bill is %.2f ",amount);

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@ ::");

printf("\n :: :: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ::");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>::>:::>\n\n");

printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");

int subtract(int num)

int result;

result=num-1;

return result;
}

int MenuChoice()//menu gives user a list of options

int choice;

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>");

printf("\n :: :: ::");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :: :: @ WELCOME TO THE @ ::");

printf("\n :: :: @ BLACKETT HOTEL @ ::");

printf("\n :: :: @ @ ::");

printf("\n :: :: @ 1. create a new file. @ ::");

printf("\n :: :: @ 2. make a reservation @ ::");

printf("\n :: :: @ 3. Display customer information @ ::");

printf("\n :: :: @ 4. edit a previous reservation @ ::");

printf("\n :: :: @ 5. Delete a record @ ::");

printf("\n :: :: @ 6. search for a guest @ ::");

printf("\n :: :: @ 7. Exit program @ ::");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :: :: ::");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>\n\n");

printf("enter the corresponding number\n");

scanf("%d",&choice);

return choice;
}/*End Function*/

main()

struct hotel guest;

FILE*pointer;

int roomNum;

char firstName[size];

char lastName[size];

char paymentType[2];

char roomType[size];

int age[5];

int numberOfNights;

float amount,bill;

int choice4,temproomnumber4,tempage4,tempnights4;

char tempfname4[size];

char templname4[size];

char temproomtype[size];

char ch;

int identification,result,f,temp;

int num,i,s,ss,d,ds,s2,ss2,p,ps;//s=single ss=singleseaview d=double ds=doubleseaview s2=suite


ss2=suite seaview

s=10;

ss=10;
d=10;

ds=10;

s2=10;

ss2=10;

p=10;

ps=10;

result=MenuChoice();/*call to function MenuChoice*/

while(result!=7)

if(result==1)

struct hotel guest={0,"","","","",0,0,0.0};

if((pointer=fopen("guestitinerary","wb"))==NULL)

printf("Cannot open file \n");

exit(1);

}/*end if*/

else

for (f=0;f<=100;f++)

{
fwrite(&guest,sizeof(struct hotel),1,pointer);

} /*end for*/

fclose(pointer);

printf("\n :: >::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>::>");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :: :: @ FILE CREATED @ ::");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>\n");

result=MenuChoice();/*call to function MenuChoice*/

}/*end if*/

if(result==2)

printf("\n ROOM AVAILABILITY");

printf("\n -------------------\n");

printf("| Type of room| rooms left | charge |");

printf("\nsingle rooms\t ");printf("%d\t",s); printf(" \t%d\t",single);


printf("\nsingle seaview\t ");printf("%d\t",ss);printf(" \t%d\t",singlesea);

printf("\ndouble rooms\t "); printf("%d\t",d);printf(" \t%d\t",duble);

printf("\ndouble seaview\t ");printf("%d\t",ds);printf(" \t%d\t",doublesea);

printf("\nsuites\t ");printf("%d\t",s2);printf(" \t%d\t",suite);

printf("\nsuite seaviews\t ");printf("%d\t",ss2);printf(" \t%d\t",suitesea);

printf("\npenthouse\t ");printf("%d\t",p);printf(" \t%d\t",penthouse);

printf("\npenthouse seaview ");printf("%d\t",ps);printf(" \t%d\t",penthousesea);

struct hotel guest={0,"","","","",0,0,0.0};

if((pointer=fopen("guestitinerary","rb+"))==NULL)

printf("Cannot open file \n");

exit(1);

printf("\nenter the room number wanted\n");

scanf("%d",&guest.roomNum);

printf("enter your first name\n");

scanf("%s",&guest.firstName);

printf("enter your last name\n");

scanf("%s",&guest.lastName);

printf("\nenter the room type\n");

scanf("%s",&guest.roomType);

printf("enter the payment type\n");

scanf("%s",&guest.paymentType);
printf("enter the number of nights staying\n");

scanf("%d",&guest.numberOfNights);

printf("enter your age\n");

scanf("%d",&guest.age);

guest.amount=findGross(guest.roomType,guest.numberOfNights);

printf("their bill is %.2f\n",guest.amount);

fseek(pointer,(guest.roomNum-1)*sizeof(struct hotel),SEEK_SET);

fwrite(&guest,sizeof(struct hotel),1,pointer);

fclose(pointer);

if (strcmp(guest.roomType ,"single")==0)

s=subtract(s);

else

if (strcmp( guest.roomType,"singlesea")==0)

ss=subtract(ss);

else

if (strcmp( guest.roomType,"double")==0)

d=subtract(d);

else

if (strcmp( guest.roomType,"doubledsea")==0)
{

ds=subtract(ds);

else

if (strcmp( guest.roomType,"suite")==0)

s2=subtract(s2);

else

if (strcmp( guest.roomType,"suitesea")==0)

ss2=subtract(ss2);

else

if (strcmp( guest.roomType,"penthouse")==0)

p=subtract(p);

else

if (strcmp( guest.roomType,"penthousesea")==0)

ps=subtract(ps);

}
result=MenuChoice();/*call to function MenuChoice*/

}//END IF

if(result==3)//this is to display customer info

struct hotel guest={0,"","","","",0,0,0.0};

if ((pointer = fopen("guestitinerary", "rb+"))==NULL)

printf("ERROR\n");

else

printf("\n :: >::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>::>");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :: :: @ VIEW RECORDS @ ::");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>\n");

/*read and display every line in the file*/

while(!feof(pointer))

fread(&guest,sizeof(struct hotel),1,pointer);
if(guest.roomNum!=0)

printResults(guest.roomNum,guest.firstName,guest.lastName,guest.roomType,guest.paymentType,gues
t.numberOfNights,guest.age,guest.amount);

printf("\n\n\n");

printf("\n\n");

printf("============================================================\n\n ");

}//END IF

}/*end while*/

}/*end else*/

fclose(pointer);

result=MenuChoice();/*call to function MenuChoice*/

} /*end if*/

if(result==4)

{ struct hotel guest={0,"","","",0,0,0.0};

if ((pointer = fopen("guestitinerary", "rb+"))==NULL)

printf("Cannot open file \n");

exit(1);
}/*end if*/

else{

printf("Enter room number to update(1 to 100)--->");

scanf("%d",&temproomnumber4);

fseek(pointer,(temproomnumber4-1)*sizeof(struct hotel),SEEK_SET);

fread(&guest,sizeof(struct hotel),1,pointer);

/*Read Mode*/

if(guest.roomNum==0)

printf("\n :: >::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>::>");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :: :: @ !!!!!!RECORD HAS NO INFORMATION!!!!!! @ ::");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>\n");

}/*end if*/

if(guest.roomNum!=0)

{
printResults(guest.roomNum,guest.firstName,guest.lastName,guest.roomType,guest.paymentType,gues
t.numberOfNights,guest.age,guest.amount);

printf("\n\n");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>");

printf("\n :: ::");

printf("\n ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ::");

printf("\n :: @ 1. edit firstname @ ::");

printf("\n :: @ 2. edit surname @ ::");

printf("\n :: @ 3. editroom type @ ::");

printf("\n :: @ 4. edit final bill @ ::");

printf("\n :: @ 5. edit customers age @ ::");

printf("\n :: @ 6. edit number of nights in hotel @ ::");

printf("\n :: @ 7. end guest information editting @ ::");

printf("\n ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ::");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>\n\n");

printf("enter a request\n");

scanf("%d",&choice4);

while(choice4!=7)

if(choice4==1)

{
printf("Enter the correct first name\n");

scanf("%s",&tempfname4);

strcpy(guest.firstName,tempfname4);/*editting first name*/

printResults(guest.roomNum,guest.firstName,guest.lastName,guest.roomType,guest.paymentType,gues
t.numberOfNights,guest.age,guest.amount);

printf("\n\n");

fseek(pointer,(guest.roomNum-1)*sizeof(struct hotel),SEEK_SET);

fwrite(&guest,sizeof(struct hotel),1,pointer);

fclose(pointer);

} /*end if*/

if(choice4==2)

printf("Enter the correct last name\n");

scanf("%s",&templname4);

strcpy(guest.lastName,templname4);/*editting last name*/


printResults(guest.roomNum,guest.firstName,guest.lastName,guest.roomType,guest.paymentType,gues
t.numberOfNights,guest.age,guest.amount);

printf("\n\n");

fseek(pointer,(guest.roomNum-1)*sizeof(struct hotel),SEEK_SET);

fwrite(&guest,sizeof(struct hotel),1,pointer);

fclose(pointer);

} /*end if*/

if(choice4==3)

printf("Enter the correct room type\n");

scanf("%s",&temproomtype);

strcpy(guest.roomType,temproomtype);/*editting room type*/

printResults(guest.roomNum,guest.firstName,guest.lastName,guest.roomType,guest.paymentType,gues
t.numberOfNights,guest.age,guest.amount);

printf("\n\n");

fseek(pointer,(guest.roomNum-1)*sizeof(struct hotel),SEEK_SET);

fwrite(&guest,sizeof(struct hotel),1,pointer);
fclose(pointer);

} /*end if*/

if(choice4==4)

printf("Enter the correct bill guest\n");

scanf("%f",&bill);

guest.amount=bill;/*editting final bill*/

printResults(guest.roomNum,guest.firstName,guest.lastName,guest.roomType,guest.paymentType,gues
t.numberOfNights,guest.age,guest.amount);

printf("\n\n");

fseek(pointer,(guest.roomNum-1)*sizeof(struct hotel),SEEK_SET);

fwrite(&guest,sizeof(struct hotel),1,pointer);

fclose(pointer);

} /*end if*/

if(choice4==5)

printf("Enter the correct age\n");

scanf("%d",&tempage4);
guest.age=tempage4;/*editting guests ages*/

printResults(guest.roomNum,guest.firstName,guest.lastName,guest.roomType,guest.paymentType,gues
t.numberOfNights,guest.age,guest.amount);

printf("\n\n");

fseek(pointer,(guest.roomNum-1)*sizeof(struct hotel),SEEK_SET);

fwrite(&guest,sizeof(struct hotel),1,pointer);

fclose(pointer);

} /*end if*/

if(choice4==6)

printf("Enter the correct number of nights guest stayed at hotel\n");

scanf("%d",&tempnights4);

guest.roomNum=tempnights4;/*editting number of nights guest stayed at hotel*/

printResults(guest.roomNum,guest.firstName,guest.lastName,guest.roomType,guest.paymentType,gues
t.numberOfNights,guest.age,guest.amount);

printf("\n\n");
fseek(pointer,(guest.roomNum-1)*sizeof(struct hotel),SEEK_SET);

fwrite(&guest,sizeof(struct hotel),1,pointer);

fclose(pointer);

} /*end if*/

} /*end while*/

} /*end if*/

} /*end else*/

result=MenuChoice();/*call to function MenuChoice*/

}/*end if*/

if(result==5)

{ struct hotel guest={0,"","","",0,0,0.0};

struct hotel blankguest={0,"","","",0,0,0.0};

if ((pointer = fopen("guestitinerary", "rb+"))==NULL)

printf("Cannot open file \n");


exit(1);

}/*end if*/

printf("\n :: >::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>::>");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :: :: @ DELETE RECORDS @ ::");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>\n");

printf("Enter guests room number to delete(1 to 100)--->");

scanf("%d",&guest.roomNum);

fseek(pointer,(guest.roomNum-1)*sizeof(struct hotel),SEEK_SET);

fread(&guest,sizeof(struct hotel),1,pointer);

/*Read Mode*/

if(guest.roomNum==0)

printf("\n :: >::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>::>");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :: :: @ !!!!!!RECORD DOES NOT EXIST!!!!!! @ ::");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");
printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>\n");

}/*end if*/

if(guest.roomNum!=0)

fseek(pointer,(guest.roomNum-1)*sizeof(struct hotel),SEEK_SET);

fwrite(&blankguest,sizeof(struct hotel),1,pointer);

printf("\n :: >::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>::>");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :: :: @ DELETE COMPLETE @ ::");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>\n");

fclose(pointer);

result=MenuChoice();/*call to function MenuChoice*/

}//END IF

if(result==6)//this is to search customer info

{
struct hotel guest={0,"","","",0,0,0.0};

if ((pointer = fopen("guestitinerary", "rb+"))==NULL)

printf("Cannot open file \n");

exit(1);

}/*end if*/

printf("\n :: >::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>::>");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :: :: @ SEARCH RECORDS @ ::");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>\n");

printf("Enter guests room number to delete(1 to 100)--->");

scanf("%d",&guest.roomNum);

fseek(pointer,(guest.roomNum-1)*sizeof(struct hotel),SEEK_SET);

fread(&guest,sizeof(struct hotel),1,pointer);

/*Read Mode*/

if(guest.roomNum==0)

{
printf("\n :: >::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>::>");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :: :: @ !!!!!!RECORD DOES NOT EXIST!!!!!! @ ::");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>\n");

}/*end if*/

if(guest.roomNum!=0)

fseek(pointer,(guest.roomNum-1)*sizeof(struct hotel),SEEK_SET);

printResults(guest.roomNum,guest.firstName,guest.lastName,guest.roomType,guest.paymentType,gues
t.numberOfNights,guest.age,guest.amount);

printf("\n :: >::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>::>");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :: :: @ SEARCH COMPLETE @ ::");

printf("\n :: ::
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::");

printf("\n :::>::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>:::>\n");
}

fclose(pointer);

result=MenuChoice();/*call to function MenuChoice*/

}/*end if*/

} //END WHILE

} //main close

Vous aimerez peut-être aussi