Question
Your job is to write a C program that implements a simple car rental information system. Your program keeps track of the cars of a
Your job is to write a C program that implements a simple car rental information system. Your program keeps track of the cars of a rental company and rental information. The program provides a simple user interface to add cars to the company's inventory, to make a car reservation, find a reservation, print rented and non-rented vehicles, and compute average number of days rented. Your program must use the data types and variables described below. A type definition of a new structure named CarT to store car information. This structure must have the following fields: int carId; // a unique ID of a car char make[20]; // make of the car char model[20]; // model of the car int numDoors; // 2 or 4 door cars double rate; // the rental rate of the car A type definition of a new structure named RentalT to store rental information of a renter: char renterName[20]; // name of renter int daysRenting; // days renting the car int carId; // ID of the car rented Two arrays in main() function that store car information and rental information: CarT allCars[20]; // a list of cars RentalT allRentals[60]; // a list of rentals Note that there can be more rentals than cars. This is because we may consider allRentals to store records about cars currently rented and those that have been reserved although the rental period is not captured in this simple program. The program keeps track of the total number of cars owned by the company and the total number of rentals by the following two variables declared in main(): int totalCars; // number of all cars owned int totalRentals; // number of rented cars Write a main program that declares the above specified variables and any other variables you may need. The main program performs the following operations: 1. It calls a function int createInventory(CarT *allCars); to add a total of 3 cars to the inventory with the following information: The new cars must be stored in the first three array positions of the array allCars. The function returns the number of cars that has been added successfully, which should be 3. This value can be used to initialize the local variable totalCars. Use strcpy to store string values. (5 points) 2. Then the program prints a menu to the screen and repeatedly prompts the user to choose from several options shown below: (5 points) 1 Add new car to the inventory. (addNewCar) 2 Make a reservation. (addNewRental) 3 Find a reservation using a renter name and print it to the screen. (findReservation, printCarInfo) 4 Print all rental information to the screen. (printAllRentals) 5 Print car information to the screen of a selected car using the make of the car to search the inventory. (findCarByMake, printCarInfo) 6 Calculate and print average number of days rented. (getAverageRentalDays) 7 Exit program. Except for exiting the program, each option is performed by a function or simple combination of several functions (listed in parenthesis, think of how to make them work together). Your program must call the appropriate function. Use a switch statement to handle the user input and make the function calls and updates as necessary. The function header and definition of the functions are given below. int addNewCar(CarT *allCars, int totalCars, int size); This function must prompt the user for the fields to initialize the values in the structure composing a car. It must use the value of totalCars to select the array location for the new car and set the corresponding fields of the CarT structure. It must use size to check if there is a space in the array. Given the above definition of the array, there can be at most 20 cars in the company's inventory. The function returns the new number of total cars in the inventory. The returned value must be used to update the totalCars variable in main(). (15 points) int addNewRental(CarT *allCars, int totalCars, RentalT *allRentals, int totalRentals, int size); This function must prompt the user for the fields to initialize the values in the structure composing a rental reservation. It must use the value of totalRentals to select the array location for the new rental reservation and set the corresponding fields of the RentalT structure. It must use size to check if there is a new space in the array. Given the above definition of the array, there can be at most 60 cars rented. The function returns the new number of total car rentals. The returned value must be used to update the Car ID Make Model #doors rate 1234 VW Golf 2 66 2241 Ford Focus 4 45 3445 BMW X3 4 128 totalRentals variable in main(). For this function, you must implement and use another function that identifies the carId of the car matching a given cars make: int findCarIDByMake(CarT *allCars, int totalCars, char *carMake); This function searches through the list of cars in the inventory and finds the car matching the given car name as indicated by the make of the car. The function then returns the ID of the car. If the car cannot be located -1 must be returned. (25 points) int findReservation(RentalT *allRentals, int totalRentals, char *renterName); This function locates a reservation in the array that matches the specified renterName in the RentalT structure. It returns the index of the field in the array that stores the matched rental information. The information can then be used to print the fields of the rental information. Instead of printing a carID from the rental information, you must locate the car information in the car array using the carID and print the car information to the screen. This can be achieved by calling the following function: int findCarById(CarT *allCars, int totalCars, int carId); This function searches through the list of cars in the inventory and finds the car matching the given car ID. The function then returns the index of the matched car in the array allCars. If the car cannot be located in the inventory -1 must be returned. With the index of the field storing a CarT structure, the car information can be printed. (25 points) void printAllRentals(RentalT *allRentals, int totalRentals, CarT *allCars, int totalCars); This function prints all car rental information to the screen. Instead of the field carID, the car information must be printed using the above function to locate the index of the car matching the carID. The variable allRentals is the array of rental information,totalRentals is the total number of car rentals, allCars is the array of car information, and totalCars is the number of cars in the inventory. void printCarInfo(CarT *allCars, int totalCars, int carId); This function prints the car information to the screen matching the specified carId. The inventory must be searched for cars matching the given Id to print all the fields in the CarT structure. If there is no car matching Id, then a message of "Car not found" must be printed. (15 points) double getAverageRentalDays(RentalT *allRentals, int totalRentals); This function computes the average number of days cars have been rented considering all rentals. The function examines all rental records in the array to compute the average number of days. The function returns the computed value. If no cars have been rented a value of -1 must be returned. (10 points)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started