Question

I need to complete the C++ program for hotel reservation. In the main cpp you have...

I need to complete the C++ program for hotel reservation.

In the main cpp you have to display the hotel information from the hotel.txt based on customer preferences(which can be taken from the User.txt) For example, if the customer's budget is 200$, then only the hotels with prices below that amount should be displayed.

Then the user has an option to choose which one to reserve for the particular time(which also can be found in the user.txt)

The last two numbers are the arrival date and the check out date. We did not consider the month yet. We assumed to allow booking only for the one month.

Also, you MUST either one of the header files provided.

Thanks! I understand, that here is a lot of work, therefore I want to post this question several times, so you will have a chance to respond to it couple times.

There are couple header files and a cpp file that I will include in this order:

1)main.cpp(needs modification)

2)DynamicArray.h (no change)

3)Queue.h(no change)

4) Hotel.txt

5) User.txt

-----------------------------------------------------------------

1) main.cpp

#include
#include
#include
#include
#include
#include "DynamicArray.h"
#include "Queue.h"
using namespace std;


struct Customer
{
char Id;
string City;
string Star;
int Budget;
int ArrivalTime;
int endTime;
};


char getLetter(char &letter)
{
letter++;
if(letter > 'Z')
letter = 'A';
return letter;
}

bool check_prefernces(const string city, const int xbudget, const DynamicArray& searching, int classIndex)
{
for(int i = 0; i < classIndex; i++)
{
if(city == searching[i].City)
{
if(xbudget >= searching[i].Budget)
{
return true;
}
}
}
return false;
}

int main()
{

srand(time(0));
rand();
  
Queue waitLine;
DynamicArray searching;
DynamicArray serverStatus;
Customer client;

fstream file;
fstream user;
int cust_num = 0;
  

string fname, fstar, flocation, fprice, frate;

int xbudget, xstay, xarrival;
  
char *token;
char buf[1000];
const char* const tab = "\t";
  
char letter = 'Z';
int classIndex = 0;
  
user.open("User.txt");
if(!user.good())
cout<<"I/O error \n";
while(user.good())
{
string line;
getline(user, line);
strcpy(buf, line.c_str());
  
if(buf[0] == 0)//empty string
continue;
  
const string location (token = strtok(buf, tab));
const string star((token = strtok(0, tab)) ? token : "");
const string budget((token = strtok(0, tab)) ? token : "");
const string rate((token = strtok(0, tab)) ? token : "");
const string arrival((token = strtok(0, tab)) ? token : "");
const string stayLength((token = strtok(0, tab)) ? token : "");
cust_num++;

client.Id = getLetter(letter);
cout<<"Customer: "< cout<<"Enter the city: \n";
cout< client.City = location;
cout<<"How many stars: \n";
cout< client.Star = star;
cout<<"Enter the budget: \n";
cout< xbudget = stoi(budget);
client.Budget = xbudget;
// cout<<"The rate should be above: \n";
// cout< cout<<"What is the arrival time: \n";
cout<   
xarrival = stoi(arrival);
client.ArrivalTime = xarrival;
  
cout<<"Check out date? \n";
cout<   
xstay = stoi(stayLength);
client.endTime = xstay;
waitLine.push(client);
cout< }
  
file.open("simulation.txt");
if(!file.good())
cout<<"I/O error \n";
while(file.good())
{
getline(file,fname, '\n');
getline(file,fstar, '\n');
getline(file,flocation, '\n');
getline(file,fprice, '\n');
getline(file,frate, '\n');
}

// if(check_prefernces())
// for(int i = 0; i < cust_num; i++)
// {
// for(int day = 1; day <= 14; day++)
// if(!serverStatus[i]) //esli hotel zanyat (true)//eti nested loops nujny dlya proverki statusa hotelya
// {
// if(searching[i].endTime == day)
// serverStatus[i] = true;
// searching[i].Id = ' ';
// }
// }

return 0;
}

//This part just displays readings from the file

//NO CHANGE IN HEADER FILES

--------------------------

2) DynamicArray.h

#ifndef DynamicArray_h
#define DynamicArray_h

template
class DynamicArray
{
T* value;
int cap;
T dummy = T();
public:
DynamicArray(int = 2);
DynamicArray(const DynamicArray&);
~DynamicArray(){delete [ ] value;}
DynamicArray& operator = (const DynamicArray&);
int capacity() const;
void capacity(int);
const T&operator[ ] (int) const;
T& operator[ ] (int);
};

template
DynamicArray::DynamicArray(int cap)
{
this->cap = cap;
value = new T[cap];
  
for(int i = 0; i < cap; i++)
value[i] = T();
}

template
DynamicArray::DynamicArray(const DynamicArray& original)
{
cap = original.cap;
value = new T[cap];
  
for(int i = 0; i < cap; i++)
value[i] = original.value[i];
dummy = original.dummy;
}

template
DynamicArray& DynamicArray::operator=(const DynamicArray& original)
{
if(this != &original)
{
delete [ ] value;
  
cap = original.cap;
value = new T[cap];
for(int i = 0; i < cap; i++)
value[i] = original.value[i];
dummy = original.dummy;
}
return *this; //to match the data type
}

template
int DynamicArray:: capacity() const
{
return cap;
}

template
void DynamicArray:: capacity(int cap)
{
T* temp = new T[cap];
for(int i = 0; i < this->cap; i++)
temp[i] = value[i];
  
for(int i = this->cap; i < cap; i++)
temp[i] = T();
delete [ ] value;
value = temp;
this->cap = cap; //reassign our capacity to the newly created one.
}

template
const T& DynamicArray::operator[](int index) const
{
if(index < 0)
return dummy;
if(index >= cap)
return dummy;
else
return value[index];
}

template
T& DynamicArray:: operator[ ] (int index)
{
if(index < 0)
return dummy;
if(index >= cap)
capacity(index*2);
return value[index];
}

#endif /* DynamicArray_h */
---------------------------------------------------------
3)QUEUE.H

#ifndef Queue_h
#define Queue_h

template
class Queue
{
struct Node
{
V value;
Node* next;
};
  
Node* firstNode;
Node* lastNode;
int siz;
V dummy = V();
  
public:
Queue();
Queue(const Queue&); //copy constructor
Queue& operator = (const Queue&);
~Queue();
void push(const V&);
const V& front() const;
const V& back() const;
  
void pop();
void clear();
int size() const;
bool empty() const;
};

template
Queue::Queue()
{
firstNode = 0;
lastNode = 0;
siz = 0;
};

template
Queue::Queue(const Queue& original)//copy
{
this->firstNode = 0;
this->lastNode = 0;
siz = original.siz;
for(Node* p = original.firstNode; p; p = p->next)
{
Node* temp = new Node{p->value,0};
// temp->value = p->value;
// temp->next = 0;
if(lastNode)
lastNode->next = temp;
else
firstNode = temp;
lastNode = temp;
}
}

template
Queue::~Queue()
{
while(firstNode)
{
Node* p = firstNode;
firstNode = firstNode->next;
delete p;
siz--;
}
}

template
Queue& Queue::operator=(const Queue& original)//assign
{
if(this != &original)
{
while(firstNode)
{
Node *p = firstNode;
firstNode = firstNode->next;
delete p;
}
  
this->lastNode = 0;
for(Node* p = original.firstNode; p; p = p->next)
{
Node* temp = new Node{p->value,0};
// temp->value = p->value;
// temp->next = 0;
if(lastNode)
lastNode->next = temp;
else
firstNode = temp;
lastNode = temp;
}
siz = original.siz;
}
return *this; //to match the data type
}

template
void Queue::push(const V& value)
{
Node* temp = new Node{value,0};
if(lastNode)//whenever my lastNode points to somehwere
lastNode->next = temp;
else
firstNode = temp;
lastNode = temp;
++siz;
}

template
const V& Queue::front() const
{
if(firstNode)
return firstNode->value;
else
return dummy;
}

template
const V& Queue::back() const
{
if(lastNode)
return lastNode->value;
return dummy;
}

template
void Queue::pop()
{
if(firstNode)
{
Node* p = firstNode;
firstNode = firstNode->next;
delete p;
siz--;
}
if (siz == 0) lastNode = 0;
}

template
void Queue::clear()
{
while(firstNode)
{
Node* p = firstNode;
firstNode = firstNode->next; //or firstNode = p->next
delete p;
--siz;
}
  
if(siz == 0)
lastNode = 0;
}

template
int Queue:: size() const
{
return siz;
}

template
bool Queue:: empty() const
{
if(siz == 0)
return true;
else
return false;
}

#endif /* Queue_h */
---------------------------------

4)HOTEL.TXT

Name               Star       Location        Price(from)   Rate

Hilton Union Square       4       San Francisco       135$       4.2
Hilton Financial District   4       San Francisco        95$       4.3
Marriott Marquis        4       San Francisco       169$       4.4
Intercontinental       4       San Francisco       144$       4.4
Hyatt Regency           5       San Francisco       179$       4.5
The Lexington Hotel       4       New York       200$       4.1
The Plaza           5       New York       830$       4.5
Four Seasons           4       New York       1495$       4.6
The Ritz-Carlton       5       New York       835$       4.6

-----------------------

5) USER.TXT

