Advertisement
Guest User

asmt 1

a guest
Feb 17th, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.56 KB | None | 0 0
  1. Description:
  2. Include the following definitions at the top of your program:
  3.  
  4. #define MAX_STRING_LEN 20
  5.  
  6. typedef struct {
  7. int year;
  8. char* make;
  9. char* model;
  10. int miles;
  11. } Car;
  12.  
  13. void fill_garage(Car** garage, char* cars, int* size);
  14.  
  15. Parameter: garage – A pointer to the pointer, which points to the head of an array of cars
  16. Parameter: cars – The name of the input file
  17. Parameter: size – A pointer to the variable where the size of the array will be stored
  18.  
  19. This function will dynamically create an array to hold the cars and read the contents of
  20. the input file into it. This is the only function which is allowed to use malloc in your
  21. assignment.
  22.  
  23. int equals (Car* car, int year, char* make, char* model);
  24.  
  25. Parameter: car – A pointer to a car struct
  26. Parameter: year – A valid year
  27. Parameter: make - A cars make
  28. Parameter: model – A cars model
  29. Return: 1 if the car has the given year, make, and model; 0 otherwise
  30. This function will determine if the provided car has the specified year, make, and model
  31.  
  32. void drive_cars(Car* garage, int* num_cars, char* driving_records);
  33.  
  34. Parameter: garage – An array of cars
  35. Parameter: num_cars – The length of the garage array
  36. Parameter: driving_records – The name of a file containing driving records
  37. This function will read from the file specified by the driving_records parameter and on
  38. each line read in a year, make, model, and number of miles driven. It will then add the
  39. number of miles to the specified car. If the car does not exist, no action should be taken.
  40.  
  41. void store_car_statisitcs(Car* garage, int num_cars, char* outFile);
  42.  
  43. Parameter: garage– An array of cars
  44. Parameter: num_cars – The length of the garage array
  45. Parameter: outFile – The name of the file to store the car information
  46. Write the car statistics to the output file. See example output below.
  47.  
  48. void empty_garage(Car* garage, int num_cars);
  49.  
  50. Parameter: garage – An array of cars
  51. Parameter: num_cars – The length of the garage array
  52. Frees all malloced memory
  53.  
  54. int main(int argc, char* argv[]);
  55.  
  56. Main should take in the names of the three files as command line arguments and then act
  57. as a driver to call the other functions. It should error check for the correct number of
  58. command line arguments.
  59.  
  60. input file
  61. 3
  62. 1993 Chevy Blazer 100200
  63. 2007 Honda Civic 23787
  64. 1903 Ford ModelT 90000
  65.  
  66. update file
  67. 4
  68. 1993 Chevy Blazer 39
  69. 1903 Ford ModelT 20
  70. 1993 Chevy Blazer 2
  71. 2014 Jeep Patriot 100
  72.  
  73. correct output
  74. The 1993 Chevy Blazer drove 100241 miles
  75. The 2007 Honda Civic drove 23787 miles
  76. The 1903 Ford ModelT drove 90020 miles
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement