Question: Attached is my code for an assignment, I am still running into an issue, from the input file it lists a name and coordinates. Unfortunately

Attached is my code for an assignment, I am still running into an issue, from the input file it lists a name and coordinates. Unfortunately I cannot sort the coordinates when the name is inputted, as well I cannot get the distance between each to work. Attached is the code and a sample I/O.

#include #include #include

struct Points {

int x; int y; float z;

};

bool location_of_product(struct Points p1, struct Points p2) { //begins the sort if (p1.x

return true;

} //if x's are equal it will determine the y values else if (p1.x == p2.x){

return p1.y

else { return false; }

}

void array1(struct Points product1[], int left_coordinate, int middle_of, int r) {

int xaxis = middle_of - left_coordinate + 1;

int yaxis = right_coordinate - middle_of; //figures which go in the system first

int i; int j; int k;

struct Points left[xaxis], right[yaxis];

for (i = 0; i

}

//runs the loop until right is satisfied

for (k = 0; k

right[k] = product1[middle_of + 1 + k];

}

i = 0;

j = 0;

int count = left_coordinate;

//Merges L and R

while (i

//finds location of the product

if (location_of_product(left[i], right[j])) {

product1[count++] = left[i++];

}

else {

product1[count++] = right[j++];

}

}

//finds values so the product can be found while (i

product1[count++] = left[i++];

}

while (j

product1[count++] = right[j++];

}

return;

}

//Sorts the locations with recursion

void Sort(struct Points a[], int left, int right) {

int value;

if (left >=right)

{

return;

}

value = (left + right) / 2;

Sort(a, left, value);

Sort(a, value + 1, right);

array1(a, left, value, right);

return;

}

int main() {

int n; int i; int p; int q; int left_coordinate; int right_coordinate;

//computes order for robot FILE *openfile= fopen("in.txt", "r"); // sees how many coordinates there are fscanf(openfile, "%d", &n);

struct Points arr[n];

for (i = 0; i

fscanf(openfile, "%d %d", &p, &q);

arr[i].x = p;

arr[i].y = q;

}

//begins the sort for the other file Sort(arr, 0, n - 1);

FILE *outfile = fopen("out.txt", "w");

for(i=0;i

}

fclose(outfile);

printf("The Shortest routes are "); int c; FILE *file; file = fopen("out.txt", "r"); if (file) { while ((c = getc(file)) != EOF) putchar(c); fclose(file); }

struct Points input;

input.x = p;

input.y = q;

left_coordinate = 0;

right_coordinate = n - 1;

while (left_coordinate

int middle = (left_coordinate + right_coordinate) / 2;

if (location_of_product(arr[middle], input)) {

left_coordinate = middle + 1;

}

else

{

right_coordinate = middle ;

}

}}

Sample Input:

6

PackingStation 0 0

Airpods 0 3

Book 2 0

Coffee 2 3

Dress 2 6

Earphones 0 6

Sample Output:

PackingStation 0 0 0.00

Airpods 0 3 3.00

Earphones 0 6 3.00

Dress 2 6 2.00

Coffee 2 3 3.00

Book 2 0 3.00

PackingStation 0 0 2.00

16.00

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!