Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream> //for creating text file
- using namespace std;
- class linklist{
- private:
- struct node{
- Reservation info;
- node *link;
- }*head;
- public:
- linklist(){
- head=NULL;
- }
- void InsNewNodeByBookNo(int bNo, string na, int phNo, int pxNo, int d, int mon, int y, int t, int da){
- node*newNode = new node;
- node*p,*q = head;
- newNode -> info.setBookingNo(bNo);
- newNode -> info.setName(na);
- newNode -> info.setPhoneNo(phNo);
- newNode -> info.setPaxNo(pxNo);
- newNode -> info.setDay(d);
- newNode -> info.setMonth(mon);
- newNode -> info.setYear(y);
- newNode -> info.setTime(t);
- newNode -> info.setDate(da);
- //If no records
- if (head == NULL){
- head = newNode;
- return;
- }
- //Insert at the start of list
- if (head -> info.getBookingNo() > newNode -> info.getBookingNo()){
- newNode -> link = head;
- head = newNode;
- return;
- }
- while(q->info.getBookingNo() < newNode -> info.getBookingNo() && q->link != NULL){
- p = q;
- q = q->link;
- }
- //Insert at the end of the list
- if(q == NULL){
- q = newNode;
- newNode-> link = NULL;
- return;
- //Insert in the middle of the list
- }else{
- p = q;
- q = q->link;
- p->link = newNode;
- newNode-> link = q;
- return;
- }
- }
- void deleteNode(int bNo){
- node *current;
- current = head;
- while (current != NULL){
- if(bNo == current->info.getBookingNo()){
- if(current == head){
- node*temp = head;
- head = head -> link;
- delete temp;
- }else if(current->link == NULL){
- node*p, *q = head;
- while(q -> link != NULL){
- p = q;
- q = q -> link;
- }
- p->link = NULL;
- delete q;
- }else{
- node*p, *q = head;
- while(q -> info.getBookingNo() != bNo){
- p = q;
- q = q -> link;
- }
- p -> link = q ->link;
- delete q;
- }
- }
- current = current->link;
- }
- total--;
- }
- void PrintList(){
- node *current;
- current = head;
- cout<<setfill(' ')<<setw(5)<<"| No. "
- <<left<<setw(30)<<"Name"
- <<setw(5)<<"Phone No."
- <<right<<setw(16)<<"Pax No."
- <<setw(10)<<"Date"
- <<setw(16)<<"Time |"<<endl
- <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
- while (current != NULL){
- cout<<"| "<<setfill(' ')<<current->info.getBookingNo()<<" "
- <<left<<setw(30)<< current->info.getName()
- <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
- <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
- <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
- <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
- current = current->link;
- }
- cout<<endl;
- }
- void PrintBookingNoRecords(int bNo){
- node *current;
- current = head;
- cout<<setfill(' ')<<setw(5)<<"| No. "
- <<left<<setw(30)<<"Name"
- <<setw(5)<<"Phone No."
- <<right<<setw(16)<<"Pax No."
- <<setw(10)<<"Date"
- <<setw(16)<<"Time |"<<endl
- <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
- while (current != NULL){
- //If there is any reservation with the same name
- if(bNo == current->info.getBookingNo()){
- cout<<"| "<<setfill(' ')<<current->info.getBookingNo()<<" "
- <<left<<setw(30)<< current->info.getName()
- <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
- <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
- <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
- <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
- }
- current = current->link;
- }
- cout<<endl;
- }
- void PrintNameRecords(string name){
- node *current;
- current = head;
- cout<<setfill(' ')<<setw(5)<<"| No. "
- <<left<<setw(30)<<"Name"
- <<setw(5)<<"Phone No."
- <<right<<setw(16)<<"Pax No."
- <<setw(10)<<"Date"
- <<setw(16)<<"Time |"<<endl
- <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
- while (current != NULL){
- //If there is any reservation with the same name
- if(name == current->info.getName()){
- cout<<"| "<<setfill(' ')<<current->info.getBookingNo()<<" "
- <<left<<setw(30)<< current->info.getName()
- <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
- <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
- <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
- <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
- }
- current = current->link;
- }
- cout<<endl;
- }
- void PrintDateRecords(int date){
- node *current;
- current = head;
- cout<<setfill(' ')<<setw(5)<<"| No. "
- <<left<<setw(30)<<"Name"
- <<setw(5)<<"Phone No."
- <<right<<setw(16)<<"Pax No."
- <<setw(10)<<"Date"
- <<setw(16)<<"Time |"<<endl
- <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
- while (current != NULL){
- //If there is any reservation with the same date
- if(date == current->info.getDate()){
- cout<<"| "<<setfill(' ')<<current->info.getBookingNo()<<" "
- <<left<<setw(30)<< current->info.getName()
- <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
- <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
- <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
- <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
- }
- current = current->link;
- }
- cout<<endl;
- }
- void PrintListTextFile(){
- string fileName;
- cout << "---------------=CREATE TEXT FILE=---------------" << endl;
- //Create file with the file name user entered
- cout << "Enter file name: ";
- cin >> fileName;
- cout << "Your .txt file can be found in the same folder where your .cpp file is saved." << endl;
- fileName = fileName + ".txt";
- //output to .txt file
- ofstream file(fileName.c_str());
- if (file.is_open()) {
- //output all the reservation records
- node *current;
- current = head;
- file<<setfill(' ')<<setw(5)<<"| No. "
- <<left<<setw(30)<<"Name"
- <<setw(5)<<"Phone No."
- <<right<<setw(16)<<"Pax No."
- <<setw(10)<<"Date"
- <<setw(16)<<"Time |"<<endl
- <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
- while (current != NULL){
- file<<"| "<<setfill(' ')<<current->info.getBookingNo()<<" "
- <<left<<setw(30)<< current->info.getName()
- <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
- <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
- <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
- <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
- current = current->link;
- }
- file.close(); //close file
- }
- }
- bool checker(int bNo){
- node *current;
- current = head;
- while(current != NULL){
- if(bNo == current->info.getBookingNo()){
- return true;
- }
- current = current->link;
- }
- return false;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement