Exemple #1
0
bool SolverClass::findSolHelp(SimpleVector<Rectangle> &hand, int index)
{
	Rectangle insertRect;
	hand.getValueAt(index, insertRect);

	if(findUnused(index, rectangleData))
	{
		if(drawRectangle(index))
		{
			findSolHelp(rectangleData, index + 1);
		}
		remove(index);
		findSolHelp(rectangleData , index);
	}

	else if(index == hand.getSize())
	{
		return true;
	}
	else
	{
		cout << "NO SOLUTION" << endl;
		return false;
	}
	return true;
}
Exemple #2
0
bool SolverClass::findUnused(int index, SimpleVector<Rectangle> &hand)
{
	Rectangle temp;
	int rectCount;
	for(rectCount = 0; rectCount < hand.getSize(); rectCount++)
	{
		hand.getValueAt(rectCount, temp);
		if(!temp.isUsed())
		{
			index = rectCount;
			return true;
		}
	}
	return false;
	
}
Exemple #3
0
int  main()
   {
    SimpleVector<char> testVectorA;
    SimpleVector<char> testVectorB( TEST_VECTOR_B_CAPACITY );
    SimpleVector<char> testVectorC( testVectorB );
    SimpleVector<char> testVectorD( TEST_VECTOR_D_CAPACITY, 'O' );

    int indexOrControl;          // List index or control
    char dataItem;               // data value
    int value = 0, dummy = 0;    // dummy used to fool compiler (no warnings allowed)
    bool dataChanged;
    char commandString[ SMALL_STR_LEN ];
    CONTROL_CODES command;
    
    ShowMenu();

    do
       {
        dataChanged = false;

        cout << endl << "Command: ";                  // Read command
        
        GetCommandInput( commandString );

        GetDataInput( commandString, indexOrControl, dataItem );

        command = ProcessInput( commandString );

        if( !VERBOSE )
           {
            cout << commandString << ", index-control: " 
                 <<  indexOrControl << ", data item: " 
                 << dataItem << endl;
           }

        switch ( command )
           {
            case AAI_CODE:  // assign at index

               testVectorA[ indexOrControl ] = dataItem;

               dataChanged = true;

               if( VERBOSE )
                  {
                   cout << "  Value " << dataItem 
                        << " has been assigned to the array at index "
                        << indexOrControl << endl;
                  }
               break;

            case ATB_CODE:  // assign to vector b

               testVectorB = testVectorA;

               dataChanged = true;

               if( VERBOSE )
                  {
                   cout << "  Test list \'A\' has been assigned to test list \'B\'." 
                        << endl;
                  }
               break;

            case CNC_CODE:  // construct c test list

               // tempTestList constructed in code block to control scope
                  { 
                   SimpleVector<char> tempVector( testVectorA );

                   testVectorC = tempVector;
                  }

               dataChanged = true;

               if( VERBOSE )
                  {
                   cout << "  Test list \'C\' has been constructed with test list \'A\'." 
                        << endl;
                  }
               break;

            case DCS_CODE:  // decrement size operation

               testVectorA.decrementSize();

               if( VERBOSE )
                  {
                   cout << "  The size of Vector A has been decreased by one "
                            << "and now has a size of " << testVectorA.getSize()
                            << '.' << endl;
                  }
               break;

            case GAI_CODE:  // get value at index

               dataItem = testVectorA[ indexOrControl ];

               if( VERBOSE )
                  {
                    cout << "  Value: " << dataItem
                         << " found at index " << indexOrControl << '.' << endl;
                  }
               break;

            case HLP_CODE:  // Help
               ShowMenu();
               break;

            case GBX_CODE:  // grow by operation

               testVectorA.grow( indexOrControl );

               if( VERBOSE )
                  {
                   cout << "  Vector A has been increased by " << indexOrControl
                            << " and now has a capacity of " << testVectorA.getCapacity()
                            << '.' << endl;
                  }
               break;

            case INS_CODE:  // increment size operation

               testVectorA.incrementSize();

               if( VERBOSE )
                  {
                   cout << "  The size of Vector A has been increased by one "
                            << "and now has a size of " << testVectorA.getSize()
                            << '.' << endl;
                  }
               break;

            case RTC_CODE:  // return the capacity

               value = testVectorA.getCapacity();

               if( VERBOSE )
                  {
                   cout << "  The capacity of Vector A is " 
                        << value << endl;
                  }
               break;

            case RTS_CODE:  // return the size

               value = testVectorA.getSize();

               if( VERBOSE )
                  {
                   cout << "  The size of Vector A is " 
                        << value << endl;
                  }
               break;

            case SBX_CODE:  // shrink by operation

               testVectorA.shrink( indexOrControl );

               dataChanged = true;

               if( VERBOSE )
                  {
                   cout << "  Vector A has been decreased by " << indexOrControl
                            << " and now has a capacity of " << testVectorA.getCapacity()
                            << '.' << endl;
                  }
               break;

            case ETP_CODE:  // clear the list

               if( VERBOSE )
                  {
                   cout << "  End Program Requested" << endl;
                  }

               break;

            default :            // Invalid command

               // clear to end of line in case further data input
               cin.ignore( SMALL_STR_LEN, ENDLINE_CHAR );

               if( VERBOSE )
                  {
                   cout << "  Inactive or invalid command" << endl;
                  }
           }

        if( dataChanged )
           {
            showData( 'A', testVectorA );
            showData( 'B', testVectorB );
            showData( 'C', testVectorC );
            showData( 'D', testVectorD );
           }
       }
    while ( command != ETP_CODE );

    dummy += value; // to eliminate compiler warning

    return 0;
   }