Question: This is my C language assignment. Please help me to solve this. Thank you. Task: please complete the program in the next page. One of

This is my C language assignment. Please help me to solve this. Thank you.

This is my C language assignment. Please help me to solve this.

Thank you. Task: please complete the program in the next page. One

of execution examples is also shown in this page. ./ a.out The

Task: please complete the program in the next page. One of execution examples is also shown in this page. ./ a.out The present car position is: (0.00, 0.00) The remaining gas is: 90.000000L Shall we start the trip? [1] The coordinate of the destination; [0] finish. 1 X for the destination is: 20.0 Y for the destination is: 40.0 The present car position is: (20.00, 40.00) The remaining gas is: 45.278640L Shall we start the trip? [1] The coordinate of the destination; [0] finish. O #include #include #define sqr(n) (n) * (n)) /* return n2 */ /* The structure "Point presents a coordinate position. It has two double type members: (x, y)) */ typedef struct {/*...*/} Point; /* The structure Car presents a car. It has two members: the position of the car (x, y) (type Point), and the remaining gas (type: double)) */ typedef struct {/*...*/} Car; /* The function "distance_of' returns the amount of the gas to be used for traveling between two positions (x1, y1), (x2, y2)). The formulation is: the amount of the gas = (x2 x1)2 + (y2 - y1)2 */ double distance_of(Point pa, Point pb) {/*...*/} /* The function put_info" outputs the information about the car: the present position and the remaining gas* / void put_info(Car c) { printf("The present car position is: (%.2f, %.2f)') , /*...*/); printf("The remaining gas is: %2f L) , /*...*/); /* The function move judges if the remaining gas is enough to get to the destination or not: if it is not enough, returns 0; if it is enough, before it returns 1. [1] the new position of the car should be the coordinate of destination; [2] the remaining gas of the car should reduce the gas for traveling */ int move (Car *c, Point dest) { double d = distance_of(c->pt, dest); /*...*/ int main(void) { Car mycar = {{0.0, 0.0}, 90.0}; while(1) { int select; Point dest; double x, y; put_info(mycar); printf(Shall we start the trip? [1] The coordinate of the destination; [C] finish.); scanf ("%d", &select); if (select != 1) break; printf(X for the destination is: "); scanf("%lf, /*...*/); printf(Y for the destination is: "); scanf("%lf, /*...*/); if (! move(&mycar, dest)) printf(There is not enough gas left. ); } return 0

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!