Exemplo n.º 1
0
int main()
{
    int choice = 0, numToAdd = 0, temp = 0;
    Queue QueueNode;
    
    do
    {
        // diplay menu of choices for user
        menu();
        
        // get and validate user's choice
        choice = user_selection();
        
        if (choice == 1)
        {
            cout << "Enter value to add to end of queue: ";
            
            // get and validate user's input
            numToAdd = validate();
            
            // Add number to the back of the queue
            QueueNode.addBack(numToAdd);
        }
        
        else if (choice == 2)
        {
            // remove value at front of queue w/o deleting node
            QueueNode.removeFront();
        }
        
        else if (choice == 3)
        {
            temp = QueueNode.getFront();
            
            while (temp != -1)
            {
                cout << temp << " ";
                
                QueueNode.removeFront();
                
                temp = QueueNode.getFront();
            }
        }
        
    } while (choice != 4);

    
    return 0;
}
Exemplo n.º 2
0
/*********************************************************************
** Function: userSelection
** Description: Sets rosters for both players
** Parameters: valid pointer to queue
** Pre-Conditions: valid pointer to queue
** Post-Conditions: queue with characters as assigned by player
*********************************************************************/
void userSelection(int rosterNum, Queue &queIn, int team){
	character *fighter = NULL;
	//string used to hold user selection
	string fighterChoice = "";
	int choice = 0;
	string name;

	for (int i = 0; i < rosterNum; i++){
		cout << "Fighter " << i + 1 << endl;
		cout << "1. Goblin 2. Reptile 3. Barbarian 4. Shadow 5. Blue Man" << endl;
		do{
			fighterChoice = getInput();
			choice = atoi(fighterChoice.c_str());
			if (choice > 5 || choice < 1) fighterChoice = "";
		} while (fighterChoice == "");

		//Create the first character object
		fighter = setFighters(choice);
		
		do{
			cout << "Character name (cannot be blank, cannot start with a space): ";
			getline(cin, name);
			if (name.size() > 0){
				if (name.at(0) == ' '){
					cout << "Name cannot begin with a space. Please reenter." << endl;
					name = "";
				}
			}
		} while (name == "");
		fighter->setFightName(name);
		fighter->setTeamNum(team);

		queIn.addBack(fighter);
	}

}
Exemplo n.º 3
0
int main(int argc, char * argv[])
{
    // Parse command line rguments
    customArgParser::InitalizeArguments();
    argp_parse (&customArgParser::argp, argc, argv, 0, 0, &customArgParser::arguments);

    DebugConsole::debug_print (0, true, COLOR_GREEN, "CS_162 lab_fb automated testing.\n\n");

    if (customArgParser::arguments.debugEnable == true)
    {
      DebugConsole::SetDebugLevel (1);
    }

    DebugConsole::debug_print (0, true, COLOR_WHITE, "Starting Automated tests...\n");

    // Create a stack and a queue

    Queue * myQueue = new Queue;
    Stack * myStack = new Stack;

    // Test functions on empty stack/queue
    // Check for segment violation

    myQueue->getFront();
    myQueue->removeFront();
    
    myStack->peek();
    myStack->pop();

    // Populate data

    myStack->push (1);
    myStack->push (2);
    myStack->push (3);

    // This should pop the number 3

    DebugConsole::debug_print (0, true, COLOR_WHITE, "stack pop: %d\n", myStack->peek());
    myStack->pop();

    // push more data

    myStack->push (4);
    myStack->push (5);

    // Print all data, empty stack

    while (!myStack->isEmpty())
    {
      DebugConsole::debug_print (0, true, COLOR_WHITE, "stack pop: %d\n", myStack->peek());
      myStack->pop();
    }

    // Push more items onto stack

    myStack->push (6);
    myStack->push (7);
    myStack->push (8);
    
    // Add items to the queue

    myQueue->addBack(1);
    myQueue->addBack(2);
    myQueue->addBack(3);

    // Get the first item from the queue and remove the first one

    DebugConsole::debug_print (0, true, COLOR_WHITE, "queue getFront: %d\n", myQueue->getFront());
    myQueue->removeFront();

    // Add more items to the queue

    myQueue->addBack(4);
    myQueue->addBack(5);

    // Print all queue items
    // Empty the queue

    while (!myQueue->isEmpty())
    {
      DebugConsole::debug_print (0, true, COLOR_WHITE, "queue getFront: %d\n", myQueue->getFront());
      myQueue->removeFront();
    }

    // Add new items to an empty queue

    myQueue->addBack(6);
    myQueue->addBack(7);
    myQueue->addBack(8);

    // Print all items from queue and stack
    // Remove all stack/queue items.

    while (!myStack->isEmpty())
    {
      DebugConsole::debug_print (0, true, COLOR_WHITE, "stack pop: %d\n", myStack->peek());
      myStack->pop();
    }
    while (!myQueue->isEmpty())
    {
      DebugConsole::debug_print (0, true, COLOR_WHITE, "queue getFront: %d\n", myQueue->getFront());
      myQueue->removeFront();
    }

    // Add more items to the stack and queues.

    myStack->push (10);
    myStack->push (11);
    myStack->push (12);
    myQueue->addBack(10);
    myQueue->addBack(11);
    myQueue->addBack(12);

    // Leave the data in the stack and queue to test for proper clean up when the Stack/Queue class is destroyed.
    // Delete stack and queue to test class destructors.
    delete myStack;
    delete myQueue;
    
    DebugConsole::debug_print (0, true, COLOR_WHITE, "Automated tests complete.\n");

    // Exit and return success.
    return 0;
}