I am trying to add commands to my main method in order to properly utilize my wait list program. The commands are:
add name: if the class is not full, add the name to the class. Otherwise, if the wait list is not full, ask the user if they want to join the wait list. If yes, add the name to the wait list and output the position.
drop name: remove the student from the class. If the wait list is not empty, remove the next name from the waitlist and ask the user if the student wants to add the class. If yes, add to the class. If not, repeat, until a student is added or the wait list is empty. Note: if the student does not want to add the class they are still removed from the wait list.
pr: print the roster of the class (sorted).
pwl: print the wait list (from position 1 to the end).
quit: quite the program.
I have this so far:
#include <iomanip>
#include <iostream>
#include <string>
#include <cassert>
using namespace std;
#include "StringQueue.h"
#include "SortedList.h"
int main() {
string name;
int classSize;
SortedList list(classSize);
int waitListSize;
StringQueue myQueue(waitListSize);
bool quit = false;
string str1;
string str2;
char ans;
cout << "Enter class size: "
<< "Enter wait list size: "
<< "Enter the commands:" << endl;
cin >> classSize;
cin >> waitListSize;
while (!quit) {
cin >> str1 >> str2;
if (str1 == "add") {
list.insert(str2);
if (classSize > 5) {
cout << ">Class is full, join the wait list (y/n) ?" << endl;
cin >> ans;
if (ans == 'y' || 'Y')
myQueue.enqueue(str2);
else
quit = true;
}
}
if (str1 == "drop") {
list.remove(str2);
}
if (str1 == "pr") {
list.displayList(cout);
}
if (str1 == "pwl") {
myQueue.display(cout);
}
else
quit = true;
}
return 0;
}
I know there is still some things needed to be added but I am struggling to understand why when included with the other files, the only output I seem to get is "Enter class size: Enter wait list size: Enter the commands:"
Any insight to this problem of mine would be greatly appreciated and if needed, I can comment the other file's codes.
Thank you.
Aucun commentaire:
Enregistrer un commentaire