Question

C++ Programming Program Design Including Data Structures 17-2 You will design a program to keep track of a restaurants waitli

below i added the code, but while running it, makefile.win error showing. how i fix this?

1.)waitlist.h

#include<iostream>
using namespace std;
class guest{
   public:
   string name;
   guest*next;
   guest*prev;
   guest(string);
  
};
class waitList{
   int numberOfGuests;
   guest* first;
   guest* last;
   public:
       waitList();
       void addPerson(string);
       void deletePerson(string);
       guest* getFirst();
       guest* getLast();
  
};

2.)waitlist.cpp

#include<iostream>
#include"waitlist.h"
using namespace std;
guest::guest(string name){
   this->name = name;
   this->next = NULL;
}
waitList::waitList(){
   this->numberOfGuests = 0;
   this->first = this->last = NULL;
}
void waitList::addPerson(string Name){
   guest* newGuest = new guest(Name);
   if(this->first==NULL){
       this->first = newGuest;
       this->last = newGuest;
}
   else{
       this->last->next = newGuest;
       this->last=newGuest;
}
   numberOfGuests++;
}
void waitList::deletePerson(string name){
   if(!first){
       cout<<"The list is empty!"<<endl;
       return;
   }
   if(first->name == name){
       guest* temp = first;
       if (last->name==name)
       first = last = NULL;
       else
           first = first->next;
       delete temp;
       numberOfGuests--;
       return;
   }
   for(guest* temp = first; temp->next; temp=temp->next){
       if(temp->next->name == name){
           if(temp->next == last)
           last = temp;
           guest* temp2 = temp->next;
           temp->next = temp->next->next;
           delete temp2;
           numberOfGuests--;
           return;
       }
   }
   cout<<"The guest named "<<name<<" is not in the list!"<<endl;
}
guest* waitList::getFirst(){
   return first;
}
guest* waitList::getLast(){
   return last;
}
  

3.)test.cpp

#include"waitlist.cpp"
#include<cstdlib>
using namespace std;
int main(){
   waitList queue = waitList();
   while(true){
       cout<<"MENU"<<endl;
       cout<<"1.) Add a guest"<<endl;
       cout<<"2.) Delete a guest"<<endl;
       cout<<"3.) Show last guest waiting"<<endl;
       cout<<"4.) Show first guest waiting"<<endl;
       cout<<"5.) Exit"<<endl;
       int ch;
       cout<<endl<<"Your choice : ";cin>>ch;
       while(ch>5||ch<1){
           cout<<"Invalid choice! Re-enter your choice : ";cin>>ch;
       }
       string name;guest* g;
       switch(ch){
           case 1:
               cout<<"Enter the guest's' name: ";cin.get();
               getline(cin,name);
               queue.addPerson(name);
               break;
           case 2:
               cout<<"Enter the guest's name: ";cin.get();
               getline(cin,name);
               queue.deletePerson(name);
               break;
           case 3:
               g = queue.getLast();
               if(g!=NULL)
               cout<<"The last guest waiting is '"<<g->name<<"'\n";
               else
               cout<<"The queue is empty\n";
               break;
           case 4:
               g = queue.getFirst();
               if(g!=NULL)
               cout<<"The first guest waiting is '"<<g->name<<"'\n";
               else
               cout<<"The queue is empty\n";
               break;
           case 5:
           cout<<"Exiting....\n";exit(0);
       }
       cout<<"----------------------------------------------------------------------\n";
   }
}

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

I made two changes to make your files program work:

1. Added header guards in header file

2. In test.cpp, changed #include “waitlist.cpp” to #include “waitlist.h”

Run test.cpp and waitlist.cpp simultaneously.

Code:

//waitlist.h:

#ifndef WAITLIST_H
#define WAITLIST_H
#include<iostream>
using namespace std;

class guest {
public:
    string name;
    guest * next;
    guest * prev;
    guest(string);

};

class waitList {
    int numberOfGuests;
    guest * first;
    guest * last;
public:
    waitList();
    void addPerson(string);
    void deletePerson(string);
    guest * getFirst();
    guest * getLast();

};
#endif

1 2 #ifndef WAITLIST_H #define WAITLIST_H #include<iostream> using namespace std; 3 4 5 6 7 8 class guest { public: string na

//waitlist.cpp:

#include<iostream>
#include"waitlist.h"
using namespace std;

guest::guest(string name) {
    this -> name = name;
    this -> next = NULL;
}

waitList::waitList() {
    this -> numberOfGuests = 0;
    this -> first = this -> last = NULL;
}
void waitList::addPerson(string Name) {
    guest * newGuest = new guest(Name);
    if (this -> first == NULL) {
        this -> first = newGuest;
        this -> last = newGuest;
    } else {
        this -> last -> next = newGuest;
        this -> last = newGuest;
    }
    numberOfGuests++;
}
void waitList::deletePerson(string name) {
    if (!first) {
        cout << "The list is empty!" << endl;
        return;
    }
    if (first -> name == name) {
        guest * temp = first;
        if (last -> name == name)
            first = last = NULL;
        else
            first = first -> next;
        delete temp;
        numberOfGuests--;
        return;
    }
    for (guest * temp = first; temp -> next; temp = temp -> next) {
        if (temp -> next -> name == name) {
            if (temp -> next == last)
                last = temp;
            guest * temp2 = temp -> next;
            temp -> next = temp -> next -> next;
            delete temp2;
            numberOfGuests--;
            return;
        }
    }
    cout << "The guest named " << name << " is not in the list!" << endl;
}
guest * waitList::getFirst() {
    return first;
}
guest * waitList::getLast() {
    return last;
}

1 2 #include<iostream> #includewaitlist.h using namespace std; 3 4 5 6 guest::guest(string name) { this -> name = name; thi

//test.cpp:

#include"waitlist.h"
#include<cstdlib>
using namespace std;

int main() {
    waitList queue = waitList();
    while (true) {
        cout << "MENU" << endl;
        cout << "1.) Add a guest" << endl;
        cout << "2.) Delete a guest" << endl;
        cout << "3.) Show last guest waiting" << endl;
        cout << "4.) Show first guest waiting" << endl;
        cout << "5.) Exit" << endl;
        int ch;
        cout << endl << "Your choice : ";
        cin >> ch;
        while (ch > 5 || ch < 1) {
            cout << "Invalid choice! Re-enter your choice : ";
            cin >> ch;
        }
        string name;
        guest * g;
        switch (ch) {
        case 1:
            cout << "Enter the guest's' name: ";
            cin.get();
            getline(cin, name);
            queue.addPerson(name);
            break;
        case 2:
            cout << "Enter the guest's name: ";
            cin.get();
            getline(cin, name);
            queue.deletePerson(name);
            break;
        case 3:
            g = queue.getLast();
            if (g != NULL)
                cout << "The last guest waiting is '" << g -> name << "'\n";
            else
                cout << "The queue is empty\n";
            break;
        case 4:
            g = queue.getFirst();
            if (g != NULL)
                cout << "The first guest waiting is '" << g -> name << "'\n";
            else
                cout << "The queue is empty\n";
            break;
        case 5:
            cout << "Exiting....\n";
            exit(0);
        }
        cout << "----------------------------------------------------------------------\n";
    }
}

1 2 #include waitlist.h #include<cstdlib> using namespace std; 3 4 5 6 7 8 9 10 11 12 13 int main() { waitList queue waitli

Output:

Cib. test MENU 1.) Add a guest 2.) Delete a guest 3.) Show last guest waiting 4.) Show first guest waiting 5.) Exit Your choiMENU 1.) Add a guest 2.) Delete a guest 3.) Show last guest waiting 4.) Show first guest waiting 5.) Exit Your choice : 4 The

Add a comment
Know the answer?
Add Answer to:
below i added the code, but while running it, makefile.win error showing. how i fix this?...
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
  • I have a C++ code that lets me enter, display and delete a student record. I...

    I have a C++ code that lets me enter, display and delete a student record. I need to implement a function that prints the average grade score of the students I input. Below is my code and a picture of how my code looks right now. #include<iostream> #include<stdlib.h> using namespace std; //Node Declaration struct node {    string name;    string id;    int score;    node *next;   }; //List class class list {        private:        //head...

  • You will design a program to keep track of a restaurants waitlist using a queue implemented...

    You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list. Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables. Add the following operations to your program: Return the first person in the queue Return the last person in the queue Add a person to the queue Delete a person from the queue Create a main program to...

  • Linkedlist implementation in C++ The below code I have written is almost done, I only need...

    Linkedlist implementation in C++ The below code I have written is almost done, I only need help to write the definition for delete_last() functio​n. ​ Language C++ // LinkedList.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <string> #include <iostream> using namespace std; struct Node { int dataItem;//Our link list stores integers Node *next;//this is a Node pointer that will be areference to next node in the list }; class LinkedList { private: Node *first;...

  • C++ - I have a doubly linked list, but I haven't been able to get the...

    C++ - I have a doubly linked list, but I haven't been able to get the "reverse list" option in the code to work(It's option #in the menu in the program). I received this guidance for testing: Test 4 cases by entering (in this order) c,a,z,k,l,m This tests empty list, head of list, end of list and middle of list. Then delete (in this order) a,z,l. This tests beginning, end and middle deletes. This exhaustively tests for pointer errors. #include...

  • Fix my code, if I the song or the artist name is not on the vector,...

    Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...

  • 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();...

  • Q) Modify the class Linked List below to make it a Doubly Linked List. Name your...

    Q) Modify the class Linked List below to make it a Doubly Linked List. Name your class DoublyLinkedList. Add a method addEnd to add an integer at the end of the list and a method displayInReverse to print the list backwards. void addEnd(int x): create this method to add x to the end of the list. void displayInReverse(): create this method to display the list elements from the last item to the first one. Create a main() function to test...

  • #include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ...

    #include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ListNode *head; class LinkedList { public: int insertNode(float num); void deleteNode(float num); void destroyList(); void displayList(); LinkedList(void) {head = NULL;} ~LinkedList(void) {destroyList();} }; int LinkedList::insertNode(float num) { struct ListNode *newNode, *nodePtr = head, *prevNodePtr = NULL; newNode = new ListNode; if(newNode == NULL) { cout << "Error allocating memory for new list member!\n"; return 1; } newNode->value = num; newNode->next = NULL; if(head==NULL) { cout << "List...

  • Hi I got error C2660 : 'valuein' : function does not take 2 parameters in visual...

    Hi I got error C2660 : 'valuein' : function does not take 2 parameters in visual studio 2013 this is my code so far #include <cstdlib> #include <list> #include <iostream> using namespace std; struct node {    int data;    node* next; }; void initialize(node*p); void insert(int data,int n); void remove(int b,int pos); bool empty(node*); void length(); bool valuein(int c); int reportvalue(int value); void ptintlist(); int menu(); int main() {    struct node*head=NULL;    char commands;    int value;   ...

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