For this assignment you will write a program that


For this assignment you will write a program that determines which of a set of rental cars the user can rent for a user-specified rental rate. The rental car data is contained in a text file which will be fed into your program using stdin redirection (or a pipe, as you prefer). Your submission should follow the instructions for program organization and Moodle submission given in Lab 5.
Your program must be written entirely using pointer syntax; i.e., it cannot contain any []'s

(hint: the declaration char* argv[] can be written char** argv). Remember to follow all of the dynamic memory allocation/deallocation "rules" given in class.

Your program must meet the following requirements:

1. The input file of rental car data will have the following format:
a. The first line will consist of the number of cars in the file.
b. Each line after the first will consist of a single car record, formatted as follows:

modelName year rentalRate

2. Define a Car structure type in your header file. The Car structure should have three fields: a model (a string), a year (an integer), and a daily rental rate (a floating point number). The model field string will be dynamically allocated (see function 3(b) below).

3. Your program should define the following functions:

a. A function that takes a single Car argument. The function should output the fields of the Car in a sentence. The rate should be formatted as money.
b. A function that takes a single Car argument. The function should first dynamically allocate the Car model field large enough to hold a string of at most 50 characters in length. It should then use scanf to read the next line from stdin and place the values into the appropriate
fields in the Car argument. The function should return 0 if successful and 1 if an error occurred in reading the line. This function should not perform any output.
c. A function that takes as arguments an array of cars and the number of cars that array can hold. The function should fill the array with the indicated number of cars using calls to your function 3(b). The function should perform reasonable error checking and should return 0 if successful and 1 if an error occurred. This function should not perform any output.
d. A function that takes as arguments an array of cars, the number of cars in the array, and a desired rental rate. The function should print-out all cars in the array with a rental rate less than or equal to the specified rate, calling your function 3(a) to perform any car output.

4. Your main function should do the following:

a. Your program should take one command line argument which represents the desired rental rate.
b. Dynamically allocate an array of Cars exactly large enough to hold the number of cars in the input file (see 1(a) above).
c. Fill the array with cars from stdin by calling your function 3(c). If an error occurs give an informative error message and exit the program with a status value of 1.
d. Call your function 3(d) with the desired rental rate (specified as a command line argument).

Run your program three times with a command line argument rental rate of $50.00, and redirecting stdin (or piping) from the rental car data files cars1.txt, cars2.txt, and cars3.txt.

These files are available in /usr/local/cs367/cars.tar.gz on cs367.sou.edu (hint: one or more of these input files may contain an intentional error that should cause your program to exit with an appropriate error message during input processing).

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: For this assignment you will write a program that
Reference No:- TGS01034165

Expected delivery within 24 Hours