예제 #1
0
/*
Function Name: Print
Purpose: Visit to print all remaining suspects
in-order.
Restriction: Only useable in an inquiry.
Pre-condition: printVisit() defined
*/
void PRINT(BinarySearchTree tree)
{
  int suspectsLeft = 0;
  tree.countSuspects(countRemainingSuspects, suspectsLeft);
  if (suspectsLeft == 0){
    cout << "There are currently no suspects." << endl;
  } else {
    cout << "The following suspects remain:" << endl;
    tree.inorderTraverse(printVisit);
    cout << endl;
  }
}
예제 #2
0
/*
Function Name: INQUIRY
Purpose: to begin a search for a suspect.
Allows the use of Tip, Check and Print
*/
string INQUIRY(BinarySearchTree tree)
{
    //Define loop and inquiry vars
    string sessionName, command, exitCommand;
    bool inquiryEnd = false;
    int suspectsLeft;
    //Initialize exitCommand to a specific value to
      //be read by the main function in case of
      //improper session name.
    exitCommand = "IMPROPER";
    //Make new tree and copy so I'm not constantly
      //referencing the tree.
    BinarySearchTree inquiryTree;
    inquiryTree = tree;
    //Begin prompting user
    cout << "Enter a name for this inquiry:" << endl;
    getline (cin, sessionName);
    //If sessionName is of appropriate length
    if(sessionName.length() > 0 & sessionName.length() < 31) {
      while (inquiryEnd == false){
        cout << "Now doing inquiry: " << sessionName;
        //line split because of character limit
        cout << ". You can use CHECK, PRINT or TIP." << endl;
        cout << "(ADD, INQUIRY or QUIT will break ";
        cout << "you out of the inquiry.)" << endl;
        cout << endl;
        getline (cin, command);
        upCase(command);
        if (command == "TIP") {
          TIP(inquiryTree);
          //Always reset suspectsLeft to 0 before calling
            //countSuspects because it is an incrementer.
          suspectsLeft = 0;
          inquiryTree.countSuspects(countRemainingSuspects, 
                   suspectsLeft);
          if(suspectsLeft == 1) {
            cout << "ALERT! That leaves only one" << endl;
            cout << "suspect in the " << sessionName;
            cout << " inquiry: ";
            //Since there's only one suspect, just call
              //the traverse function used in the PRINT
              //function.
            inquiryTree.inorderTraverse(printVisit);
          } else if (suspectsLeft == 0) {
            cout << "ALERT! That means there are no suspects" << endl;
            cout << "left in the " << sessionName;
            cout << " inquiry." << endl;
          }
        } else if (command == "CHECK"){
          CHECK(inquiryTree);
        } else if (command == "PRINT"){
          PRINT(inquiryTree);
        } else if (command == "ADD" | command == "INQUIRY"
                                  | command == "QUIT") {
            exitCommand = command;
            inquiryEnd = true;
            //destroy the inquiry tree to save memory
            inquiryTree.~BinarySearchTree();
            cout << endl;
            cout << "Ending inquiry: " << sessionName << endl;
            cout << endl;
        }
      }
    }
    return exitCommand;
}