943,898 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1005
  • C RSS
Apr 10th, 2008
0

Evaluate my C Program

Expand Post »
I just finished up the final touches on my C Project (at least I hope that's the last of them). Anyway, it's due Friday (10% of my overall grade) and I'd like to have some quick feedback (constructive criticisms and complements) before I had it in. It was suppose to be a group project but my group members weren't on top of their game so I had to push and do all the work myself. A blessing in disguise I guess.

Enough of my chatter, evaluate my presumable complete hotel reservation and booking system.
Attached Files
File Type: zip c project.zip (97.1 KB, 28 views)
Last edited by knight fyre; Apr 10th, 2008 at 1:30 am.
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
knight fyre is offline Offline
88 posts
since Feb 2008
Apr 10th, 2008
0

Re: Evaluate my C Program

If you want proper advice, you should post your code, not your executable.

One tip is: validate user input.

See attachment.
Attached Thumbnails
Click image for larger version

Name:	naamloos.JPG
Views:	21
Size:	32.1 KB
ID:	5772  
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Apr 10th, 2008
0

Re: Evaluate my C Program

Ok, check out my source code file too.
Attached Files
File Type: c SSI_SYSTEM.c (45.8 KB, 18 views)
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
knight fyre is offline Offline
88 posts
since Feb 2008
Apr 10th, 2008
0

Re: Evaluate my C Program

It makes your code easier for us all to read if you wrap it in code tags and not on an attachment.
Reputation Points: 256
Solved Threads: 72
Nearly a Posting Virtuoso
majestic0110 is offline Offline
1,306 posts
since Oct 2007
Apr 10th, 2008
0

Re: Evaluate my C Program

It's kind of long in my view. That's why I didn't post it up in the first place but here it is:

  1. /* South Coast Serenity Inn (SSI) Automated Reservation and Booking System */
  2.  
  3. /*
  4. FILE NAME: SSI_SYSTEM.c
  5. COMPILER: Borland C++ 5.02
  6.  
  7. AUTHOR: knight fyre
  8.  
  9. DATE: April, 2008
  10. COURSE: Programming Using C
  11. TITLE: Class Project
  12.  
  13. GROUP: PBCMS 1
  14. FACULTY: SCIT */
  15.  
  16.  
  17. // INCLUDED LIBRARIES
  18. #include <stdio.h>
  19. #include <conio.h>
  20. #include <stdlib.h>
  21. #include <time.h> // needed for time function
  22. #include <string.h> // needed for string compare function
  23. #include <dos.h> // needed for sleep function
  24. #include <ctype.h> // needed for tolower function
  25.  
  26. // MACROS - Used in the local room_assigner function
  27. #define TRUE 1
  28. #define FALSE 0
  29.  
  30.  
  31.  
  32. /* ----------GLOBAL DATA----------- */
  33.  
  34. // STRUCTURES
  35.  
  36. // Structure for storing information about the rooms (ROOM_DATA)
  37. typedef struct{
  38. int room_num; // room number must be between 1 - 50 inclusively
  39. int room_type; //1- smoking 2- non-smoking
  40. float room_rate;
  41. int room_status; //9-reserve 10-vacant 12-occupied
  42. } ROOM_DATA;
  43.  
  44. // Structure for storing information about the guests (ADMISSION_DATA)
  45. typedef struct{
  46. int reservation_num;
  47. int guest_num;
  48. char first_name[20];
  49. char MI[2]; // middle initial
  50. char last_name[20];
  51. int credit_card; // credit card number
  52. int telephone;
  53. float charge; // (bill) charge = room_rate * lengh_stay
  54. int cancel; // 1 - no , 2 - yes
  55. int length_stay; // during of visit in days
  56. ROOM_DATA room_connec; // ROOM_DATA is a member of ADMISSION_DATA
  57. } ADMISSION_DATA;
  58.  
  59.  
  60. // STRUCT NAME ASSIGNMENT - Initialization with blank data
  61. static ADMISSION_DATA section={NULL,NULL,"","","",0,999,0.00,1,0};
  62. static ROOM_DATA room={NULL,1,0.00,10};
  63.  
  64.  
  65. // FUNCTIONS
  66. void menu();
  67. void addReserve();
  68. void cancelReserve();
  69. void checkin();
  70. void checkout();
  71. void incomereport();
  72. void room_available_report();
  73. void reservation_report();
  74. void room_info_menu(); // includes add room data capability
  75. void all_guests_report(); // list details of all reserved and checked-in guests
  76.  
  77. /* ----END OF GLOBAL DATA---- */
  78.  
  79.  
  80.  
  81. // MAIN FUNCTION
  82. int main()
  83. {
  84. menu(); // call to user main menu
  85.  
  86. sleep(2); // pauses screen for 2 seconds
  87. return 0; // Retuns zero indicating successful program termination
  88. } // END OF MAIN
  89.  
  90.  
  91.  
  92.  
  93. // FUNCTION IMPLEMENTATIONS
  94.  
  95.  
  96. /* +++++++++MENU FUNCTION+++++++++ */
  97. void menu()
  98. {
  99. int choice; // variable for storing user's choice
  100.  
  101. do{
  102. // clears the console of all output - system call works on Windows and Unix / Linux Systems
  103. if( system( "cls" ) != 0 ) system( "clear" );
  104.  
  105. // ASCII ART BANNER
  106. textcolor(4); // specifies a particular colour for cprintf
  107. cprintf("+-+-+-+-+-+ +-+-+-+-+-+ +-+-+-+-+-+-+"); // cprintf is capable of printing statements in colour
  108. printf("\n");
  109. textcolor(13);
  110. cprintf("|S.o.u.t.h| |C.o.a.s.t| |S.y.s.t.e.m|");
  111. printf("\n");
  112. textcolor(4);
  113. cprintf("+-+-+-+-+-+ +-+-+-+-+-+ +-+-+-+-+-+-+");
  114. // END OF BANNER
  115.  
  116. // Program menu with user prompt
  117. textcolor(14);
  118. printf("\n\n\n");
  119. cprintf("Welcome to South Coast Serenity Inn Guest Manangement System");
  120. printf("\n\n");
  121. textcolor(15);
  122. cprintf("To Exit the Program, Select -1 Followed by the Enter or Return Key");
  123. textcolor(14);
  124. printf("\n\n");
  125. cprintf("Please Select the Number For the Corresponding Request.\n");
  126.  
  127. // USER OPTIONS
  128. textcolor(14); printf("\n"); cprintf("(1)"); printf("\t"); textcolor(15); cprintf("Add Reservation");
  129. textcolor(14); printf("\n"); cprintf("(2)"); printf("\t"); textcolor(15); cprintf("Cancel Reservation");
  130. textcolor(14); printf("\n"); cprintf("(3)"); printf("\t"); textcolor(15); cprintf("Guest Check-In");
  131. textcolor(14); printf("\n"); cprintf("(4)"); printf("\t"); textcolor(15); cprintf("Guest Check-Out");
  132. textcolor(14); printf("\n"); cprintf("(5)"); printf("\t"); textcolor(15); cprintf("Income Report");
  133. textcolor(14); printf("\n"); cprintf("(6)"); printf("\t"); textcolor(15); cprintf("Room Status Report");
  134. textcolor(14); printf("\n"); cprintf("(7)"); printf("\t"); textcolor(15); cprintf("Reservation Report");
  135. textcolor(14); printf("\n"); cprintf("(8)"); printf("\t"); textcolor(15); cprintf("Room Information Sub-Menu");
  136. textcolor(14); printf("\n"); cprintf("(9)"); printf("\t"); textcolor(15); cprintf("All Guests");
  137. // END OF USER OPTIONS
  138.  
  139. textcolor(14); printf("\n\n"); cprintf("Enter Your Selection Now: ");
  140. scanf("%d", &choice);
  141.  
  142. if( system( "cls" ) != 0 ) system( "clear" ); // clears the console before displaying sub-menu
  143.  
  144. switch(choice) // contains all global function calls
  145. {
  146. case 1:
  147. addReserve();
  148. break;
  149.  
  150. case 2:
  151. cancelReserve();
  152. break;
  153.  
  154. case 3:
  155. checkin();
  156. break;
  157.  
  158. case 4:
  159. checkout();
  160. break;
  161.  
  162. case 5:
  163. incomereport();
  164. break;
  165.  
  166. case 6:
  167. room_available_report();
  168. break;
  169.  
  170. case 7:
  171. reservation_report();
  172. break;
  173.  
  174. case 8:
  175. room_info_menu();
  176. break;
  177.  
  178. case 9:
  179. all_guests_report();
  180. break;
  181.  
  182. default:
  183. textcolor(12); // sets unspecified colour prints to light red
  184. (choice == -1?textcolor(10), cprintf("SSI SYSTEM SHUTTING DOWN"): cprintf("\nONLY 1 - 9 ARE VALID OPTIONS"));
  185. sleep(3);
  186. }
  187.  
  188. }while(choice <= -2 || choice >= 0); // only -1 can end the menu function, hence returns control to main menu effectively closing the program
  189. }
  190.  
  191.  
  192.  
  193. /* +++++++ADD NEW RESERVATION FUNCTION+++++++ */
  194. void addReserve()
  195. {
  196. int room_assigner(int, int); // local function for assigning a user to a room
  197. void create_reservations(); // local function for creating reservations.txt file
  198. char uoption; // user's choice
  199. int res_num; // reservation number assigned to a specific guest (1 - 50)
  200. FILE *reserver; // reservations.txt file pointer
  201. srand(time(NULL)); // seeds rand function to generate guest number
  202.  
  203. // fopen opens the reservations.txt file, attempts to create one if cannot be opened
  204. if((reserver=fopen("reservations.txt", "rb+"))==NULL)
  205. {
  206. textcolor(12); cprintf("\nERROR!! FILE COULD NOT BE OPENED!"); sleep(3);
  207. printf("\n");
  208. textcolor(10); cprintf("\nATTEMPTING TO CREATE RESERVATIONS FILE"); sleep(1);
  209. create_reservations(); // function call to generate reservations.txt file
  210. }
  211. else
  212. {
  213. printf("Welcome to the Add Reservation Section!");
  214.  
  215. do{ // user prompt
  216. printf("\n\nEnter a reservation number: ");
  217. scanf("%d", &res_num);
  218.  
  219. if( res_num > 0 && res_num < 51 ) // A maximum of 50 rooms can be reserved
  220. {
  221. // sets the pointer to the reservation specified by the user
  222. fseek( reserver, (res_num - 1) * sizeof ( ADMISSION_DATA ), SEEK_SET );
  223. // reads a record from the file into the section structure
  224. fread( &section, sizeof( ADMISSION_DATA ), 1, reserver );
  225.  
  226. // checks if record is blank
  227. if(section.reservation_num != 0)
  228. {
  229. printf("\nA reservation already exits in this slot");
  230. }
  231. else
  232. {
  233. // user prompts
  234. printf("\nEnter First Name: ");
  235. scanf("%s",&section.first_name);
  236.  
  237. printf("\nEnter Middle Initial: %c");
  238. scanf("%s", &section.MI);
  239.  
  240. printf("\nEnter Last Name: ");
  241. scanf("%s",&section.last_name);
  242.  
  243. printf("\nEnter credit card number: ");
  244. scanf("%d",&section.credit_card);
  245.  
  246. printf("\nCell, Home, or Work #: ");
  247. scanf("%d", &section.telephone);
  248.  
  249. printf( "\nNumber of days of stay: " );
  250. scanf("%d", &section.length_stay);
  251.  
  252. textcolor(10); printf("\n"); cprintf("DATA VERIFIED"); sleep(2);
  253.  
  254. printf("\n\nEnter room type (1 for smoking and 2 non-smoking): ");
  255. scanf("%d", &section.room_connec.room_type); //1-smoking 2-non-smoking
  256.  
  257. if( section.room_connec.room_type == 1 || section.room_connec.room_type == 2 )
  258. {
  259. // call to room_assigner function to locate and assigns a room - returns the number of the avaliable room
  260. section.room_connec.room_num = room_assigner(section.room_connec.room_type, 9);
  261.  
  262. // zero indicates that a free room was not located
  263. if(section.room_connec.room_num == 0)
  264. {
  265. printf("\n\nNo space avaliable");
  266. }
  267. else
  268. {
  269. textcolor(10); printf("\n"); cprintf("ROOM FOUND"); printf("\n\nYour Room Number is: %d", section.room_connec.room_num); sleep(2);
  270.  
  271. section.reservation_num = res_num;
  272. // random # is generated for guest
  273. section.guest_num = rand()% (30000 - 1 + 1) + 1;
  274.  
  275. // calculates bill based on room type and length of stay
  276. section.charge=((section.room_connec.room_type==1)?4000*section.length_stay:3000*section.length_stay);
  277.  
  278. // moves file pointer to the correct record in the file
  279. fseek( reserver, ( section.reservation_num - 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
  280. // writes contents of section into the record in file
  281. fwrite( &section, sizeof( ADMISSION_DATA ), 1, reserver );
  282. }
  283. }
  284. else
  285. {
  286. textcolor(12); printf("\n"); cprintf("ONLY 1 AND 2 ARE VALID OPTIONS"); sleep(1);
  287. textcolor(12); printf("\n\n"); cprintf("RESERVATION PROCESS ABORTED"); sleep(3);
  288. }
  289. }
  290.  
  291. section.reservation_num = 0;
  292. }
  293. else
  294. {
  295. textcolor(12); printf("\n"); cprintf("RESERVATION NUMBER MUST BE GREATER THAN 0 AND LESS THAN 51"); sleep(6);
  296. }
  297.  
  298. printf("\n\nDo you wish to continue? Any key for Yes, (n) for No: ");
  299. fflush(stdin); // clears input buffer
  300. scanf("%c",&uoption);
  301. if( system( "cls" ) != 0 ) system( "clear" );
  302. }while( tolower(uoption)!='n' ); // only the character 'n' can end the loop
  303. }
  304. fclose ( reserver ); // fclose closes the reservations.txt file
  305. }
  306.  
  307.  
  308.  
  309. /* +++++++++CREATE NEW RESERVATION FILE FUNCTION+++++++++ */
  310. void create_reservations()
  311. {
  312. FILE *reserver; // reservations.txt file pointer
  313. int count = 1;
  314.  
  315. // fopen opens reservations.txt file; exits if file cannot be opened
  316. if(( reserver = fopen( "reservations.txt", "wb" )) == NULL)
  317. {
  318. textcolor(12); cprintf("\nERROR!! RESERVATION FILE COULD NOT BE CREATED!"); sleep(3);
  319. }
  320. else
  321. { // output 50 blank records to the file
  322. for(; count <=50; count++ )
  323. {
  324. fwrite( &section, sizeof( ADMISSION_DATA ), 1, reserver );
  325. }
  326. textcolor(10); printf("\n\n"); cprintf("RESERVATION FILE SUCCESSFULLY CREATED"); sleep(3);
  327. }
  328. fclose( reserver ); // fclose closes the reservations.txt file
  329. }
  330.  
  331.  
  332.  
  333. /* ++++++++ROOM ASSIGNMENT FUNCTION+++++++ */
  334. int room_assigner(int type, int status) // type (1- smoking 2- non-smoking); status (9-reserve 10-vacant 12-occupied)
  335. {
  336. FILE *roomPtr; // rooms.txt file pointer
  337. int r_num = 1; // room number
  338. int found = FALSE; // macro TRUE = 1, FALSE = 0
  339. int seeker = 1; // traverses through each record
  340.  
  341. // fopen opens the rooms.txt file, exits function if file cannot be opened
  342. if((roomPtr = fopen("rooms.txt", "rb+")) == NULL)
  343. {
  344. textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
  345. }
  346. else
  347. {
  348. do
  349. { // seeker positions file pointer to correct record in file
  350. fseek( roomPtr, ( seeker - 1) * sizeof( ROOM_DATA ), SEEK_SET);
  351. // reads record from the file into the room structure
  352. fread( &room, sizeof( ROOM_DATA ), 1, roomPtr );
  353.  
  354. if( room.room_num != NULL ) // checks for blank record
  355. {
  356. if( room.room_status == 10 ) // checks if room is avaliable
  357. {
  358. // room type is smoking AND user selected smoking
  359. if (room.room_type == 1 && type == 1)
  360. {
  361. room.room_rate = 4000; // smoking rate is $4000
  362. room.room_num = room.room_num;
  363. room.room_type = room.room_type;
  364. room.room_status = status;
  365. r_num = room.room_num; // assigns the available room to r_num
  366.  
  367. // seeker positions file pointer to correct record in file
  368. fseek( roomPtr, ( seeker - 1) * sizeof( ROOM_DATA ), SEEK_SET);
  369. // writes the contents of room is a record in the file
  370. fwrite( &room, sizeof( ROOM_DATA ), 1, roomPtr );
  371.  
  372. found = TRUE; // assigns true when a room is found
  373. }
  374.  
  375. // room type is non-smoking AND user selected non-smoking
  376. if(room.room_type == 2 && type == 2)
  377. {
  378. room.room_rate = 3000; // smoking rate is $3000
  379. room.room_num = room.room_num;
  380. room.room_type = room.room_type;
  381. room.room_status = status;
  382. r_num = room.room_num; // assigns the available room to r_num
  383.  
  384. // seeker positions file pointer to correct record in file
  385. fseek( roomPtr, ( seeker - 1) * sizeof( ROOM_DATA ), SEEK_SET);
  386. // writes the contents of room is a record in the file
  387. fwrite( &room, sizeof( ROOM_DATA ), 1, roomPtr );
  388.  
  389. found = TRUE; // assigns true when a room is found
  390. }
  391.  
  392. // available room type and desired type were not a match
  393. if( room.room_type != type )
  394. {
  395. seeker++; // increments if not a match
  396. }
  397. }
  398. else
  399. {
  400. seeker++; // increments if room not available
  401. }
  402. }
  403. else
  404. {
  405. seeker++; // increments if no data was set for that room
  406. }
  407. }while(found == FALSE && !feof(roomPtr)); // loop ends only if a empty room was found or the end of the file is reached
  408. }
  409. (( found == FALSE )? r_num = 0 : NULL ); // if feof occurs and found is still false, r_num is set to zero
  410. fclose ( roomPtr ); // fclose closes the rooms.txt file
  411.  
  412. return r_num; // return the choosen room, if zero then a room was not found
  413. }
  414.  
  415.  
  416.  
  417. /* ++++++++CANCEL RESERVATION FUNCTION++++++++ */
  418. void cancelReserve()
  419. {
  420. FILE *reserver; // reservations.txt file pointer
  421. FILE *roomPtr; // rooms.txt file pointer
  422. FILE *logger; // guest_history.txt file pointer
  423. int res_num; // reservation number
  424. int rm_num; // room number
  425. int confirm;
  426.  
  427. // create ADMISSION_DATA with no information
  428. static ADMISSION_DATA res_remover={NULL,NULL,"","","",0,999,0.00,1,0};
  429.  
  430. // fopen opens the file; exits if file cannot be opened
  431. if((roomPtr = fopen( "rooms.txt", "rb+" )) == NULL )
  432. {
  433. textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
  434. }
  435. else
  436. { // fopen opens the file; exits if file cannot be opened
  437. if((reserver = fopen( "reservations.txt", "rb+")) == NULL)
  438. {
  439. textcolor(12); cprintf("\nERROR!! RESERVATION FILE COULD NOT BE OPENED!"); sleep(3);
  440. }
  441. else
  442. {
  443. printf("Welcome to the Cancel Reservation Section!");
  444.  
  445. printf("\n\nEnter reservation number to cancel: ");
  446. scanf("%d", &res_num);
  447.  
  448. // positions file pointer to the correct record in file
  449. fseek( reserver, (res_num - 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
  450. // reads record from file in section structure
  451. fread( &section, sizeof ( ADMISSION_DATA ), 1, reserver );
  452.  
  453. // checks to see if reservation was made; # must be (1 - 50)
  454. if( section.reservation_num == 0 )
  455. {
  456. textcolor(12); cprintf("\nINVALID!! RESERVATION DOES NOT EXIST!"); sleep(3);
  457. }
  458. else
  459. {
  460. // displays guest details for confirmation purposes
  461. printf("\n%d\t%s\t%s\t%d", section.reservation_num, section.first_name, section.last_name, section.credit_card);
  462. printf("\n\nConfirm Check-out? (1 for yes, 2 for no): ");
  463. scanf("%d", &confirm);
  464.  
  465. if (confirm == 1)
  466. {
  467. // fopen opens/creates the file for appending; exits if file cannot be opened/created
  468. if((logger = fopen("guest_history.txt", "ab")) == NULL )
  469. {
  470. textcolor(12); cprintf("\nERROR!! HISTORY FILE COULD NOT BE CREATED!"); sleep(3);
  471. }
  472. else
  473. {
  474. rm_num = section.room_connec.room_num;
  475.  
  476. // rm_num positions file pointer to the correct record in file
  477. fseek ( roomPtr, ( rm_num - 1 ) * sizeof( ROOM_DATA ), SEEK_SET );
  478. // reads record from file in room structure
  479. fread ( &room, sizeof( ROOM_DATA ), 1, roomPtr );
  480.  
  481. // Writes to guest_history file
  482. fseek( logger, ( NULL ) * sizeof( ADMISSION_DATA ), SEEK_SET );
  483. fread( &section, sizeof ( ADMISSION_DATA ), 1, logger );
  484. section.cancel = 2; // 2 = reservation was cancelled
  485. section.charge = room.room_rate * .01; // cancellations subject to 1% charge on room cost
  486. section.room_connec.room_rate = room.room_rate; // needed for display in income_report function
  487.  
  488. // rm_num positions file pointer to the correct record in file
  489. fseek( logger, ( NULL ) * sizeof( ADMISSION_DATA ), SEEK_SET );
  490. // reads record from file in room structure
  491. fwrite( &section, sizeof( ADMISSION_DATA ), 1, logger );
  492. // end of guest_history writer
  493.  
  494. rm_num = section.room_connec.room_num;
  495.  
  496. // Updates room.txt
  497. fseek ( roomPtr, ( rm_num - 1 ) * sizeof( ROOM_DATA ), SEEK_SET );
  498. fread ( &room, sizeof( ROOM_DATA ), 1, roomPtr );
  499. room.room_status = 10;
  500. fseek ( roomPtr, ( rm_num - 1 ) * sizeof( ROOM_DATA ), SEEK_SET );
  501. fwrite( &room, sizeof( ROOM_DATA ), 1, roomPtr );
  502. // end of rooms.txt updater
  503.  
  504. // Erases reservation record by writing blank data
  505. fseek( reserver, (res_num - 1) * sizeof( ADMISSION_DATA ), SEEK_SET );
  506. fwrite( &res_remover, sizeof( ADMISSION_DATA ),1 ,reserver );
  507.  
  508. // update confirmation
  509. textcolor(10); printf("\n"); cprintf("RESERVATION SUCCESSFULLY CANCELLED"); sleep(3);
  510. }
  511. }
  512. else
  513. {
  514. if (confirm == 2)
  515. {
  516. printf("\nReservation Cancellation process aborted");
  517. }
  518. else
  519. {
  520. printf("\nOnly 1 or 2 maybe selected");
  521. }
  522. _getch(); // pauses the screen until the user enters any value
  523. }
  524. fclose(logger); // flcose closes guest_history.txt file
  525. }
  526. fclose(reserver); // flcose closes reservations.txt file
  527. fclose(roomPtr); // flcose closes rooms.txt file
  528. }
  529. }
  530. if( system( "cls" ) != 0 ) system( "clear" ); // clears the console of all output before returning to main menu
  531. }
  532.  
  533.  
  534.  
  535. /* ++++++++GUEST CHECK-IN FUNCTION++++++++ */
  536. void checkin()
  537. {
  538. int res_num = 0; // reservation number
  539. int confirm;
  540. FILE *reserver; // reservations.txt file pointer
  541. FILE *roomPtr; // rooms.txt file pointer
  542.  
  543. // fopen opens rooms.txt file; exits if cannot be opened
  544. if(( roomPtr=fopen("rooms.txt", "rb+")) == NULL)
  545. {
  546. textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
  547. }
  548. else
  549. { // fopen opens reservations.txt file; exits if cannot be opened
  550. if((reserver=fopen("reservations.txt","rb+"))==NULL)
  551. {
  552. textcolor(12); cprintf("\nERROR!! RESERVATION FILE COULD NOT BE OPENED!"); sleep(3);
  553. }
  554. else
  555. {
  556. printf("Welcome to the Check-In Section!");
  557.  
  558. printf("\n\nPlease enter the reservation number: ");
  559. scanf("%d",&res_num);
  560.  
  561. fseek( reserver, ( res_num - 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
  562. fread( &section, sizeof( ADMISSION_DATA ), 1, reserver );
  563.  
  564. // checks to see if a reservation was made
  565. if( section.reservation_num == 0 )
  566. {
  567. textcolor(12); cprintf("\nINVALID!! NO RESERVATION WAS MADE!"); sleep(3);
  568. }
  569. else
  570. { // displays reserver's details for confirmation purposes
  571. printf("\n%d\tMr/Ms. %s %s\t Credit Card: %d", section.guest_num, section.first_name, section.last_name, section.credit_card);
  572. printf("\n\nConfirm Check-In? (1 for yes, 2 for no): ");
  573. scanf("%d", &confirm);
  574.  
  575. if (confirm == 1) // if the users selected yes
  576. {
  577. fseek( roomPtr, ( section.room_connec.room_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );
  578. fread( &room, sizeof( ROOM_DATA ), 1, roomPtr );
  579.  
  580. room.room_status = 12; // 12 = occupied
  581.  
  582. fseek( roomPtr, ( section.room_connec.room_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );
  583. fwrite( &room, sizeof( ROOM_DATA ), 1, roomPtr);
  584.  
  585. // confirmation message
  586. printf("\n\nMr/Ms. %s %s sucessfully checked-in", section.first_name, section.last_name);
  587. sleep(2);
  588. }
  589. else
  590. {
  591. if (confirm == 2) // if the users selected no
  592. {
  593. printf("\nCheck-In process cancelled");
  594. sleep(2);
  595. }
  596. else
  597. {
  598. printf("\nOnly 1 or 2 maybe selected");
  599. sleep(2);
  600. }
  601. }
  602. }
  603. fclose ( reserver ); // flcose closes reservations.txt file
  604. }
  605. fclose ( roomPtr ); // flcose closes reservations.txt file
  606. }
  607. }
  608.  
  609.  
  610.  
  611. /* +++++++GUEST CHECK-OUT FUNCTION+++++++++ */
  612. void checkout()
  613. {
  614. FILE *reserver; // reservations.txt file pointer
  615. FILE *roomPtr; // rooms.txt file pointer
  616. FILE *logger; // guest_history file pointer
  617. int res_num; // reservation number
  618. int confirm;
  619. int rm_num; // room number
  620.  
  621. // create ADMISSION_DATA with no information
  622. static ADMISSION_DATA booking_remover={NULL,NULL,"","","",0,999,0.00,1,0};
  623.  
  624. // fopen opens the file; exits if file cannot be opened
  625. if(( roomPtr=fopen("rooms.txt", "rb+")) == NULL )
  626. {
  627. textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
  628. }
  629. else
  630. { // fopen opens the file; exits if file cannot be opened
  631. if((reserver=fopen("reservations.txt","rb+"))==NULL)
  632. {
  633. textcolor(12); cprintf("\nERROR!! RESRVATION FILE COULD NOT BE OPENED!"); sleep(3);
  634. }
  635. else
  636. {
  637. printf("Welcome to the Check-Out Section!");
  638.  
  639. printf("\n\nPlease enter the reservation number:");
  640. scanf("%d",&res_num);
  641. // positions file pointer to the correct record in file
  642. fseek( reserver, ( res_num - 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
  643. // reads record from file in section structure
  644. fread( &section, sizeof( ADMISSION_DATA ), 1, reserver );
  645.  
  646. // checks to see if reservation was made; # must be (1 - 50)
  647. if( section.reservation_num == 0 )
  648. {
  649. textcolor(12); cprintf("\nINVALID!! NO RESERVATION WAS MADE/GUEST NOT CHECKED-IN!"); sleep(3);
  650. }
  651. else
  652. { // fopen opens/creates the file for appending; exits if file cannot be opened/created
  653. if((logger = fopen("guest_history.txt", "ab")) == NULL )
  654. {
  655. cprintf("\nERROR!! HISTORY FILE COULD NOT BE CREATED!"); sleep(3);
  656. }
  657. else
  658. {
  659. // displays guest details for confirmation purposes
  660. printf("\n%d\t%s\t%s\t%d", section.reservation_num, section.first_name, section.last_name, section.credit_card);
  661. printf("\n\nConfirm Check-out? (1 for yes, 2 for no): ");
  662. scanf("%d", &confirm);
  663.  
  664. if (confirm == 1)
  665. {
  666. rm_num = section.room_connec.room_num;
  667.  
  668. // rm_num positions file pointer to the correct record in file
  669. fseek ( roomPtr, ( rm_num - 1 ) * sizeof( ROOM_DATA ), SEEK_SET );
  670. // reads record from file in room structure
  671. fread ( &room, sizeof( ROOM_DATA ), 1, roomPtr );
  672.  
  673. // Writes to guest_history file
  674. fseek( logger, ( NULL ) * sizeof( ADMISSION_DATA ), SEEK_SET ); // &&&&&&&& END
  675. fread( &section, sizeof ( ADMISSION_DATA ), 1, logger );
  676. section.cancel = 1; // 1 = reservation was NOT cancelled
  677. section.charge = room.room_rate * section.length_stay;
  678. section.room_connec.room_rate = room.room_rate;
  679. fseek( logger, ( NULL ) * sizeof( ADMISSION_DATA ), SEEK_SET ); // &&&&&&&& END
  680. fwrite( &section, sizeof( ADMISSION_DATA ), 1, logger );
  681. // end of guest_history writer
  682.  
  683. // Guest Invoice/Bill
  684. if( system( "cls" ) != 0 ) system( "clear" );
  685. printf("\n*******************SSI INVOICE*************************\n\n");
  686. printf("Guest Name\t: %s %s. %s\n", section.first_name, section.MI, section.last_name);
  687. printf("Room Number\t: %d\n", section.room_connec.room_num);
  688. printf("Room Type\t: ");
  689. (section.room_connec.room_num == 1?printf("Smoking\n"):printf("Non-Smoking\n"));
  690. printf("Amount\t\t: JMD $ %.2f\t US $ %.2f\n", section.room_connec.room_rate, (section.room_connec.room_rate / 72));
  691. printf("\n*******************************************************\n");
  692. _getch();
  693. // End of Invoice
  694.  
  695. rm_num = section.room_connec.room_num;
  696.  
  697. // Erases reservation record by writing blank data
  698. fseek( reserver, ( res_num - 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
  699. fwrite( &booking_remover, sizeof( ADMISSION_DATA ),1 ,reserver );
  700.  
  701. // Updates room.txt
  702. fseek( roomPtr, ( rm_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );
  703. fread( &room, sizeof( ROOM_DATA ), 1, roomPtr );
  704. room.room_status = 10;
  705. fseek( roomPtr, ( rm_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );
  706. fwrite( &room, sizeof( ROOM_DATA ), 1, roomPtr);
  707.  
  708. // confirmation message printed
  709. textcolor(10); printf("\n"); cprintf("GUEST SUCCESSFULLY CHECKED-OUT"); sleep(3);
  710. }
  711. else
  712. {
  713. if (confirm == 2)
  714. {
  715. printf("\nCheck-out process cancelled");
  716. }
  717. else
  718. {
  719. printf("\nOnly 1 or 2 maybe selected");
  720. }
  721. _getch();
  722. }
  723. }
  724. }
  725. }
  726. fclose( reserver ); // fclose closes reservations.txt file
  727. }
  728. fclose( roomPtr ); // fclose closes rooms.txt file
  729. }
  730.  
  731.  
  732.  
  733. /* +++++++INCOME REPORT FUNCTION++++++++ */
  734. void incomereport()
  735. {
  736. void insertion_sort(); // local function for sorting guests of the guest_history.txt alphabetically
  737. FILE *logger; // guest_history.txt file pointer
  738. float total_cancel = 0.00; // total income from cancellations
  739. float total_chk_out = 0.00; // total income from checked-out guests
  740. float grand_total; // TOTAL INCOME (total_cancel + total_chk_out)
  741.  
  742. // fopen opens file, attempts to create one if cannot be opened
  743. if(( logger = fopen("guest_history.txt", "rb")) == NULL )
  744. {
  745. textcolor(12); cprintf("\nERROR!! HISTORY FILE COULD NOT BE OPENED!"); sleep(3);
  746. }
  747. else
  748. {
  749. insertion_sort(); // call to function for alphabetical sorting
  750.  
  751. printf( "---------------------------CHECKED-OUT GUESTS-------------------------------\n" );
  752.  
  753. // reads all the records of the file
  754. while ( fread( &section, sizeof (ADMISSION_DATA), 1, logger ) == 1 )
  755. {
  756. if( section.cancel == 1) // checks for cancellations
  757. {
  758. // formatted output for report
  759. printf("\nFirst Name:\t%s\n", section.first_name);
  760. printf("Last Name:\t%s\n", section.last_name);
  761. printf("Middle I.:\t%s\t\t", section.MI);
  762. printf("Room Rate:\t%.2f\t", section.room_connec.room_rate);
  763. printf(" Duration:\t%d\n", section.length_stay);
  764. printf("Guest Num:\t%d\t\t", section.guest_num);
  765. printf("Charge:\t\t%.2f\n", section.charge);
  766.  
  767. total_chk_out += section.charge; // calculates total check-out charges collected
  768. }
  769. }
  770.  
  771. rewind( logger ); // sets pointer to beginning of file
  772.  
  773. printf( "\n\n\n--------------------------CANCELLED RESERVATION------------------------------\n" );
  774.  
  775. // reads all the records of the file
  776. while ( fread( &section, sizeof (ADMISSION_DATA), 1, logger ) == 1 )
  777. {
  778. if( section.cancel == 2) // checks for checked-out guests
  779. {
  780. // formatted output for report
  781. printf("\nFirst Name:\t%s\n", section.first_name);
  782. printf("Last Name:\t%s\n", section.last_name);
  783. printf("Middle I.:\t%s\t\t", section.MI);
  784. printf("Room Rate:\t%.2f\t", section.room_connec.room_rate);
  785. printf(" Duration:\t%d\n", section.length_stay);
  786. printf("Guest Num:\t%d\t\t", section.guest_num);
  787. printf("Charge:\t\t%.2f\n", section.charge);
  788.  
  789. total_cancel += section.charge; // calculates total reservation cancellation charges collected
  790. }
  791. }
  792.  
  793. grand_total = total_chk_out + total_cancel; // calculates grand total
  794.  
  795. printf("\n\n\nTOTAL CANCELLATIONS:\t$ %.2f\nINCOME:\t\t\t$ %.2f\nGRAND TOTAL:\t\t$ %.2f", total_cancel, total_chk_out, grand_total);
  796. _getch();
  797. }
  798. fclose( logger ); // fclose closes guest_history.txt file
  799. }
  800.  
  801.  
  802.  
  803. /* +++++++++INSERTION SORT FUNCTION +++++++++++ */
  804. void insertion_sort()
  805. {
  806. FILE *guest_Ptr; // guest_history.txt file pointer
  807. int size=0; // represents the total # of records in the file
  808. int outer_run;
  809. int inner_run;
  810. int grand_run=0; // ensures that all the records are sorted
  811.  
  812. // blank structure which stores the smallest value
  813. ADMISSION_DATA small = {NULL,NULL,"","","",0,999,0.00,1,0};
  814.  
  815. // fopen opens the guest_history.txt file, exits function is file cannot be opened
  816. if( (guest_Ptr = fopen("guest_history.txt", "rb+")) == NULL )
  817. {
  818. textcolor(12); cprintf("\nERROR!! HISTORY FILE COULD NOT BE OPENED!"); sleep(3);
  819. }
  820. else
  821. {
  822. // counts the number of guest records in the file
  823. while ( fread( &section, sizeof (ADMISSION_DATA), 1, guest_Ptr ) == 1 )
  824. {
  825. size++;
  826. }
  827. // sets pointer to start of file
  828. rewind( guest_Ptr );
  829.  
  830. grand_run -= size;
  831.  
  832. // sort loop equal to the number of records to ensure 100% file sort
  833. while (grand_run <= 0)
  834. { // START OF SORTING ALGORITHM
  835. for(outer_run = 1; outer_run < size; outer_run++)
  836. {
  837. fseek( guest_Ptr, ( outer_run ) * sizeof( ADMISSION_DATA ), SEEK_SET );
  838. fread( &section, sizeof( ADMISSION_DATA ), 1, guest_Ptr );
  839. small = section;
  840.  
  841. rewind ( guest_Ptr );
  842.  
  843. inner_run = outer_run - 1;
  844.  
  845. fseek( guest_Ptr, ( inner_run ) * sizeof( ADMISSION_DATA ), SEEK_SET );
  846. fread( &section, sizeof( ADMISSION_DATA ), 1, guest_Ptr );
  847. rewind ( guest_Ptr );
  848.  
  849. for(; inner_run >= 0 && (strcmp( small.first_name, section.first_name) <= 0 ); inner_run--)
  850. {
  851. fseek( guest_Ptr, ( inner_run ) * sizeof( ADMISSION_DATA ), SEEK_SET );
  852. fread( &section, sizeof( ADMISSION_DATA ), 1, guest_Ptr );
  853.  
  854. fseek( guest_Ptr, ( inner_run + 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
  855. fwrite( &section, sizeof( ADMISSION_DATA ), 1, guest_Ptr );
  856. }
  857.  
  858. fseek( guest_Ptr, ( inner_run + 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
  859. fwrite( &small, sizeof( ADMISSION_DATA ), 1, guest_Ptr );
  860. }
  861. // END OF SORTING ALGORITHM
  862. grand_run++; // grant_run incremented by one until zero is reached
  863. }
  864. }
  865. fclose( guest_Ptr ); // flcose closes the guest_history file
  866. } // Control is returned to the report function
  867.  
  868.  
  869.  
  870. /* ++++++++ROOM AVAILABILITY REPORT+++++++++ */
  871. void room_available_report()
  872. {
  873. FILE *roomPtr; // rooms.txt file pointer
  874.  
  875. // fopen opens the rooms.txt file; exits function if file cannot be opened
  876. if(( roomPtr = fopen( "rooms.txt", "rb")) == NULL)
  877. {
  878. textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
  879. }
  880. else
  881. {
  882. textcolor(14);
  883. cprintf("----------AVALIABLE SMOKING ROOMS---------------");
  884. textcolor(15);
  885. printf("\n");
  886. cprintf("R_NUM R_TYPE R_RATE R_STATUS");
  887.  
  888. // reads through all records in the file
  889. while ( (fread( &room, sizeof (ROOM_DATA), 1, roomPtr)) == 1 )
  890. {
  891. // room data must be set, type must be smoking, and status set to available
  892. if( room.room_num != 0 && room.room_type == 1 && room.room_status == 10)
  893. {
  894. printf( "\n%d\t\t%d\t%.2f\t\t%d", room.room_num, room.room_type, room.room_rate, room.room_status );
  895. }
  896. }
  897.  
  898. rewind( roomPtr ); // sets pointer to beginning of file
  899.  
  900. printf("\n\n");
  901. textcolor(14);
  902. cprintf("----------AVALIABLE NON-SMOKING ROOMS-----------");
  903. textcolor(15);
  904. printf("\n");
  905. cprintf("R_NUM R_TYPE R_RATE R_STATUS");
  906.  
  907. // reads through all records in the file
  908. while ( (fread( &room, sizeof (ROOM_DATA), 1, roomPtr)) == 1 )
  909. {
  910. // room data must be set, type must be non-smoking, and status set to available
  911. if( room.room_num != 0 && room.room_type == 2 && room.room_status == 10)
  912. {
  913. printf( "\n%d\t\t%d\t%.2f\t\t%d", room.room_num, room.room_type, room.room_rate, room.room_status );
  914. }
  915. }
  916. getchar(); // waits for user to enter character from the keyboard
  917. fclose ( roomPtr ); // fclose closes rooms.txt file
  918. }
  919. if( system( "cls" ) != 0 ) system( "clear" ); // clears the console
  920. }
  921.  
  922.  
  923.  
  924. /* +++++++RESERVATION REPORT+++++++ */
  925. void reservation_report()
  926. {
  927. FILE *reserver; // reservations.txt file pointer
  928. FILE *roomPtr; // rooms.txt file pointer
  929.  
  930. // fopen opens file; exits function is file cannot be opened
  931. if((reserver = fopen( "reservations.txt", "rb")) == NULL)
  932. {
  933. textcolor(12); cprintf("\nERROR!! RESERVATION FILE COULD NOT BE OPENED!"); sleep(3);
  934. }
  935. else
  936. { // fopen opens room file; exits function is file cannot be opened
  937. if (( roomPtr = fopen( "rooms.txt", "rb")) == NULL)
  938. {
  939. textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
  940. }
  941. else
  942. { // reads through all records in the file
  943. while (!feof( reserver ))
  944. { // reads reservation record into section
  945. fread( &section, sizeof ( ADMISSION_DATA ), 1, reserver);
  946. // positions pointer at room cooresponding with reservation
  947. fseek( roomPtr, ( section.room_connec.room_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );
  948. // reads room data in room
  949. fread( &room, sizeof ( ROOM_DATA ), 1, roomPtr);
  950.  
  951. // checks if a reservation was made and the room is reserved
  952. if( section.reservation_num != 0 && room.room_status == 9 )
  953. {
  954. // formatted output for report
  955. printf( "---------------RESERVATION DATA---------------\n" );
  956. printf("\nReser. Num:\t%d\t\t", section.reservation_num);
  957. printf("Credit Card\t%d\n", section.credit_card);
  958. printf("Guest Num:\t%d\t\t", section.guest_num);
  959. printf("Contact #:\t%d\n", section.telephone);
  960. printf("First Name:\t%s\t\t", section.first_name);
  961. printf("Charge:\t\t%.2f\n", section.charge);
  962. printf("Middle I.:\t%s\t\t", section.MI);
  963. printf("Duration:\t%d\n", section.length_stay);
  964. printf("Last Name:\t%s\t\t", section.last_name);
  965. printf("Cancel:\t\t%d\n\n", section.charge);
  966. printf( "---------------ROOM DATA----------------------\n" );
  967. printf("\nRoom Num:\t%d\t\t", section.room_connec.room_num);
  968. printf("Room Type:\t");
  969. (section.room_connec.room_type == 1? printf("SMOKING\n\n\n"):printf("NON-SMOKING\n\n\n"));
  970. }
  971. }
  972. getchar(); // waits for user to enter character from the keyboard
  973. }
  974. fclose ( roomPtr ); // fclose closes rooms.txt
  975. }
  976. fclose( reserver ); // fclose closes reservations.txt
  977. if( system( "cls" ) != 0 ) system( "clear" ); // clears display console
  978. }
  979.  
  980.  
  981.  
  982. /* ++++++ROOM INFORMATION SUB-MENU FUNCTION++++++++ */
  983. void room_info_menu()
  984. {
  985. FILE *roomPtr; // roomPtr = rooms.txt file pointer
  986. int count = 1;
  987. int choice; // user's choice
  988.  
  989. printf("Welcome to the room sub-menu!\n\n");
  990. printf("1\tCreates/reset room info.\n2\tModify room info\n3\tView rooms\n\nEnter your selection now: ");
  991. scanf("%d", &choice);
  992.  
  993. switch (choice)
  994. {
  995. case 1:
  996. if((roomPtr = fopen("rooms.txt", "wb")) == NULL)
  997. {
  998. textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE CREATED!"); sleep(3);
  999. }
  1000. else
  1001. {
  1002. for(; count <= 50; count++) // outputs 50 blank records to file
  1003. {
  1004. fwrite(&room, sizeof( ROOM_DATA ), 1, roomPtr );
  1005. }
  1006. textcolor(10); printf("\n\n"); cprintf("ROOM FILE SUCCESSFULLY CREATED"); sleep(3);
  1007. }
  1008. fclose( roomPtr ); // room file closed here
  1009. break;
  1010.  
  1011. case 2:
  1012. // fopen opens the file; exits if file cannot be opened
  1013. if((roomPtr = fopen("rooms.txt", "rb+")) == NULL)
  1014. {
  1015. textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
  1016. }
  1017. else
  1018. {
  1019. printf( "\nEnter Room Number ( 1 to 50, -1 to end input): " );
  1020. scanf("%d", &room.room_num);
  1021.  
  1022. while( room.room_num != -1 && room.room_num > 0 && room.room_num < 51 )
  1023. {
  1024. printf("\nEnter Room Type: ");
  1025. scanf("%d", &room.room_type);
  1026.  
  1027. switch (room.room_type) //1- smoking 2- non-smoking
  1028. {
  1029. case 1:
  1030. room.room_rate = 4000.00; // smoking rate is $4000
  1031. break;
  1032.  
  1033. case 2:
  1034. room.room_rate = 3000.00; // non-smoking rate is $3000
  1035. break;
  1036.  
  1037. default:
  1038. textcolor(12); printf("\n"); cprintf("ONLY 1 AND 2 ARE VALID OPTIONS"); printf("\n");
  1039. break;
  1040. }
  1041.  
  1042. // ensures that nothing is done if the user selects an invalid type
  1043. if ( room.room_type == 1 || room.room_type == 2)
  1044. {
  1045. room.room_status = 10; // 10 = vacant
  1046.  
  1047. // sets file pointer at room specified by user
  1048. fseek( roomPtr, (room.room_num -1) * sizeof ( ROOM_DATA ), SEEK_SET );
  1049. // updates room file
  1050. fwrite( &room, sizeof ( ROOM_DATA ), 1, roomPtr );
  1051. // user prompt
  1052. printf( "\nEnter Room Number ( 1 to 50, -1 to end input): " );
  1053. scanf("%d", &room.room_num);
  1054. }
  1055. }
  1056.  
  1057. // checks if user entered invalid option
  1058. if( room.room_num < -1 || room.room_num > 50 || room.room_num == 0 )
  1059. {
  1060. textcolor(12); printf("\n"); cprintf("ROOM NUMBER MUST BE GREATER THAN 0 AND LESS THAN 51"); sleep(5);
  1061. }
  1062. }
  1063. fclose( roomPtr ); // room file closed here
  1064. break;
  1065.  
  1066. case 3:
  1067. if(( roomPtr = fopen( "rooms.txt", "rb")) == NULL)
  1068. {
  1069. textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
  1070. }
  1071. else
  1072. {
  1073. printf("\n"); textcolor(15); cprintf("R_# RM_TYPE RM_RATE RM_STAT"); printf("\n");
  1074.  
  1075. // reads all records from the file until the end of the file (eof)
  1076. while ( !feof(roomPtr) )
  1077. {
  1078. fread( &room, sizeof( ROOM_DATA ), 1, roomPtr );
  1079.  
  1080. if( room.room_num != 0) // checks to see if user has eentered details about the room
  1081. {
  1082. printf( "%d", room.room_num );
  1083.  
  1084. if( room.room_type == 1 )
  1085. printf("\tSMOKING");
  1086.  
  1087. if( room.room_type == 2 )
  1088. printf("\tNON-SMO");
  1089.  
  1090. printf("\t\t%.2f\t\t", room.room_rate);
  1091.  
  1092. if( room.room_status == 9 )
  1093. printf("RESERVED\n");
  1094.  
  1095. if( room.room_status == 10 )
  1096. printf("VACANT\n");
  1097.  
  1098. if( room.room_status == 12 )
  1099. printf("OCCUPIED\n");
  1100. }
  1101. }
  1102. _getch();
  1103. }
  1104. fclose( roomPtr );
  1105. break;
  1106.  
  1107. default:
  1108. textcolor(12); cprintf("\nONLY 1, 2, 3 ARE VALID OPTIONS"); sleep(3);
  1109. break;
  1110. }
  1111. if( system( "cls" ) != 0 ) system( "clear" ); // clears the console of all output
  1112. }
  1113.  
  1114.  
  1115.  
  1116. /* ++++++EXTRA FUNCTION FOR SEEING ALL RESERVATIONS AND BOOKED GUESTS++++++ */
  1117. void all_guests_report()
  1118. {
  1119. FILE *reserver; // reservations.txt file pointer
  1120. FILE *roomPtr; // rooms.txt file pointer
  1121.  
  1122. // fopen opens the reservations.txt file, exits function if cannot be opened
  1123. if(( reserver = fopen( "reservations.txt", "rb")) == NULL)
  1124. {
  1125. textcolor(12); cprintf("\nERROR!! RESERVATION FILE COULD NOT BE OPENED!"); sleep(3);
  1126. }
  1127. else
  1128. { // fopen opens the rooms.txt file, exits function if cannot be opened
  1129. if (( roomPtr = fopen( "rooms.txt", "rb")) == NULL)
  1130. {
  1131. textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
  1132. }
  1133. else
  1134. {
  1135. printf( "+++++++++++++++++++CHECKED-IN GUEST DATA++++++++++++++++++\n\n\n" );
  1136.  
  1137. // reads all records in the file
  1138. while (!feof( reserver ) )
  1139. {
  1140. fread( &section, sizeof (ADMISSION_DATA), 1, reserver);
  1141.  
  1142. fseek( roomPtr, ( section.room_connec.room_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );
  1143.  
  1144. fread( &room, sizeof ( ROOM_DATA ), 1, roomPtr);
  1145.  
  1146. // only rooms whose data is set and checked-in
  1147. if( section.reservation_num != 0 && room.room_status == 12)
  1148. {
  1149. // formatted output for extra function
  1150. printf( "------------------------GUEST DATA------------------------\n" );
  1151. printf("\nReser. Num:\t%d\t\t", section.reservation_num);
  1152. printf("Credit Card\t%d\n", section.credit_card);
  1153. printf("Guest Num:\t%d\t\t", section.guest_num);
  1154. printf("Contact #:\t%d\n", section.telephone);
  1155. printf("First Name:\t%s\t\t", section.first_name);
  1156. printf("Charge:\t\t%.2f\n", section.charge);
  1157. printf("Middle I.:\t%s\t\t", section.MI);
  1158. printf("Duration:\t%d\n", section.length_stay);
  1159. printf("Last Name:\t%s\t\t", section.last_name);
  1160. printf("Cancel:\t\t%d\n\n", section.charge);
  1161. printf( "------------------------ROOM DATA--------------------------\n" );
  1162. printf("\nRoom Num:"); printf("\t%d\t\t", section.room_connec.room_num);
  1163. printf("Room Type:\t");
  1164. (section.room_connec.room_type == 1? printf("SMOKING\n\n\n"):printf("NON-SMOKING\n\n\n"));
  1165. }
  1166. }
  1167.  
  1168. rewind( reserver ); // sets file pointer to beginning of file
  1169.  
  1170. printf( "\n\n\n\n\n+++++++++++++++++++RESERVED GUEST DATA++++++++++++++++++++++\n\n\n" );
  1171.  
  1172. // only rooms whose data is set and reserved
  1173. while (!feof( reserver ) )
  1174. {
  1175. fread( &section, sizeof (ADMISSION_DATA), 1, reserver);
  1176.  
  1177. fseek( roomPtr, ( section.room_connec.room_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );
  1178.  
  1179. fread( &room, sizeof ( ROOM_DATA ), 1, roomPtr);
  1180.  
  1181. if( section.reservation_num != 0 && room.room_status == 9)
  1182. {
  1183. // formatted output for extra function
  1184. printf( "------------------------GUEST DATA--------------------------\n" );
  1185. printf("\nReser. Num:\t%d\t\t", section.reservation_num);
  1186. printf("Credit Card\t%d\n", section.credit_card);
  1187. printf("Guest Num:\t%d\t\t", section.guest_num);
  1188. printf("Contact #:\t%d\n", section.telephone);
  1189. printf("First Name:\t%s\t\t", section.first_name);
  1190. printf("Charge:\t\t%.2f\n", section.charge);
  1191. printf("Middle I.:\t%s\t\t", section.MI);
  1192. printf("Duration:\t%d\n", section.length_stay);
  1193. printf("Last Name:\t%s\t\t", section.last_name);
  1194. printf("Cancel:\t\t%d\n\n", section.charge);
  1195. printf( "------------------------ROOM DATA--------------------------\n" );
  1196. printf("\nRoom Num:"); printf("\t%d\t\t", section.room_connec.room_num);
  1197. printf("Room Type:\t");
  1198. (section.room_connec.room_type == 1? printf("SMOKING\n\n\n"):printf("NON-SMOKING\n\n\n"));
  1199. }
  1200. }
  1201. getchar();
  1202. }
  1203. fclose( roomPtr ); // fclose closes rooms.txt
  1204. }
  1205. fclose( reserver ); // fclose closes reservations.txt
  1206. }
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
knight fyre is offline Offline
88 posts
since Feb 2008
Apr 13th, 2008
0

Re: Evaluate my C Program

welp, i just tried to compile your C code, and got a flood of compiler errors.

god forbid anyone try and run your code on a non-Windows environment.

for this reason you should stay away from CONIO.H and DOS.H...

but i imagine your entire class uses nothing but windows, and your instructor doesn't care if he teaches you programming without regard to the ugly consequences of using Non-ANSI C

anyhow, im on my way upstairs now, so maybe I'll peek at it on my vista laptop.
Last edited by jephthah; Apr 13th, 2008 at 2:55 am.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Apr 13th, 2008
0

Re: Evaluate my C Program

okay, WTF is this?

fseek( logger, ( NULL ) * sizeof( ADMISSION_DATA ), SEEK_SET );

NULL * sizeof(something) ?? zero times anything is still zero. if you just want the beginning of the file, why are you using fseek?

but a larger issue: NULL is a pointer. not an int. you cant multitply a pointer and an int. at least not on most compilers. Borland maybe you can get away with it, but not GCC. and probably not MSVC either.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Apr 14th, 2008
0

Re: Evaluate my C Program

Im still getting a bazillion compiler warnings and errors when i try and compile it on MSVC.

i changed the #include <dos.h> to <windows.h>, and changed your sleep() calls to Sleep(). that got rid of some of them, but brought in new ones to replace it.

did this compile for you even, on Borland?

and whether it did or didn't, you should really think about getting rid of Borland compiler, in favor of GCC or MSVC. borland was in the trash bin 10 years ago.
Last edited by jephthah; Apr 14th, 2008 at 3:53 am.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: c+ Coin tossing program
Next Thread in C Forum Timeline: Fanciful errors :o





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC