Question

In: Computer Science

I know how to do this with arrays, but I have trouble moving my code to...

I know how to do this with arrays, but I have trouble moving my code to use with linked lists

Write a C program that will deal with reservations for a single night in a hotel with 3 rooms, numbered 1 to 3. It must use an 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. The valid commands are: R or r: reserve a room C or c: cancel a reservation W or w: remove a request from the waiting list L or l: list the current reservations for the night Q or q: quit the program Any other input: print an error message and prompt for another command.

You must use a linked list to represent the reservation list, and another linked list to represent the waiting list. You can determine whether each list will be singly- or doubly linked, and whether each list has just a front pointer, or a front and rear pointer. The two lists do not need to have the same design (that is one could be singly-linked with a front pointer, and the other doubly-linked with front and rear pointers. The reservation list can have at most as many nodes as there are rooms in the hotel 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 inserting a node on the reservation list containing the next reservation id and the name associated with the reservation. When there is space available, 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, add a node to 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. The waiting list must be implemented as a queue (insert nodes at the back of the list and remove nodes from the front of the list when a room becomes available)

Cancellation: If there is a room reserved under that reservation id, cancel the reservation by removing the node associated with 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 and insert the data in the reservation list, then print a message indicating that reservation id is now confirmed. Note that, if the nodes on both lists are the same type, you can simply insert the node you removed from the waiting list into the reservation list.

Wait cancellation: If there is a waiting list entry with that reservation id, the node containing that reservation id should be removed from the waiting list. 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. 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.

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 3 (very expensive) rooms. But make liberal use of #define statements so it would be trivial to adapt your solution to a larger hotel.

Solutions

Expert Solution

    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++)
        System.out.print(i * j % 10);
      System.out.println();
    }
CODE PRINTS THIS VALUES:
    0000000000
    0123456789
    0246802468
    0369258147
    0482604826
    0505050505
    0628406284
    0741852963
    0864208642
    0987654321

2)int s = 0;
for (int i = 1; i <= 10; i++) s = s + 1;
REWRITE INTO WHILE LOOP:
int s = 0;
int i = 1;
while (i <= 10) {
s = s + 1;
i++;
}


3)int n = 1;
double x = 0;
double s;
do {
s = 1.0 / (n * n);
x = x + s;
n++;
} while (s > 0.01);


REWRITE INTO WHILE LOOP:
int n = 1;
double x = 0;
double s;
s = 1.0 / (n * n);
x = x + s;
n++;
while (s > 0.01) {
s = 1.0 / (n * n);
x = x + s;
n++;

4)A loop that runs forever and can be stopped only by killing the program or restarting the computer. Some infinite loops are useful though: as long as we are sure we can end them when we want them. An example is:

    while (true) {
      String input = console.readLine();
      if (inputLine == null) break;
      double x = Double.parseDouble(input);
      sum += x;
      count += 1;
    }

This loop is also infinite, because at least in principle it can last forever. But it's a controlled infinite loop, which can be ended in a disciplined way.

5)Java Loops
& Methods
The
while
loop
Syntax:
while (
condition is true
) {
do these statements
}
Just as it says, the statements execute while the condition is true. Once the condition becomes
false, execution continues with the statements that appear after the loop.
Example
:
count = 1;
while (count <= 10) {
out.
println(count);
count = coun
t + 1;
}
This loop prints out the numbers from 1 through 10 on separate lines. How does it work?
Output:
1
2
3
4
5
6
7
8
9
10


Related Solutions

Hello I have this error in the code, I do not know how to fix it....
Hello I have this error in the code, I do not know how to fix it. It is written in C++ using a Eclipse IDE Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string bus.h =========== #pragma once #include using namespace std; class Bus { private:    string BusId; // bus ID    string Manufacturer; // manufacturer of the bus    int BusCapacity; // bus capacity    int Mileage; // mileage of bus    char Status; // current status...
PHP Language I have XAMPP and I don't know how to display my PHP code. For...
PHP Language I have XAMPP and I don't know how to display my PHP code. For instance, when I create a basic HTML webpage I just open the code into a web browser and it shows me a basic web page. When I try to show a PHP calculation it doesn't show. What are the steps in displaying my PHP doc?
hi i do not know what is wrong with my python code. this is the class:...
hi i do not know what is wrong with my python code. this is the class: class Cuboid: def __init__(self, width, length, height, colour): self.__width = width self.__length = length self.__height = height self.__colour = colour self.surface_area = (2 * (width * length) + 2 * (width * height) + 2 * (length * height)) self.volume = height * length * width def get_width(self): return self.__width def get_length(self): return self.__length def get_height(self): return self.__height def get_colour(self): return self.__colour def set_width(self,...
Python I want to name my hero and my alien in my code how do I...
Python I want to name my hero and my alien in my code how do I do that: Keep in mind I don't want to change my code except to give the hero and alien a name import random class Hero:     def __init__(self,ammo,health):         self.ammo=ammo         self.health=health     def blast(self):         print("The Hero blasts an Alien!")         if self.ammo>0:             self.ammo-=1             return True         else:             print("Oh no! Hero is out of ammo.")             return False     def...
I'm having trouble with my ZeroDenominatorException. How do I implement it to where if the denominator...
I'm having trouble with my ZeroDenominatorException. How do I implement it to where if the denominator is 0 it throws the ZeroDenominatorException and the catch catches to guarantee that the denominator is never 0. /** * The main class is the driver for my Rational project. */ public class Main { /** * Main method is the entry point to my code. * @param args The command line arguments. */ public static void main(String[] args) { int numerator, denominator =...
How do I add the information below to my current code that I have also posted...
How do I add the information below to my current code that I have also posted below. <!DOCTYPE html> <html> <!-- The author of this code is: Ikeem Mays --> <body> <header> <h1> My Grocery Site </h1> </header> <article> This is web content about a grocery store that might be in any town. The store stocks fresh produce, as well as essential grocery items. Below are category lists of products you can find in the grocery store. </article> <div class...
I am having trouble with my assignment and getting compile errors on the following code. The...
I am having trouble with my assignment and getting compile errors on the following code. The instructions are in the initial comments. /* Chapter 5, Exercise 2 -Write a class "Plumbers" that handles emergency plumbing calls. -The company handles natural floods and burst pipes. -If the customer selects a flood, the program must prompt the user to determine the amount of damage for pricing. -Flood charging is based on the numbers of damaged rooms. 1 room costs $300.00, 2 rooms...
I'm having trouble with validating this html code. Whenever I used my validator, it says I...
I'm having trouble with validating this html code. Whenever I used my validator, it says I have a stray end tag: (tbody) from line 122 to 123. It's the last few lines. Thanks and Ill thumbs up whoever can help solve my problem. Here's my code: <!DOCTYPE html> <html lang="en"> <head> <title>L7 Temperatures Fields</title> <!--    Name:    BlackBoard Username:    Filename: (items left blank for bb reasons    Class Section: (blank)    Purpose: Making a table to demonstrate my...
Hello, I am having trouble getting started on my project and building these functions. How do...
Hello, I am having trouble getting started on my project and building these functions. How do I build a function that continuously adds new "slices" to the list if they are below/above the size limit? I didn't copy the entire problem, but just for reference, when the code is run it will take user input for size limit (L), time cost for a random slice(R), and time cost for an accurate slice(A). Question: In real life, a steak is a...
I don't know how to build my last code for TestPairOfDice...below the question is in bold....
I don't know how to build my last code for TestPairOfDice...below the question is in bold. I'm including my code for the previous problems which are all needed for number 6 1. Implement a method named surface that accepts 3 integer parameters named width, length, and height as user input. It will return the total surface area (6 sides) of the rectangular box it represents. The formula for Surface Area is 2(length * width) + 2(length * height) + 2(height...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT