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

Please program this using only basic pointers, multi-arrays, and functions. Crea

ID: 648570 • Letter: P

Question

Please program this using only basic pointers, multi-arrays, and functions.

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 uniformly filled. 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 customer ID 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

/* hotel reservation program */

include <stdio.h>

function roomNum(double rooms)

{    int j=0;

      

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

       {j = j+100;

    

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

                j++;

                  rooms_array[i,1] = j; }   }

            for (l=2;l<6,l++){

              roomsarray[i,l] = 0 }

      }

function filldetails(roomsarray)

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

     { printf ( "Enter details for room %d ( room rate, smoking y/n, cust id, nod", roomsarray[i]);

       scanf( roomsarray[i][1], roomsarray[i][2], roomsarray[i][3], roomsarray[i][4]);

    }

int addreservation()

{   char ch;

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

   ch = getch();

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

     {   if roomsarray[i][2] = ch

            if roomsarray[i][3] = 0   /*   the room is not allocated */

              printf("Enter cust id");

              scanf("%d", roomsarray[i][3]);

              printf("Enter numb of days");

              scanf("%d", roomsarray[i][4]);

         exit

        }

function cancelreservation()

{ double custid;

printf("Enter the custid");

scanf("%d",custid);

int i = 0;

lab1: while(roomsarray[i][0] <> cust id) i++;

   for (j=1,j<5; j++)

     roomsarray[i][j] = 0;

    if (i < numb_rooms)

       { i++; goto lab1;}

}   

function retieveReservation()

{ int custid;

printf("Enter cust id");

scanf("%d", custid);

int i=0;

while(roomsarray[i][1] <> custid) i++;

    printf( " the details are %d %d %d %d %d), roomsarray[i][0], roomsarray[i][1], roomsarray[i][2], roomsarray[i][3], roomsarray[i][4], roomsarray[i][1] * roomsarray[i][4]);

}

function displayall()

{

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

{ if custid<>0

     printf("%d,%d,%d,%d,%d", roomsarray[i][0], roomsarray[i][1], roomsarray[i][2], roomsarray[i][3], roomsarray[i][4]);

}

int numb_rooms;

char corr = 'y', choice;

main()

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

    while(corr){

   scanf ("%d", &numb_rooms);

    if( numb_rooms not in (20, 30,40,50) )

      { printf("invalid number of rooms entered");

   else

     corr = 'n';

}

double   roomsarray[numb_rooms][5];    

   roomNum(double roomsarray);

printf("Enter choice A to add, C to cancel, R to retrieve, T to display reservations, X to exit");

choice = getch();

switch choice{

case ( 'A') : addreservation();

   case ('C') : cancelreservation();

   case('R') : Retres();

   case('T') : disp();

    case('X') : return

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote