Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make the walkthrough table should include the values changes for cars[0],cars[1],cars[2],i in main function and values changes for raceDist,tDist,tTime in getTime function and the output

Make the walkthrough table should include the values changes for cars[0],cars[1],cars[2],i in main function and values changes for raceDist,tDist,tTime in getTime function and the output (13 marks)

1. #define _CRT_SECURE_NO_WARNINGS

2. #include

3. #include

4.

5. struct Car {

6. int id;

7. double accel;

8. double topSpeed;

9. double time;

10. };

11.

12. void getTime(struct Car* cr, double raceDist) {

13.

14. double tDist = (cr->topSpeed * cr->topSpeed) / (2 * cr->accel);

15. double tTime = 0;

16.

17.

18. if (tDist > raceDist) {

19.

20. tDist = raceDist;

21. // Time at which the car reaches top speed from a standstill. // SQRT is square root

22. tTime = sqrt(tDist * 2 / cr->accel);

23. }

24. //If the car reaches top speed before track ends

25. else {

26. // Time at which the car reaches top speed from a standstill. // SQRT is square root

27. tTime = sqrt(tDist * 2 / cr->accel) + (raceDist - tDist) / cr->topSpeed;

28. }

29.

30. cr->time = tTime;

31. printf("Car-%d Finishes: %.2lfsec ", cr->id, cr->time);

32.

33. }

34.

35.

36. int main() {

37.

38. struct Car cars[3] = { {1,0.5,30,0},{2,0.1,34,0}, {3,1,25,0 } };

39.

40. int i; 41. for (i = 0; i < 3; i++) {

42.

43. getTime(&cars[i], 1000);

44. }

45.

46. return 0;

47. }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions