Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help fixing my code with c program code. I get so many different errors with my line 237 cancelreservation. I tried to deifne

I need help fixing my code with c program code. I get so many different errors with my line 237 cancelreservation. I tried to deifne it and then had more errors. this code for a making reservations ata hotel. here is my code and my errors are attatched in pic:

#include

#include "stdafx.h"

#include //STRING LIBRARY

#include

//DECLARE USER-DEFINED FUNCTIONS

int isSomeRoomFree(int *rooms, int n);

int isResvIdPresent(int *rooms, int n, int resID);

void cancelReservation(int *rooms, char roomReserve, int *waiting, char waitingName, int noOfRooms, int *waitingCount, char *reservationName);

void removeWaiting(int *waiting, char waitingName[][15], int n, int indexToRemove);

void printInfo(int *rooms, char roomReserve[][15], int *waiting, char waitingName[][15], int noOfRooms, int waitingCount);

int isSomeRoomFree(int *rooms, int n);

void reserveRoomIfPossible(int *rooms, char roomReserve[][15], int *waiting, char waitingName[][15], int noOfRooms, int *reservationId, int *waitingCount, char* reservationName, int *waitingId);

//THESE VARIABLES CAN ONLY BE READ

#define MAXWAITING 3

#define NO_OF_ROOMS 3

#define maxName 15

// checks if some room is free

int isSomeRoomFree(int *rooms, int n) {

int i = 0;

for (; i

if (rooms[i] == -1) {

return i;

}

}

return -1;

}

// checks if some reservation Id is valid or not

int isResvIdPresent(int *rooms, int n, int resID) {

int i = 0;

for (; i

if (rooms[i] == resID) {

return i;

}

}

return -1;

}

// checks if someone is waiting for room

int isAnyoneWaiting(int *waiting, int n) {

int i = 0;

for (; i

if (waiting[i] != -1)

{

return i;

}

}

return -1;

}

// removes waiting list's indexToRemove and shuffles the array

void removeWaiting(int *waiting, char waitingName[][15], int n, int indexToRemove) {

int lastWaitingId = waiting[0];

char * s = waitingName[0];

int i = indexToRemove;

for (; i

waiting[i] = waiting[i + 1];

memset(&waitingName[i], 0, strlen(waitingName[i]));

strncpy_s(waitingName[i], waitingName[i+1], sizeof(waitingName)); //COPIES NAME OF PERSON 2ND IN LINE TO 1ST IN LINE

}

waiting[i] = -1;

}

// try to reserve a room if possible

void reserveRoomIfPossible(int *rooms, char roomReserve[][15], int *waiting, char waitingName[][15], int noOfRooms, int *reservationId, int *waitingCount, char* reservationName, int *waitingId) {

int roomNo = isSomeRoomFree(rooms, noOfRooms);

if (roomNo != -1) {

int nameLength = sizeof(reservationName);

rooms[roomNo] = *reservationId;

printf("Room is available. ");

printf("Enter your name for reservation: "); //NAME FOR RESERVATION

scanf_s("%s", reservationName, nameLength); //FOR SOME REASON, HAVE TO PRESS ENTER IN THE COMMAND WINDOW THEN ENTER NAME, THEN HIT ENTER

// empty the string first

memset(roomReserve[roomNo], 0, 15);

fgets(roomReserve[roomNo], 15, stdin);

//memset(reservationName[roomNo], 0, 15); //IS THIS NEEDED?

//fgets(reservationName[roomNo], 15, stdin);

// to remove new line character

printf("Room %d has been reserved for %s, Reservation Id: %d ", roomNo+1, reservationName, *reservationId);

// increment reservation Id

*reservationId+=1;

}

else {

char choice;

printf("There are no rooms available. Do you want to get registered in waiting list(y): ");

scanf_s(" %c", &choice,1);

// to consume extra new line

//getchar(); //USED SCAN INSTEAD

if (choice == 'Y' || choice == 'y')

{

//DISTINGUISHED BETWEEN RESERVATION ID AND WAITING ID

waiting[*waitingCount] = *waitingId;

printf("Enter your name for waiting list: ");

scanf_s(" %s", &waitingName[*waitingCount], 15);

// empty the string first

memset(waitingName[*waitingCount], 0, 15);

fgets(waitingName[*waitingCount], 15, stdin);

// to remove new line character

printf("You are successfully registered on waiting list with waitingId: %d name: %s ", waiting[*waitingCount], waitingName[*waitingCount]);

*waitingCount += 1;

*waitingId += 1;

}

else

printf("Select another option: ");

}

printf(" ");

}

