Starting from:

$30

COMSCI31 Project 2-Solved

Your job at Yentl's Rentals is to write a program to determine how much to charge a car rental customer who has rented a car for a certain number of days and driven a certain number of miles.

 Your program must accept as input the odometer readings at the start and end of the rental, the number of days the car was rented, the customer's name, whether or not the car is a luxury car, and the month the rental started.

 Here is an example of a dialog with the program (user input is shown here in boldface):

 Odometer at start: 2417
Odometer at end: 2754
Rental days: 4
Customer name: Lewis Hamilton
Luxury car? (y/n): n
Month (1=Jan, 2=Feb, etc.): 10
---
The rental charge for Lewis Hamilton is $248.77

 An odometer reading is an integer indicating the number of miles the car has been driven since being built. In the example above, Lewis Hamilton drove 337 miles. The number of rental days is an integer.

 Here is the Yentl's Rentals schedule of charges:

 The base charge for a rental is $43 per day for a non-luxury car, or $71 per day for a luxury car. In addition to the base charge, there is a charge per mile driven. The first 100 miles driven cost $0.27 per mile. In addition, for the next 400 miles driven, the charge is $0.27 per mile for a rental starting in a winter month (December through March), or $0.21 per mile for rentals starting in other months. In addition, for every mile beyond 500 miles, the charge is $0.17 per mile. As an example, Lewis Hamilton above would be charged a base charge of $172 (4 days at $43 per day for a non-luxury car) plus $27 for the first 100 miles driven, plus $49.77 for the remaining 237 miles driven (starting in October), for a total of $248.77.

 Here's another example:

 Odometer at start: 1885
Odometer at end: 1973
Rental days: 1
Customer name: Richard Petty
Luxury car? (y/n): y
Month (1=Jan, 2=Feb, etc.): 2
---
The rental charge for Richard Petty is $94.76

 For the examples above, if your program's behavior is not exactly as shown, it will probably fail most of our other test cases as well.

 You can test your understanding of the schedule of charges by experimenting with this rental charge calculator we found at the Yentl's Rentals web site.

 Your program must collect the information for one customer in the manner indicated by the examples, and then write to cout a line with three hyphens only (no spaces or other characters), followed by exactly one line in a format required below. Our grading tool will judge the correctness of your program by examining only the line following the line with three hyphens (and verifying that there are no additional lines). That one line you write must be in one of the following seven forms; the text must be identical to what is shown, except that italicized items are replaced as appropriate:

 If the starting odometer reading is negative: The starting odometer reading must not be negative. If the ending odometer reading is less than the starting reading: The ending odometer reading must be at least as large as the starting reading. If the number of rental days is not positive: The number of rental days must be positive. If an empty string was provided for the customer name: You must enter a customer name. If the luxury status is not y or n (must be lower case): You must enter y or n. If the month number is not an integer between 1 and 12 inclusive: The month number must be in the range 1 through 12. If the input is valid and none of the preceding situations holds: The rental charge for customer is $amount In the last case, customer must be the customer name the user entered, and amount must be the correct answer, shown as a nonnegative number with at least one digit to the left and exactly two digits to the right of the decimal point. The lines you write must not start with any spaces. If you are not a good speller or typist, or if English is not your first language, be especially careful about duplicating the messages exactly. Here are some foolish mistakes that may cause you to get very few points for correctness on this project, no matter how much time you put into it, because the mistake will cause your program to fail most or all of the test cases we run:

 Not writing to cout a line with exactly three hyphens in all cases. Writing any spaces or any other text on the line that is supposed to have three hyphens. Writing more than one line after the line with three hyphens. Don't, for example, add a gratuitous "Thank you for being gentle with your Yentl rental!". Writing lines to cerr instead of cout. Writing lines like these: You must enter a customer name missing period The rentel charge for Mario Andretti is $123.40 misspelling The rental Charge for Mario Andretti is $123.40 wrong capitalization rental charge for Mario Andretti is $123.40 missing text The rental charge for Mario Andretti will be $123.40 wrong text The rental charge for Mario Andretti is $ 123.40 extra space The rental charge for Mario Andretti is 123.40 missing dollar sign The rental charge for Mario Andretti is $123.40. extra period The rental charge for Mario Andretti is $123.400 extra digit The rental charge for Mario Andretti is $123 missing decimal point and digits Your program must gather the starting and ending odometer readings, the number of rental days, the customer name, the luxury status, and the rental month in that order. However, if you detect an error in an item, you do not have to request or get the remaining items if you don't want to; just be sure you write to cout the line of three hyphens, the required message and nothing more after that. If instead you choose to gather all input first before checking for errors, and you detect more than one error, then after writing the line of three hyphens, write only the error message for the earliest erroneous item.

 You will not write any loops in this program. This means that each time you run the program, it handles only one customer. It also means that in the case of bad input, you must not keep prompting the user until you get something acceptable; our grading tool will not recognize that you're doing that.

 A string with no characters in it is the empty string. A string with at least one character in it is not the empty string, even if the only characters in it are things like spaces or tabs. Although realistically it would be silly to have a customer name consisting of seventeen spaces and nothing more, treat that as you would any other non-empty string: as a valid customer name. (Since you don't yet know how to check for that kind of situation anyway, we're not requiring you to.)

 The one kind of input error that your program does not have to deal with, because you don't yet know how to do so, is not finding an integer in the input where an integer is expected. We promise that our grading tool will not, for example, supply the text a whole lot or 3256.5 when your program requests an odometer reading.

 The correctness of your program must not depend on undefined program behavior. Your program could not, for example, assume anything about n's value at the point indicated:

 int main()
{
    int n;
    int m = 42 * n;  // n's value is undefined
    …

 Your program must build successfully under both g31 and either Visual C++ or clang++.

More products