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

  Demonstrate knowledge of design patterns

Your software should make use of the concepts outlined at the start of the assignment brief above. Think about where you can employ appropriate design patterns and other techniques.

  Elements from a html document

Function test Count List Elements should simply retrieve an array of all list elements on the page and assert that their total count is 3.

  Create an application that will allow a new customer

Create an application that will allow a new customer to order a house. You'll allow the customer to choose among four models (Aspen, Britattany, Colonial, and Dartmoor) by creating separate ButtonGroups.

  Implement a method with three arguments

Implement a method with three arguments: a graph, a starting vertex number, and an ending vertex number. The method determines whether there is a directed path from the starting vertex to the ending vertex.

  Implement a class person with two fields name and age

Implement a class Person with two fields name and age, and a class Car with three fields

  Part-2write a program that will perform some of the basic

part-2write a program that will perform some of the basic tasks accomplished by a file integrity checker such as

  Inheritance involves the concept of super class

Inheritance involves the concept of super class (parent class) and sub class (derived class). What is a super class in Java? What is a sub or derived class in Java?

  Reverse the array, and find the largest element

find the max block of an array by splitting it into three parts: left, middle, right. And then reverse the array, and find the largest element.

  1 explain the differences between our specifications of the

1. explain the differences between our specifications of the sorted list adt and the binary search tree adt.2. define a

  Create a constructor with three default parameters

How can you create a constructor with three default parameters two of type string and one double?

  Explain the graphical coordinate system in java where is

question 1 describe the graphical coordinate system in java. where is the origin? what units apply to the xy

  Write java code to read integers from an input file

write java code to read integers from an input file and write only the odd numbers to an output file. the two file names will be provided on the command line as the input file followed by the output file.

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