// try to cancel a reservation if possible

void cancelReservation(int *rooms, char roomReserve[NO_OF_ROOMS][15], int *waiting, char waitingName[MAXWAITING][15], int noOfRooms, int *waitingCount, char *reservationName) {

printf(" Enter reservation Id to be cancelled: ");

int resId;

scanf_s("%d", &resId);

// to consume extra new line

//getchar(); // USED A SCANF INSTEAD

if (resId

printf("Reservation Id should be greater than 0");

return;

}

int roomToCancel = isResvIdPresent(rooms, noOfRooms, resId);

if (roomToCancel != -1)

{

// resv id is valid

printf(" ReservationId: %d has been cancelled successsfully.", resId);

rooms[resId] = rooms[roomToCancel];

int waitingIndex = isAnyoneWaiting(waiting, *waitingCount);

if (waitingIndex != -1)

{

//rooms[roomToCancel] = waiting[waitingIndex];

strcpy_s(roomReserve[roomToCancel], waitingName[*waitingCount]); //COPIES PERSON NEXT IN WAITLIST TO RECENTLY CANCELLED ROOM

printf(" Reservation Id: %d has been confirmed.", rooms[resId]);

removeWaiting(waiting, waitingName, *waitingCount, 0);

*waitingCount -= 1;

}

}

else {

printf(" Invalid reservation id to be cancelled");

}

printf(" ");

}

// try to cancel a waiting if possible

void cancelWaiting(int *waiting, char waitingName[MAXWAITING][15], int *waitingCount) {

printf(" Enter reservation Id to be cancelled in waiting list: ");

int resId;

scanf_s("%d", &resId);

// to consume extra new line

//getchar(); REPLACED WITH A SCAN

if (resId

printf("Reservation Id should be greater than 0");

return;

}

int resvIdTOCancel = isResvIdPresent(waiting, *waitingCount, resId);

if (resvIdTOCancel != -1) {

// if res id is valid

printf(" ReservationId: %d has been cancelled successsfully from waiting list. ", resId);

removeWaiting(waiting, waitingName, *waitingCount, resvIdTOCancel);

*waitingCount -= 1; //DECREMENTS PLACE IN LINE

}

else {

printf(" Invalid reservation id to be cancelled. Not on waiting list. ");

}

printf(" ");

}

// Print information related to waiting and reservation

void printInfo(int *rooms, char roomReserve[][15], int *waiting, char waitingName[][15], int noOfRooms, int waitingCount) {

int i = 0;

int noOfRoomReserved = 0;

for (; i

if (rooms[i] != -1) {

noOfRoomReserved++; //GOES THROUGH EACH ROOM

if (noOfRoomReserved == 1) {

printf(" Room Reservation List:");

}

printf(" RoomNo. %d, ReservationID: %d, Name: %s", i + 1, rooms[i], roomReserve[i]);

}

}

if (noOfRoomReserved

printf(" No room is reserved.");

}

if (waitingCount

printf(" No one is on waitlist.");

}

else {

printf(" Waiting List =>>>");

for (i = 0; i

if (waiting[i] != -1) {

printf(" ReservationID: %d, Name: %s", waiting[i], waitingName[i]);

}

}

}

printf(" ");

}

int main(int argc, char **argv)

{

char choice;

int rooms[NO_OF_ROOMS], waiting[MAXWAITING], noOfRooms;

char roomReserve[NO_OF_ROOMS][15], waitingName[MAXWAITING][15], reservationName[NO_OF_ROOMS][maxName]; //ADDED RESERVATION NAME

int reservationId = 1, i, waitingCount = 0, waitingId = 1; // DISTINGUISHED BETWEEN WAITING ID AND RESERVATION ID

for (i = 0; i

waiting[i] = -1;

}

for (i = 0; i

rooms[i] = -1;

}

while (1) {

int exit = 0;

printf("Enter choice: 1.Reserve(R or r) 2.Cancel(C or c) 3.Remove From Waiting(W or w) 4.List reservations(L or l):");

scanf_s("%c", &choice,1);

switch (choice)

{

case 'R':

case 'r':

reserveRoomIfPossible(rooms, roomReserve, waiting, waitingName, noOfRooms, &reservationId, &waitingCount, *reservationName, &waitingId); //ADDED RESERVATION NAME AND WAITING ID

break;

case 'C':

case 'c':

cancelReservation(&rooms, roomReserve[NO_OF_ROOMS][15], &waiting, waitingName[MAXWAITING][15], noOfRooms, &waitingCount, &reservationName[NO_OF_ROOMS][15]);

break;

case 'W':

case 'w':

cancelWaiting(waiting, waitingName, &waitingCount);

break;

case 'L':

case 'l':

printInfo(rooms, roomReserve, waiting, waitingName, NO_OF_ROOMS, waitingCount);

break;

case 'Q':

case 'q':

exit = 1;

break;

default:

printf("Wrong choice. Please try again. ");

}

if (exit) {

printf("Exiting now.");

break;

}

}

}

image text in transcribed

the lesson is suposse to be:

This program is about 1 night stay at Hotel.

-with 3 rooms numbered 1 to 3

-must infinite loop to read commands from the keyboard and quit the program (return) when a quit command is entered.

-use a switch statement to choose the code to execute for a valid command.

-valid commands are:R or r: reserve a roomC or c: cancel a reservationW or w: remove a request from the waiting listL or l: list the current reservations for the nightQ or q: quit the programAny other input: print an error message and prompt for another command

-please use one-dimensional array for a room a parallel one- dimensional array of character strings to reserve a room

-one-dimensional array to hold waiting list entries, and a parallel one-dimensional array to hold the name associated with the waiting list entry. Actions taken in response to a valid command (r, c, w, or l) must be implemented using programmer-defined functions, one per command. Any needed data must be passed to the functions, not declared globally. Implement reservation ids using a simple integer counter. Names will have fewer than 15 characters. Actions for each command are:

Reservation: If there is a free room, reserve a room by assigning the next reservation id to the array element representing that room, print the reservation id for the person at the keyboard, and prompt for and read the name associated with the reservation. If there are no rooms, print an appropriate message and ask if the person wants to be entered on the waiting list. If they do, place the reservation id in the waiting list array, print the reservation id for the person at the keyboard, and prompt for and read the name associated with the waiting list entry.

Cancellation: If there is a room reserved under that reservation id, cancel the reservation. Otherwise print a message that the id is not valid. If a room is cancelled and there are entries on the waiting list, remove the first entry on the waiting list (array element [0]) assign that reservation id and the associated waiting list name to the room, then print a message indicating that reservation id is now confirmed. Shuffle any other entries on the waiting list up one place.

Wait cancellation: If there is a waiting list entry with that reservation id, delete it and the associated name, and shuffle all waiting list entries below the one deleted up one place. Otherwise print a message indicating that id is not on the waiting list.

List reservations: Print the reservation ids and associated names of all rooms that are reserved, along with the room number that reservation occupies. Do not print anything for rooms that are vacant. If there are no rooms reserved, print a message indicating that. If there are any entries on the waiting list you should also print the reservation number and name of all elements on the waiting list.

Quit: end the program by returning from the main function.Any other command: print an error message and prompt for another command.

Your solution must use four arrays (two for the rooms and two for the waiting list). The waiting list should have as many entries as there are rooms. Use an integer counter for reservation ids that starts at 1. Reservation ids are not reused. Use another integer to keep track of the number of rooms reserved.

Your solution will be for a boutique hotel with only 10 (very expensive) rooms. But make liberal use of #define statements so it would be trivial to adapt your solution to a larger hotel.

Error List 4 Errors o warnings Messages xr Build IntelliSense Entire Solution Code Description PCH warning: cannot find a suitable header stop location. An IntelliSense PCH file was not generated. expected a no instance of overloaded function cancel Reservation" matches the argument list C2665 ation none of the 2 overloads could convert all the argument types Project Lab7c Lab7c Lab7c Lab7c Search Error List Lab7c.cpp Lab7c.cpp Lab7c.cpp lab7c CPP Line 239 239 Error List 4 Errors o warnings Messages xr Build IntelliSense Entire Solution Code Description PCH warning: cannot find a suitable header stop location. An IntelliSense PCH file was not generated. expected a no instance of overloaded function cancel Reservation" matches the argument list C2665 ation none of the 2 overloads could convert all the argument types Project Lab7c Lab7c Lab7c Lab7c Search Error List Lab7c.cpp Lab7c.cpp Lab7c.cpp lab7c CPP Line 239 239

<>

<>

<>

<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Identify four applications of HRM to healthcare organizations.

Answered: 1 week ago