San Francisco   4   100   4   1   3
San Francisco   4   200   4   1   2
Abu Dhabi   5   500   4   1   5
New York   5   1000   4   7   11
Amsterdam   2   50   4   5   6
London       4   100   4   1   2
London       4   2000   4   6   10
New York   5   500   4   1   4
London       2   300   4   7   10

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer is :A

Because of main.cpp file is consist all information about hotel.txt and also user.txt. In the main .cpp is all wants some modification and another working is done by the question.

In main.cpp file hold all knowledge of the budget to check also arrival time and checkout time .so,main.cpp is right with some modification to get desired result.

Add a comment
Know the answer?
Add Answer to:
I need to complete the C++ program for hotel reservation. In the main cpp you have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi I need a fix in my program. The program needs to finish after serving the...

    Hi I need a fix in my program. The program needs to finish after serving the customers from the queue list. Requeriments: Headers: DynamicArray.h #ifndef DynamicArray_h #define DynamicArray_h #include using namespace std; template class DynamicArray { V* values; int cap; V dummy; public: DynamicArray(int = 2); DynamicArray(const DynamicArray&); ~DynamicArray() { delete[] values; } int capacity() const { return cap; } void capacity(int); V operator[](int) const; V& operator[](int); DynamicArray& operator=(const DynamicArray&); }; template DynamicArray::DynamicArray(int cap) { this->cap = cap; values =...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • A library maintains a collection of books. Books can be added to and deleted from and...

    A library maintains a collection of books. Books can be added to and deleted from and checked out and checked in to this collection. Title and author name identify a book. Each book object maintains a count of the number of copies available and the number of copies checked out. The number of copies must always be greater than or equal to zero. If the number of copies for a book goes to zero, it must be deleted from the...

  • C++ assignment help! The instructions are below, i included the main driver, i just need help...

    C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...

  • I need help with understanding dummy nodes in doubly-linked lists. Here is the code that I...

    I need help with understanding dummy nodes in doubly-linked lists. Here is the code that I have right now. ************city.h**************** #ifndef city_h #define city_h #include <string> using namespace std; class City{ public: City () { name = "N/A"; population = 0; } City (string nm, unsigned int pop){ name = nm; population = pop; } void setName (string name) { this -> name = name; } void setPopulation (unsigned int population){ this -> population = population; } string getName() const...

  • Requirements: Finish all the functions which have been declared inside the hpp file. Details: st...

    Requirements: Finish all the functions which have been declared inside the hpp file. Details: string toString(void) const Return a visible list using '->' to show the linked relation which is a string like: 1->2->3->4->5->NULL void insert(int position, const int& data) Add an element at the given position: example0: 1->3->4->5->NULL instert(1, 2); 1->2->3->4->5->NULL example1: NULL insert(0, 1) 1->NULL void list::erase(int position) Erase the element at the given position 1->2->3->4->5->NULL erase(0) 2->3->4->5->NULL //main.cpp #include <iostream> #include <string> #include "SimpleList.hpp" using std::cin; using...

  • in C++ creat a DynamicQueue class, add a new data member called count to trace the...

    in C++ creat a DynamicQueue class, add a new data member called count to trace the total number of node you have in current queue (you need to modify some member functions for adding count). Add a member function called displayQueue() to display values stored in each node in the current queue, also the total number of nodes in the queue. You also need to have a driver program (refer to Tester) to test your modified new class and new...

  • // thanks for helping // C++ homework // The homework is to complete below in the...

    // thanks for helping // C++ homework // The homework is to complete below in the stack.h : // 1. the copy constructor // 2. the assignment operator // 3. the destructor // 4. Write a test program (mytest.cpp) to test copy and assignment // 5. Verify destructor by running the test program in Valgrind // This is the main.cpp #include <iostream> #include "stack.h" using namespace std; int main() { Stack<int> intStack; cout << "\nPush integers on stack and dump...

  • Introduction In this lab, you are supposed to implement a graph class with the data structure...

    Introduction In this lab, you are supposed to implement a graph class with the data structure implemented before like linked list and queue. graph The class graph contains three member variables: linkedList *adjacentVertices; //an array of linked list. For a vertice i, adjacentVertices[i] stores the linked list that contains all other vertices connected to vertice i. int numVertices; //The number of vertices in the graph. int maxNumVertices; //The maximum number of vertices the graph can hold. Following public methods are...

  • Hi, I hope I can get some help with the following exercise in C++( CPP): 1.Write...

    Hi, I hope I can get some help with the following exercise in C++( CPP): 1.Write an additional method called push_back(int) that will add an integer to the end of the list. You can modify the provided code. 2.Modify the Node class and LinkedList class so that you can access your parent node (double linked-list). #include #include using namespace std; typedef int Type; enum Boolean { False = 0, True }; class Item { friend class SLList; public: Type getVal()...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT