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

  • This is just a partial C++ code. I am having a problem with the getline(cin, variable)...

    This is just a partial C++ code. I am having a problem with the getline(cin, variable) statement of my code. Please run the code for yourself and see that it doesn't let you enter the full name. It skips the prompt to enter the name and goes straight to the next cout statement. I can't use cin alone because I need to capture and store both the first name followed by space followed by last name. I was trying to...

  • Hi I've a problem with this code. When I add more than 1 song to the...

    Hi I've a problem with this code. When I add more than 1 song to the list, it doesn't show the first one, only shows the latest one, when I called the function displaysong, let's say when you add 2 songs ID 1 then ID 2, it shows only ID 1. Can you fix it.  Everything else is fine.. #include <iostream> #include<string> using namespace std; //class Song class Song{ private: int songID; string title; string artist; string album; int year; public:...

  • PART A - STACKS To complete this assignment: Please study the code posted below. Please rewrite...

    PART A - STACKS To complete this assignment: Please study the code posted below. Please rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same *************************************************************************************************************** /** * Stack implementation using array in C/procedural language. */ #include <iostream> #include <cstdio> #include <cstdlib> //#include <climits> // For INT_MIN #define SIZE 100 using namespace std; /// Create a stack with capacity of 100 elements int stack[SIZE]; /// Initially stack is...

  • Study the "Queue as linked list simple example" posted in this module. Rewrite the code to...

    Study the "Queue as linked list simple example" posted in this module. Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. LListQueue.cpp ///--------------------------------------------------------------- /// File: LListQueue.cpp /// Purpose: Implementation file for a demonstration of a queue /// implemented as an array. Data type: Character /// Programming Language: C++ ///--------------------------------------------------------------- #include "LListQueue.h" ///-------------------------------------------- /// Function: LListQueue() ///...

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