1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<iostream>
#include<string.h>
void login();
int main;
void newrec( FILE * uPtr);
void rec( FILE * uPtr);
void update (FILE * uPtr);
void deleterec(int);
void updatefile( FILE * uPtr);
typedef struct guests
{
int room_no;
char name[30];
char address[50];
char phone[10];
char period;
}guests;
guests guest[50];
void login()
{
int password;
int counter;
password=12345678;
counter=0;
printf(" Please enter the password\n");
scanf("%d",&password);
while (counter<3);
{
printf("Please enter the password\n");
scanf("%d",&password);
if (password!=12345678)
{
printf(" password denied. Please try again");
counter=counter+1;
system("pause");
}
else
{
printf("\tAccess Granted\n");
system("pause");
main();
}
}
system("pause");
return(0);
}
int main()
{
int option;
FILE *cfPtr;
if(( cfPrt=Fopen("hotel.txt", "a+")) ==NULL){
printf(" File could not be opened\n");
}
}
else
{
do{
printf (" *********************************************************************\n");
printf (" * *\n");
printf (" * W E L C O M E *\n");
printf (" * *\n");
printf (" * T O *\n");
printf (" * *\n");
printf (" * T R A N Q U I L P A R A D I S E H O T E L *\n");
printf (" * *\n");
printf (" * H O T E L M A N A G E M E N T S Y S T E M *\n");
printf (" * *\n");
printf (" * *\n");
printf ("**********************************************************************\n");
printf ("\n");
system ("cls");
printf ("\n\tPlease select your option from the list below:\n\n\n");
printf ("\t 1. Add new record\n");
printf ("\t 2. View Records\n");
printf ("\t 3. Update/Edit Record\n");
printf ("\t 4. Delete Record\n");
printf ("\t 5. Exit\n");
system ("pause\n");
system ("CLS");
printf ("Enter your option\n\n");
int option;
scanf ("%d",&option);
switch (option)
{
case 1: system("cls");
newrec("fPtr");
break;
case 2: system("cls");
rec("fPtr");
break;
case 3: system("cls");
update("fPtr");
break;
case 4: system("cls");
deleterec("fPtr");
break;
case 6: exit(0);
default:
printf ("\n INVALID SELECTION!!!\n");
system ("pause\n");
return 0;
}
void newrec()
{
int answer;
int i = 1;
if(( cfPrt=Fopen("hotel.txt", "a+")) ==NULL){
printf(" File could not be opened\n");
}
else
{
do{
system ("cls");
system (" color 3a");
printf ("Enter full name:\n\n");
scanf ("%s", guest[i].name);
printf ("Enter address:\n\n");
scanf ("%s", guest[i].address);
printf ("Enter room number:");
scanf ("%s", guest[i].room_no);
printf ("Enter phone number:");
scanf ("%d", guest[i].phone);
printf ("Enter how long guest will stay:");
scanf ("%d", guest[i].period);
fprintf(fPtr, "%s %s %d %2.2f\n", client[i].firstname, guest[i].name, guest[i].address, guest[i].room_no, guest[i].phone, guest[i].period);
printf("Do you want to add another guest? (1 for Yes of 2 for No)\n");
scanf("%d",&answer);
i = i + 1
}while (answer!= 2);
}
fclose(fPtr);
system("cls");
printf("n\\t^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^\n");
pri ntf("\n\t-------Guest Was Successfully Added--------\n");
printf("\n\t^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^\n");
system ("\npause");
main();
}
void rec( FILE * uPtr)
{
updatefile(pPtr);
system("cls");
int i = 1;
if ( ( pPtr= fopen("hotel.txt", "r") )==NULL )
{
printf("File couldn't' be opened.\n");
}
else
{
printf("%s %s %d %2.2f\n", "Guest Name", "Adress", "Room #", "Phone #", "Period");
fscanf(pPtr, "%s%s%d%d%s\n", guest[i].name, guest[i].address, guest[i].room_no, guest[i].phone, guest[i].period);
}
main()
}
void updatefile( FILE * uPtr)
{
int i;
if ( ( uPtr = fopen("customers.txt", "w")) == NULL )
{
printf("File cannot be opened\n");
}
else
{
for (i = 1; i < 100; i ++)
{
if (guest[i].size != 0)
{
fprintf("%s %s %d %d %s %2.2f\n", "Guest Name", "Adress", "Room #", "Phone #", "Period");
fscanf(pPtr, "%s%s%d%d%s\n", guest[i].name, guest[i].address, guest[i].room_no, guest[i].phone, guest[i].period);
}
}
fclose(uPtr);
}
}
void deletecustomer(FILE *dPtr)
{
char name[30];
int i = 1;
if ( ( dPtr = fopen("guests.txt", "r")) == NULL )
{
printf("File cannot be opened\n");
}
else
{
system ("cls");
printf("\tWho do you want to delete?\n");
scanf ("\n\t%s", name);
while (!feof(dPtr)) {
fscanf(pPtr, "%s%s%d%d\n", guest[i].name, guest[i].address, guest[i].room_no, guest[i].phone, guest[i].period);
if (strcmp(name,guest[i].name)==0)
{
system ("pause");
strcpy(guest[i].name , "");
strcpy(guest[i].address, "");
strcpy(guest[i].room_no, "");
strcpy(guest[i].phone, "");
strcpy(guest[i].period, "");
printf("%d Guest has been deleteed\n", i);
}
i= i +1;
}
updatefile(dPtr);
fclose(dPtr);
system ("pause");
main();
}
}
|