Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.7 kB
6
Indexable
Never
	/*edit*/

/*custom header*/

	/*end_edit*/
	/*edit*/
/* Write your code here */
#include <stdio.h>
#include <string.h>
#define MAX 100
typedef struct {
    int roomID;
    int status;
    char name[20];
}  Room;
void listOccupiedRooms(Room *rm, int size);
int assignRoom(Room *rm);  
int main()
{
    Room s[MAX];
    char t[20], *p;
    int size=0, choice;
    char dummychar;
    
    printf("NTU HOTEL ROOM RESERVATION PROGRAM: \n");
    printf("1: listOccupiedRooms()\n");
    printf("2: assignRoom()\n");
    printf("3: removeRoom()\n");
    printf("4: findCustomer()\n");
    printf("5: quit\n");
    do {
        printf("Enter your choice: \n");
        scanf("%d", &choice);
        switch (choice) {
            case 1:
               listOccupiedRooms(s, size);
               break;
        case 2:
            scanf("%c", &dummychar);
            size = assignRoom(s);
            break;
        }
    } while (choice <6);
    return 0;
}
void listOccupiedRooms(Room *rm, int size)
{
    int i;
    
    printf("listOccupiedRooms():\n");
    if(size==0)
      printf("The hotel is empty\n");
    else{
         for(i=0;i<size;i++){
             printf("customer name: %s\n",(rm+i)->name);
         }
    }
}
int assignRoom(Room *rm)
{
    int size = 0;
    char *p,dummy[80];
    printf("assignRoom():\n");
    
    while(1){
        printf("Enter a roomID between 1 and 5:\n");
        scanf("%d",&(rm->roomID));
        printf("Enter customer name: \n");
        fgets(rm->name,80,stdin);
        if(p=strchr(rm->name,'\n'))*p='\0';
        printf("The room has been assigned successfully \n");
        rm++;
        size++;
        break;
    }
    return size;
}
	/*end_edit*/