Exemple #1
0
bool
GNEJunction::isValid(SumoXMLAttr key, const std::string& value) {
    switch (key) {
        case SUMO_ATTR_ID:
            return isValidID(value) && myNet->retrieveJunction(value, false) == 0;
            break;
        case SUMO_ATTR_TYPE:
            return SUMOXMLDefinitions::NodeTypes.hasString(value);
            break;
        case SUMO_ATTR_POSITION:
            bool ok;
            return GeomConvHelper::parseShapeReporting(value, "user-supplied position", 0, ok, false).size() == 1;
            break;
        case SUMO_ATTR_SHAPE: {
            bool ok = true;
            PositionVector shape = GeomConvHelper::parseShapeReporting(
                                       value, "user-supplied position", 0, ok, true);
            return ok;
            break;
        }
        case SUMO_ATTR_RADIUS:
            return canParse<SUMOReal>(value);
            break;
        case SUMO_ATTR_KEEP_CLEAR:
            return value == "true" || value == "false";
            break;
        default:
            throw InvalidArgument("junction attribute '" + toString(key) + "' not allowed");
    }
}
void Teacher::setEmployeeID(std::string employeeID) {
	// sets the employee ID
	if (isValidID(employeeID)) {
		m_employeeID = employeeID;
	} else {
		cout << "Not a valid teacher ID.\n";
		Sleep(300);
	}
}
Exemple #3
0
int main(int argc, char **argv)
{

	FILE *in = NULL;
	int num_read, array_size = 0;

	if(argc != 2){
		printf("hw4 <input-file>\n");
		return 1;
	}

	in = fopen(argv[1], "r");

	if(in == NULL){
		printf("File can not be opened.\n");
		return 2;
	}

	// declare the array
	int array[MAX_SIZE];

	// read from the second line to get each element of the array
	while(!feof(in)){
		fscanf(in, "%d", &num_read);
		if(isValidID(array, array_size, num_read) == 0) {
			array[array_size] = num_read;
			array_size++;
			printf("%d added to array\n", num_read);
		}
		else if(isValidID(array, array_size, num_read) == 1) {
			printf("ERROR - %d bad ID. Not in range [0, 99].\n", num_read);
		}
		else if(isValidID(array, array_size, num_read) == 2) {
			printf("ERROR - %d bad ID. Duplicate.\n", num_read);
		}
	}
	fclose(in);

	Node *root1 = NULL, *root2 = NULL, *root3 = NULL;

	int i;
	// task1: construct a bst from the unsorted array
	printf("=== task1: construct a bst from the unsorted array ===\n");
	for (i = 0; i < array_size; i++) {
		root1 = bstInsert(root1, array[i]);
	}
	displayTree(root1, 0);
	printf("Height of bst1 is %d\n", getBstHeight(root1));

	// task2: sort the array and use the sorted array to construct a bst, each time taking an element in order
	printf("=== task2: sort the array and use the sorted array to construct a bst ===\n");
	bsort1(array, array_size);
	for (i = 0; i < array_size; i++) {
		root2 = bstInsert(root2, array[i]);
	}
	displayTree(root2, 0);
	printf("Height of bst2 is %d\n", getBstHeight(root2));

	// task3: use the sorted array to construct a balanced bst
	printf("=== task3: use the sorted array to construct a balanced bst ===\n");
	root3 = sortedArrayToBalancedBst(array, 0, array_size-1);
	displayTree(root3, 0);
	printf("Height of bst3 is %d\n", getBstHeight(root3));

	return 0;
}