Define a car structure type

Assignment Help JAVA Programming
Reference no: EM13764087

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).

Reference no: EM13764087

Questions Cloud

Osi model-switching systemsnetwork-channel processors : A switch is a Data Link layer device, which means it's able to look into the packets that pass through it to examine a critical piece of Data Link layer information: the MAC address. With this information in hand, a switch can keep track of which ..
Computation of present value : Using the appropriate interest table, compute the present values of the following periodic amounts due at the end of the designated periods.
Distinguishing feature of a common law legal system : Which of the following is a distinguishing feature of a common law legal system
Discuss the main parts of the auditor report : Discuss the main parts of the Auditor Report for the company (list the 8 parts for audit report and match them with your selected auditor report).
Define a car structure type : 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 redirect..
Write a c program that will calculate the gross pay : Write a C program that will calculate the gross pay of a set of employees. For each employee the program should prompt the user to enter the clock number, wage rate, and number of hours as shown below.
Find economies of scope : Find economies of scope. Provide examples of specific actions Harley-Davidson's managers could take to reduce expenses or share activities through horizontal relationships across brands.
History of women and minorities in policing : History of Women and Minorities in Policing
Revenue expenditures and capital expenditures : Write a 400 - 700-word summary explaining the differences between revenue expenditures and capital expenditures during a useful life and identifying any similarities. Briefly explain the entries of revenue expenditures and capital expenditures.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Bulloil company is planning a large pipeline from east to

bulloil company is planning a large pipeline from east to west x-axis across its oil fieldbullthe field has n

  1 what makes a program easy to modify2 describe the order

1. what makes a program easy to modify?2. describe the order of magnitude of the following code section using bigo

  How many states are there and draw and label the states

How many states are there and draw and label the states (with variable values) and transitions (with method names). Notice that all of the methods are total.

  Write a friend function that can examine the elements

Write a friend function that can examine the elements directly, or pop the stacks and save the popped elements so that the stacks can be restored.

  Implement a shopping cart class with user interface

project will be to implement a shopping cart class with user interface (UI) that contains main() in Net Beans. The UI class will be used to perform user input/output and to invoke the appropriate methods of shopping cart class. When your program star..

  Ticketmaster

TICKETMASTER - this class will have: a service charge = $8.00 per ticket, tax = .085 current amount of all tickets sold. Its responsibilities are printing a list of events for sale, looking up an event for a customer, and selling a ticket to the e..

  Traditionally-nutrition programs were targeted to indigent

Traditionally, nutrition programs were targeted to the indigent and poor populations in developing countries. Many of today's Americans are malnourished also, but they are glutted with a wealth of unhealthy foods and require a multidisciplinary appro..

  Write a complete java program assuming that the variables gp

Write a complete java program Assuming that the variables gpa, deanList and studentName have been declared, you should read in the studentName and gpa from keyboard. Write an if statement that adds 1 to deansList and prints studentName to the standar..

  Implement the employee class and its three child classes

Implement the Employee class and its three child classes (ManagementEmployee, EngineeringEmployee and AdministrationEmployee), with all the necessary attributes and methods.

  Create a program that does runtime performance

Create a program that does runtime performance analysis of ArrayLists, TreeSets and HashSets.Add 100,000 random random integers ( 0 - 1,000,000 )Attempt to remove 10,000 random integers ( 0 - 1,000,000 )

  Critics of american often that teacher''s unions represent

Which organization has proposed a set of standards for both elementary level and secondary-level teachers? According to the latest info.,  teachers will be most needed in which of the following areas: Critics of American often argue that teacher's un..

  Create a 2-by-3 two-dimensional array of integers

Create a 2-by-3 two-dimensional array of integers and fill it with data. Loop through the array and locate the smallest value stored.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd