The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Hello, you helped me with my last question and it was very helpful, if you don't mind helping me with this one; it is a little longer but you'd have more time to answer it.Â
The information stored for an automobile at a car dealer are saved in the file cars.txt. Each line contains the record for a car including the make and model, manufacture year, city mpg, and highway mpg. Write a program that reads file cars.txt, store the data in an array of car structures, and sort the cars by average mpg (the average of city mpg and high way mpg). Output the sorted cars, including the average mpg in a text file called sorted_cars.txt.  A car structure should have the following attributes:Â
o make             stringÂ
o model             stringÂ
o manufacture year   intÂ
o city mpg          intÂ
o highway mpg      intÂ
You can assume the cars.txt as the following format for each car: make (one single word), model (one single word), manufacture year, city mpg, highway mpg.  Â
Mercury Sable 2009 18Â 28Â
Jeep Wrangler 2016 17 21
 ...Â
1. Name your program car.c.Â
2. The program should be built around an array of structures, with each structure containing information of a car's make, model, manufacture  year, city mpg, highway mpg, and average mpg( average of the city mpg and highway mpg).  Assume the make and model are no more than 30 characters. Assume that there are no more than 1000 cars in the file.Â
3. Use fscanf and fprintf to read and write data.Â
4. Modify the selection_sort function provided to sort an array of product struct. The boxes should be sorted by average mpg in ascending order. The function should have the following prototype:Â
void selection_sort(struct car cars[], int n);Â
5. Output the sorted cars, including average mpg, in a text file called sorted_cars.txt, in the following format.Â
Make     Model    year  city mpg    highway mpg  average mpgÂ
Jeep     Wrangler  2016    17           21            19Â
Mercury  Sable     2009   18            28           23Â
...
Â
Mercury Sable 2009 18 28Jeep Wrangler 2016 17 21Honda civic 2015 31 41Toyota Corolla 2015 30 42Toyta Prius 2010 51 48Ford Escape 2013 23 33Ford Fusion 2013 25 37Acura MDX 2014 20 28Lexus RX 2013 32 28
Attachments:
-----------