Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please supply the proper \"C\" code for me to reference off of when writing my o

ID: 656148 • Letter: P

Question

Please supply the proper "C" code for me to reference off of when writing my own code. Thanks!

Create a hotel reservation program with the following parameters:

The hotel has 20, 30, 40, or 50 rooms.

For each room you have to store the following information:

Room number. (assigned by program)

Room rate. (entered by user)

Smoking or non-smoking. (entered by user, max 8 per hotel)

Customer Id (if room is reserved). (entered by user)

Number of days reserved. (entered by user)

Prompt the user to enter the number of rooms in the hotel and create a two dimensional array (of variables type double) that fits the exact number entered. If the user enters a number other than 20, 30, 40, or 50, display an invalid input message and re-prompt the user to enter the right number.

Populate the room numbers as follows: the first 10 rooms numbered from 101 to 110, the second ten rooms numbered 201 to 210, and so forth. Use a function, roomNum, to assign the room numbers using loops. Initialize all other array locations to zero.

Display a menu asking the user for the following options:

A to add reservation.

C to cancel reservation.

R to retrieve reservation.

T to display all reservations.

X to exit program.

Adding reservation should be done with a function named addReservation. The user is asked first whether this will be smoking or nonsmoking and the availability of room is determined before adding the room (there are eight smoking rooms in any hotel, they could be any rooms, but a total of eight). If the room is available (not reserved), then the user is prompted to enter the rest of the reservation info, otherwise, display a message saying all rooms are reserved.

Cancel reservation will ask for the customer Id and free the rooms reserved by the customer (hint, a customer could reserve more than one room). This option is performed by a function named cancelReservation.

Retrieve reservation will ask for a customer Id and retrieve all the information for the rooms reserved by the customer, including the total cost of the hotel stay for the specific customer (tax is 12%). This option is performed by a function named retrieveReservation.

Display all reservations will display the information for all reservations by room number, and the total amount charged for all reservations, tax included. This option is performed by a function named displayAll.

Since the reservations could be cancelled, it is assumed that the array will not be uniformlyfilled. The addReservation function should add new reservations in the first available room in the array, for which the customer id would be zero.

Cancelling a reservation is done by setting the room number to zero.

To indicate that a room is smoking, enter 1 for smoking, 0 for non-smoking.

Only function calls are allowed to execute menu options.

Array arguments passed to functions could be done with or without pointers, it is up to the programmer.

Explanation / Answer

Program code:

/* hotel reservation program */

#include < stdio.h >

int custid;

int numb_rooms;

void roomNum(double rooms[][6], int numb_rooms)

{

    int j = 0, i, l = 0;

    int k;

    int size = numb_rooms / 10;

    while (l < numb_rooms)

    {

         for (i = 1; i <= size; i++)

         {

             j = 100 * i;

             for (k = 1; k <= 10; k++)

             {

                 rooms[l][0] = j + k;

                 l++;

             }

         }

    }

    for (i = 0; i < numb_rooms; i++)

    {

         if (i >= numb_rooms - 8)

         {

             rooms[i][2] = 1;

         }

         else

         {

             rooms[i][2] = 0;

         }

    }

    for (i = 0; i < numb_rooms; i++)

    {

         rooms[i][5] = 0;

    }

}

void addreservation(double rooms_array[][6], int numb_rooms)

{

    int ch, i;

    printf("Smoking/ non smoking 1/0");

    scanf("%d", &ch);

    for (i = 0; i < numb_rooms; i++)

    {

         if (rooms_array[i][2] == ch)

             if (rooms_array[i][5] == 0)

             {

                 // the room is not allocated

                 printf("Enter cust id");

                 scanf("%lf", &rooms_array[i][1]);

                 printf("Enter room rate per day: ");

                 scanf("%lf", &rooms_array[i][3]);

                 printf("Enter numb of days");

                 scanf("%lf", &rooms_array[i][4]);

                 rooms_array[i][5] = 1;

             }

    }

}

void cancelreservation(double rooms_array[][6], int numb_rooms)

{

    double custid;

    printf("Enter the custid");

    scanf("%lf", &custid);

    int i = 0, j;

    while (rooms_array[i][1] != custid)

    {

         i++;

         for (j = 1; j < 6; j++)

         {

             rooms_array[i][j] = 0;            

         }

         if (i < numb_rooms)

         {

             i++;

         }

    }

}

void retieveReservation(double rooms_array[][6], int numb_rooms)

{

    double custid;

    printf("Enter cust id");

    scanf("%lf", &custid);

    int i = 0;

    while (rooms_array[i][1] != custid)

    {

         i++;

    }

    printf(" The details are : %0.0lf %0.0lf %0.0lf %0.2lf %0.0lf ", rooms_array[i][0], rooms_array[i][1], rooms_array[i][2], rooms_array[i][3], rooms_array[i][4], rooms_array[i][1] * rooms_array[i][4]);

}

void displayall(double rooms_array[][6], int numb_rooms)

{

    int i;

    for (i = 0; i < numb_rooms; i++)

    {

         printf("%0.0lf %0.0lf %0.0lf %0.2lf %0.0lf ", rooms_array[i][0], rooms_array[i][1], rooms_array[i][2], rooms_array[i][3], rooms_array[i][4]);

    }

}

int main()

{

    char choice;

    printf("How many rooms are there in the hotel ? (enter 20,30,40 or 50): ");

    scanf("%d", &numb_rooms);

    while (numb_rooms != 20 && numb_rooms != 30 && numb_rooms != 40 && numb_rooms != 50)

    {

         printf("invalid number of rooms entered");

         scanf("%d", &numb_rooms);

    }

    double rooms_array[numb_rooms][6];

    roomNum(rooms_array, numb_rooms);

    printf(" Menu: A to add C to cancel R to retrieve T to display reservations X to exit ");

    printf(" Enter choice: ");

    scanf("%c", &choice);

    switch (choice)

    {

         case 'A':

             addreservation(rooms_array, numb_rooms);

             break;

         case 'C':

             cancelreservation(rooms_array, numb_rooms);

             break;

         case 'R':

             retieveReservation(rooms_array, numb_rooms);

             break;

         case 'T':

             displayall(rooms_array, numb_rooms);

             break;

         case 'X':

             return 0;

             break;

         default:

             printf(" Please enter correct option. ");

    }

    return 0;

}