Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <time.h>
  6. int atoi(const char *string);
  7. //add more to the sections below if needed-
  8. //declaring all the procedures to be written later:
  9. void check_in(), book_tables(), check_out(), menu(), display_rooms(), displayCost();
  10. void getCost(int n);
  11. //declaring any constants we will use:
  12. int room_rates[4] = {100, 85, 75, 50};
  13. int board_rates[3] = {20, 15, 5};
  14. //declaring and initiating any global variables we will use:
  15. int rooms[4] = {1, 1, 1, 1};//room one is the 0th element (1 means free 0 booked)
  16. int roomUsed[4]; //room number in correct slot
  17. int tables[2][3] = {{0, 0, 0}, {0, 0, 0}};//Endor, Naboo and Tatooine at 7pm and 9pm respectively
  18. //since there can only be 4 rooms booked and each person has one of those rooms, the variables for the check in function come in fours:
  19. const char* table_names[] = {"Endor", "Naboo", "Tatooine"};
  20. const char *table_time[] = {"7pm", "9pm"};
  21. char names[4][2][12];
  22. char IDs[4][12] = {
  23. {'A', '1'}, {'B', '2'}, {'C', '3'}, {'D', '4'}
  24. }; //placeholder IDs
  25. int DOB[4][8] = {{0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}};
  26. int board_type[4] = {0, 0, 0, 0};//1:FB 2:HB 3:BB
  27. int length[4] = {0, 0, 0, 0};
  28. int numChild[4] = {0,0,0,0}; //number of each type per room
  29. int numAdult[4] = {0,0,0,0};
  30. int numElderly[4] = {0,0,0,0};
  31. int newspaper[4] = {0, 0, 0, 0};
  32. //for check_out
  33. float costNP = 5.5;
  34. float childMultiply = 0.5;
  35. float elderlyMultiply = 0.9;
  36. char currentID[12];
  37. float currentRoom;
  38. int guestPos; //to use as reference in arrays 0-3
  39. float roomCost = 0;
  40. float boardCost = 0;
  41. float tableCost = 0;
  42. float newsCost = 0;
  43. float totalCost = 0;
  44.  
  45. int freeSpace[4] = {1,1,1,1}; //1 = free, 0 = used
  46. int userPos;
  47.  
  48. struct guestUser
  49. {
  50. int inUse; // 0 is free, 1 is taken
  51. int used;
  52. char bookingID[12];
  53. int room;
  54. int board;
  55. int length;
  56. int news; //1 is yes
  57. int numChild;
  58. int numAdult;
  59. int numOld;
  60. };
  61.  
  62. struct guestUser guest1, guest2, guest3, guest4, guestC, guestE; //c is current, e is empty
  63.  
  64.  
  65. int main(void)
  66. {
  67. guest1.inUse = 0;
  68. guest2.inUse = 0;
  69. guest3.inUse = 0;
  70. guest4.inUse = 0;
  71.  
  72. menu();
  73. }
  74. //main menu function
  75. void menu()
  76. {
  77. int option = 1;
  78. printf("Menu Options, press:\n1 for checking in\n2 for table booking\n3 for checking out\n4 for exit\n");
  79. fflush(stdin);
  80. scanf("%d", &option);
  81. switch (option)
  82. {
  83. case 1:
  84. check_in();
  85. break;
  86. case 2:
  87. book_tables();
  88. break;
  89. case 3:
  90. check_out();
  91. break;
  92. case 4:
  93. break;
  94. default:
  95. printf("That wasn't an option");
  96. menu();
  97. }
  98. }
  99. //check in function
  100. void check_in()
  101. {
  102. //temporary variables to store the user input before it is integrated into the global database
  103. char first_name[12], second_name[12], date_of_birth[8];
  104. int num_children = 0, num_adults = 0, num_elderly = 0, room = 0, daily_newspaper = 0;
  105.  
  106. if(guest1.inUse ==0)
  107. {
  108. guest1.inUse = 1;
  109. guestC = guest1;
  110. guestC.used = 1;
  111. }
  112. else if(guest2.inUse==0)
  113. {
  114. guest2.inUse = 1;
  115. guestC = guest2;
  116. guestC.used = 2;
  117. }
  118. else if(guest3.inUse ==0)
  119. {
  120. guest3.inUse = 1;
  121. guestC = guest3;
  122. guestC.used = 3;
  123. }
  124. else if(guest4.inUse==0)
  125. {
  126. guest4.inUse = 1;
  127. guestC = guest4;
  128. guestC.used = 4;
  129. }
  130. else
  131. {
  132. printf("fully booked");
  133. menu();
  134. }
  135.  
  136. //getting and saving relevant data
  137. printf("Please enter your first name:\n");
  138. fflush(stdin);
  139. scanf("%s", first_name);
  140. printf("Please enter your second name:\n");
  141. fflush(stdin);
  142. scanf("%s", second_name);
  143. printf("Please enter your date of birth in the form [DDMMYYYY]:\n");
  144. fflush(stdin);
  145. scanf("%s", date_of_birth);
  146. printf("Please enter the number of children staying:\n");
  147. fflush(stdin);
  148. scanf("%d", &num_children);
  149. printf("Please enter the number of adults between 18 and 65 staying:\n");
  150. fflush(stdin);
  151. scanf("%d", &num_adults);
  152. printf("Please enter the number of adults over 65 staying:\n");
  153. fflush(stdin);
  154. scanf("%d", &num_elderly);
  155.  
  156. guestC.numChild = num_children;
  157. guestC.numAdult = num_adults;
  158. guestC.numOld = num_elderly;
  159.  
  160.  
  161. //checking if too many people
  162. if((num_children + num_adults + num_elderly) > 4)
  163. {
  164. printf("the maximum number of people is 4\n");
  165. menu();
  166. return;
  167. }
  168.  
  169. //displays available rooms
  170. display_rooms();
  171.  
  172. printf("which room would you like to stay in?\n");
  173. fflush(stdin);
  174. scanf("%d", &room);
  175. room -= 1;
  176. rooms[room] = 0;
  177.  
  178. guestC.room = room;
  179.  
  180. //adding data to global data structure
  181. for(int j = 0; j < strlen(first_name); j++)
  182. {
  183. names[room][0][j] = first_name[j];
  184. }
  185. for(int k = 0; k < strlen(second_name); k++)
  186. {
  187. names[room][1][k] = second_name[k];
  188. }
  189. for(int l = 0; l < 8; l++)
  190. {
  191. DOB[room][l] = date_of_birth[l] - 48;
  192. }
  193. numChild[room] = num_children;
  194. numAdult[room] = num_adults;
  195. numElderly[room] = num_elderly;
  196.  
  197. //last pieces of relevant data
  198. printf("Please enter length of stay (in days):");
  199. fflush(stdin);
  200. scanf("%d", &length[room]);
  201. printf("Please chose which board type:\n1 - full board\n2 - half board\n3 - bed and breakfast\n");
  202. fflush(stdin);
  203. scanf("%d", &board_type[room]);
  204. printf("Would you like the daily newspaper?\n1 - yes\n2 - no\n");
  205. fflush(stdin);
  206. scanf("%d", &daily_newspaper);
  207.  
  208. guestC.board = board_type[room];
  209. guestC.news = daily_newspaper;
  210. guestC.length = length[room];
  211.  
  212.  
  213. if(daily_newspaper == 1)
  214. {
  215. newspaper[room] = 1;
  216. }
  217. else
  218. {
  219. newspaper[room] = 0;
  220. }
  221.  
  222. //generating randomized ID from second name and random number
  223. for(int m = 0; m < strlen(second_name); m++)
  224. {
  225. IDs[room][m] = second_name[m];
  226. }
  227. for(int n = 0; n < 4; n++)
  228. {
  229. srand(time(NULL)+n*30000);
  230. IDs[room][n+strlen(second_name)] = rand()%10+48;
  231. }
  232. printf("Your booking ID is %s\n\n", IDs[room]);
  233.  
  234. strcpy(guestC.bookingID, IDs[room]);
  235. guestC.used = room;
  236.  
  237. roomUsed[userPos]= room;
  238. menu();
  239. }
  240. //displaying available rooms function
  241. void display_rooms() {
  242. printf("The available rooms are:\n");
  243. for (int i = 0; i < 4; i++) {
  244. if (rooms[i] == 1) {
  245. printf("room %d - £%d\n", i+1, room_rates[i]);
  246. }
  247. }
  248. }
  249.  
  250.  
  251.  
  252. //book tables function
  253. void book_tables()
  254. {
  255.  
  256.  
  257.  
  258. // ask for the booking id
  259. char bookingid[13];
  260. printf("Enter booking ID: ");
  261. fflush(stdin);
  262. scanf("%s", bookingid);
  263.  
  264.  
  265.  
  266. int roomid = -1;
  267. // try and find a matching user with that booking id
  268. for(int t = 0; t < 4; t++){
  269. if (strcmp(IDs[t], bookingid )==0){
  270. roomid = t;
  271. }
  272.  
  273.  
  274.  
  275. }
  276. if(roomid == -1){
  277. printf("Your booking id is not on our database\n");
  278. return menu();
  279. }
  280. int board = board_type[roomid];
  281.  
  282.  
  283.  
  284. if (board == 3){
  285. printf("You can't book a table, due to you being in Bed and breakfast\n");
  286. return menu();
  287. }
  288.  
  289.  
  290.  
  291. int table_availability = 0;
  292. for(int table = 0; table < 3; table++){
  293. for(int time = 0; time < 2; time++){
  294. if(tables[time][table] == 0){
  295. table_availability = 1;
  296. }
  297. //printf("%d" , tables[time][table]);
  298. }
  299. }
  300. if(table_availability == 1){
  301. printf("The following tables are available: \n");
  302.  
  303.  
  304.  
  305. }
  306. else{
  307. printf("There are no tables available");
  308. return menu();
  309. }
  310. int option = 0;
  311. for(int table = 0; table < 3; table++){
  312. for(int time = 0; time < 2; time++){
  313. option++;
  314. if(tables[time][table] == 0){
  315. // printf("Tables available: \n");
  316. printf("%d . %s %s \n",option, table_names[table], table_time[time]);
  317.  
  318.  
  319.  
  320. }
  321. //printf("%d" , tables[time][table]);
  322. }
  323. }
  324. int selection_table = 0;
  325. printf("What table would you like to book? \nEnter number:");
  326. fflush(stdin);
  327. scanf("%d", &selection_table);
  328. switch (selection_table){
  329. case 1:
  330. tables[0][0] = 1;
  331. printf("Your table has been booked\n");
  332. break;
  333. case 2:
  334. tables[1][0] = 1;
  335. printf("Your e has been booked\n");
  336. break;
  337. case 3:
  338. tables[0][1] = 1;
  339. printf("Your e has been booked\n");
  340. break;
  341. case 4:
  342. tables[1][1] = 1;
  343. printf("Your e has been booked\n");
  344. break;
  345. case 5:
  346. tables[0][2] = 1;
  347. printf("Your e has been booked\n");
  348. break;
  349. case 6:
  350. tables[1][2] = 1;
  351. printf("Your e has been booked\n");
  352. break;
  353. default:
  354. printf("You have entered an invalid number\n");
  355. }
  356. menu();
  357. }
  358. //check out function
  359. void check_out()
  360. {
  361. int validID = 0;
  362. float cost;
  363. while(validID != 1)
  364. {
  365. printf("enter ID:");
  366. fflush(stdin);
  367. // gets(currentID);
  368. scanf("%s", &currentID);
  369. for(int i = 0; i<4; i++)
  370. {
  371. if(strcmp(currentID, IDs[i]) == 0)
  372. {
  373. printf("valid ID\n");
  374. validID = 1;
  375. guestPos = i;
  376. }
  377. }
  378. }
  379. getCost(guestPos);
  380. displayCost();
  381.  
  382. if(guestC.used ==1)
  383. {
  384. guest1 = guestE;
  385. guestC = guestE;
  386. }
  387. else if(guestC.used==2)
  388. {
  389. guest1 = guestE;
  390. guestC = guestE;
  391. }
  392. else if(guestC.used ==3)
  393. {
  394. guest1 = guestE;
  395. guestC = guestE;
  396. }
  397. else if(guestC.used==4)
  398. {
  399. guest1 = guestE;
  400. guestC = guestE;
  401. }
  402. menu();
  403. }
  404. void getCost(int n)
  405. {
  406. roomCost =guestC.length*(guestC.numChild * room_rates[guestC.room] +
  407. guestC.numAdult * room_rates[guestC.room] +
  408. elderlyMultiply*guestC.numOld * room_rates[guestC.room]);
  409. boardCost = guestC.length*(childMultiply * guestC.numChild * board_rates[guestC.board-1] +
  410. guestC.numAdult * board_rates[guestC.board-1] +
  411. guestC.numOld * board_rates[guestC.board-1]);
  412.  
  413. if(guestC.news == 1)
  414. {
  415. newsCost = 5.5;
  416. }
  417. totalCost = roomCost + boardCost + newsCost;
  418. }
  419. void displayCost()
  420. {
  421. printf("Bill for %s\n", currentID);
  422. printf("Rooms: %f\n", roomCost);
  423. printf("Boards: %f\n", boardCost);
  424. if(newsCost == 5.5)
  425. {
  426. printf("Newspaper: %f\n", newsCost);
  427. }
  428. printf("Total: %f\n", totalCost);
  429.  
  430. //:)
  431. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement