コード例 #1
0
/*If all parameters match, update the target vehicle with the information of the numvehicle-1 index and decrease the number of vehicles in the registry by 1
Updating the target vehicle is basically removing the target vehicle*/
bool VehicleRegistry::Remove(Vehicle vehicle)
{
	for (int i = 0; i < numvehicles; i++)
	{
		if ( vehicles[i].GetPlate() == vehicle.GetPlate() && vehicles[i].GetMake() == vehicle.GetMake() && vehicles[i].GetModel() == vehicle.GetModel() && vehicles[i].GetColour() == vehicle.GetColour())
		{
			vehicles[i].Update(vehicles[numvehicles-1].GetPlate(),vehicles[numvehicles-1].GetMake(),vehicles[numvehicles-1].GetModel(),vehicles[numvehicles-1].GetColour());
			vehicles[numvehicles-1].Update("clear","clear","clear","clear");
			numvehicles -= 1;
			return true;
		}
	}

	cout << "could not remove vehicle" << endl;
	return false;
}
コード例 #2
0
	//////////////////////////
    /////// Mutators /////////
    //////////////////////////
bool VehicleRegistry::Insert(Vehicle vehicle)
{
	for (int i = 0; i < numvehicles; i++)
	{
		if (vehicles[i].GetPlate() == vehicle.GetPlate())
		{
			cout << "Failed to insert vehicle, same plate number exists in registry." << endl;
			return false;
		}
	}

	if (numvehicles == maxsize) //expand array
	{
		Vehicle *old_arr = vehicles;
		maxsize = 2*maxsize;
		vehicles = new Vehicle[maxsize];

		for (int i = 0; i < numvehicles; i++)
		{
			vehicles[i].UpdatePlate(old_arr[i].GetPlate());
			vehicles[i].UpdateMake(old_arr[i].GetMake());
			vehicles[i].UpdateModel(old_arr[i].GetModel());
			vehicles[i].UpdateColour(old_arr[i].GetColour());
		}

		delete [] old_arr;
	}

	vehicles[numvehicles].UpdatePlate(vehicle.GetPlate()); //this records the plate number and saves it in the index of vehicles array
	vehicles[numvehicles].UpdateMake(vehicle.GetMake());
	vehicles[numvehicles].UpdateModel(vehicle.GetModel());
	vehicles[numvehicles].UpdateColour(vehicle.GetColour());

	numvehicles += 1;

	return true;
}