Lab_Evaluation-1_Hotel_Management
kaziamir
c_cpp
2 years ago
2.3 kB
9
Indexable
#include<bits/stdc++.h>
#include<windows.h>
#include<unistd.h>
using namespace std;
typedef struct guests{
int id, room;
string name;
struct guests *next;
}guests;
guests *start = NULL;
#define int long long
void landing();
void addGuest();
void removeGuest();
void Display();
signed main(){
bool stop = false;
while(!stop){
landing();
int op;
cin>>op;
switch(op){
case 1:
addGuest();
break;
case 2:
removeGuest();
break;
case 3:
Display();
break;
case 4:
stop = true;
break;
}
}
}
void landing(){
cout<<endl<<"Hotel Reservation System: "<<endl;
cout<<"\t1. Add a guest"<<endl;
cout<<"\t2. Remove a guest"<<endl;
cout<<"\t3. Display guests"<<endl;
cout<<"\t4. Exit"<<endl<<endl;
cout<<"Enter your choice: ";
}
void addGuest(){
int id, room;
string name;
cout<<"Enter Guest ID: ";
cin>>id;
cout<<"Enter Guests Name: ";
cin.ignore();
getline(cin,name);
//cin>>name;
cout<<"Enter Reserved Room No: ";
cin>>room;
guests *newGuest = new guests();
newGuest->id = id;
newGuest->room = room;
newGuest->name = name;
newGuest->next = NULL;
if(start==NULL){
start = newGuest;
}
else{
guests *p = start;
while(p->next!=NULL){
p = p->next;
}
p->next = newGuest;
}
cout<<endl<<newGuest->name<<" is checked in."<<endl;
Sleep(1000);
}
void removeGuest(){
int id;
cout<<"Guest ID: ";
cin>>id;
guests *p = start, *prev = NULL;
while(p!=NULL){
if(p->id == id){
break;
}
prev = p;
p = p->next;
}
if(prev==NULL){
start = start->next;
}
else{
prev->next = p->next;
}
cout<<endl<<p->name<<" is checked out"<<endl;
delete p;
Sleep(1000);
}
void Display(){
guests *p = start;
int ct = 0;
cout<<"All guests: "<<endl;
while(p!=NULL){
cout<<p->id<<" "<<p->name<<" "<<p->room<<endl;
ct++;
p = p->next;
}
cout<<"Total guests: "<<ct<<endl;
}Editor is loading...