Question

Assignment You will be developing a speeding ticket fee calculator. This program will ask for a t...

Assignment

You will be developing a speeding ticket fee calculator. This program will ask for a ticket file, which is produced by a central police database, and your program will output to a file or to the console depending on the command line arguments. Furthermore, your program will restrict the output to the starting and ending dates given by the user.

The ticket fee is calculated using four multipliers, depending on the type of road the ticket was issued:

Interstate multiplier:  5.2252
Highway multiplier:     9.4412
Residential multiplier: 17.1525
None of the above:      12.152

The multiplier is multiplied to the difference between the speed limit and the clocked speed to determine the fine's dollar amount.

Use global constants for the multipliers above.

User Interaction

There will be no console interaction with the user for this lab. Instead, you the inputs will be made using command line arguments:

The first user argument will be the database file to read from.

The second user argument will be the start date in the format: year-month-day, such as 2011-11-22

The third user argument will be the end date in the format: year-month-day, such as 2015-11-23

The fourth user argument will be an output file name or a single dash "-". If the user gives you a "-", you will write the report to the console using cout. Otherwise, you will write the report to the given filename.

If the user types - for the output ticket file, you will write the output to the console, otherwise, you will output to an output file.

Date Structure

Create a structure called Date which contains three integers: month, day, and year.

Ticket Structure

Create a structure called Ticket which will describe a single ticket and has the following fields:

1. a string representing the citation number.

2. an Date structure representing the citation date.

3. an integer representing the clocked speed.

4. an integer representing the speed limit.

5. a char representing the type of road.

Database Class

Create a class called "Database" with the following members:

1. a private vector of Ticket structures.

2. a public mutator called add_ticket, which returns nothing and takes a read-only Ticket structure by-reference. This member function will add the given ticket to the private vector.

3. a public accessor called gen_report, which returns a vector of Ticket structures, and takes two Date structures: start and end which will be the start date and end date. This member function will return a vector of Ticket structures whose dates are inclusively between start and end.

Standalone Functions

bool Read(Database &d, istream &in);

Write a standalone function called Read which returns a bool (true if the input successfully read all tickets, false if it was not). This function will take a Database class by-reference and an input stream by reference. The purpose of this function is to read ALL tickets from the input stream and call add_ticket() on the Database class for each ticket read. NOTE: You will be taking an input stream by reference (istream), NOT an input file stream (ifstream).

bool Write(const vector<Ticket> &tickets, ostream &out);

Write another standalone function called Write. This function will take a vector of Ticket structures and output them the to an output stream (ostream), NOT an output file stream (ofstream). This allows you to output to cout or an ofstream or stringstream using the same function.

int Encode(const Date &d);

Write the function Encode. Encode will translate a Date structure containing a month, day, and year into a single integer in the format YYYYMMDD. For example, given October 13, 2018, you would return the integer: 20,181,013 (20181013). The year is always 4 digits, the month is always 2 digits, and day is always 2 digits. A single digit day or month will be preceded by a 0, such as 20190101 would be New Year's Day for 2019.

Input File Format

Each line will contain the following information:

<citation number> <month> <day> <year> <clocked speed> <speed limit> <type of road>
  1. The citation number may contain numbers and letters.
  2. The month is an integer between 1 (January) and 12 (December).
  3. The day and year are integers.
  4. The clocked speed is an integer in miles per hour.
  5. The speed limit is an integer in miles per hour.
  6. The type of road is a single character: I or i (Interstate), R or r (Residential), H or h (Highway).

Output File Format

Your output file format will be:

<day>-<3-character Month>-<Year> <citation> $<fine>
  1. The day must be exactly two digits. If the day is 1 - 9, it must be 01 - 09.
  2. The 3-character month must be the three-character month: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, or Dec.
  3. The year is simply a 2 or 4 digit year. If the year is only two digits, assume the 21st century. For example, year 10 will be the year 2010.
  4. The citation is exactly the citation given in the input file, but it will be in a left justified field, 10 characters wide.
  5. The $ must follow the citation field.
  6. The fine will be a dollar amount in a right justified field, 9 characters wide.
  7. You will only output those citations that occur between the given report start date and end dates (inclusively).
  8. You must use your Encode function to handle the dates.

Restrictions / Hints

  1. You must use I/O manipulators to force the day to be exactly two digits.
  2. You must use I/O manipulators to set the fine to two decimal points.
  3. You must use global constants for the fine multiplier.
  4. Store all months, such as Jan, Feb, Mar, in a global, constant, 12-element array of strings.
  5. You must use I/O manipulators to set the field justifications (right and/or left).
  6. The minimum fine is $0.00. If you calculate a negative fine, you must round it up to exactly $0.00.
  7. You must use your standalone functions and all member functions when writing these labs. You are simulating writing an API for other programmers to use your class and/or functions to generate a report.
  8. Do NOT hardcode any extensions or file names. Read the filename directly from the command line, regardless of whether it contains the extension you think it should or not.
  9. All classes, structures, and prototypes must be declared ABOVE int main. All definitions must be written BELOW int main.
  10. Do not attempt to write to any file if the user gives you a dash "-" for the output file name.

Example

Valid input example:

./lab11 ticket.input 2017-7-3 2017-12-27 output.file

ticket.input file contains:

E059564 8 12 2018 89 55 i
E515522 7 3 2017 105 50 r
E712221 6 4 2015 200 25 h
E219221 12 25 17 2000 10 p

output.file contains:

03-Jul-2017 E515522    $   943.39
25-Dec-2017 E219221    $ 24182.48

Invalid files:

./lab11 ticket.idontexist 2017-7-3 2017-12-27 output.file
The file 'ticket.idontexist' cannot be read.

Output to console:

./lab11 ticket.input 2017-7-3 2017-12-27 -
03-Jul-2017 E515522    $   943.39
25-Dec-2017 E219221    $ 24182.48

Not enough arguments:

./lab11 ticket.input
Usage: ./lab11 <input file> <start: year-month-day> <end: year-month-day> <output or '-'>

Submission

Compile your code using the following

g++ -Wall -O0 -g -std=c++11 -o lab lab.cpp
0 0
Add a comment Improve this question Transcribed image text
Answer #1

sat Giien Wet tt include <stalib.h> int off endn Sead t (voia); chan aff enen school 2ra nput Cvoid); float compute schol 군onir& Speed :0; printf (und 요 afronden, speed ?); mtley over tue Spest Snuit en tomen uatan milesoven snt gaaton tan 20 Tflt3 prir&f (The offendns SpeeQ was Y. d and the speed Part f (mhe offender oill be changed $ .4 xchange);

Add a comment
Know the answer?
Add Answer to:
Assignment You will be developing a speeding ticket fee calculator. This program will ask for a t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The assignment : Assignment You will be developing a speeding ticket fee calculator. This program will...

    The assignment : Assignment You will be developing a speeding ticket fee calculator. This program will ask for a ticket file, which is produced by a central police database, and your program will output to a file. Furthermore, your program will restrict the output to the starting and ending dates given by the user. The ticket fee is calculated using four multipliers, depending on the type of road the ticket was issued: Interstate multiplier: 5.2252 Highway multiplier: 9.4412 Residential multiplier:...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

  • For this lab, you can assume that no string entered by the user will be longer...

    For this lab, you can assume that no string entered by the user will be longer than 128 characters. You can also assume that the database file does not contain more than 128 lines. However, you can not assume that the database has the correct format. There are three commands your program must handle. If any other command is entered, the program should reply Unrecognized command. and then present the prompt again. The three commands are: quit - The program...

  • C++ Functions & Streams Write a program that will demonstrate some of the C++ Library Functions,...

    C++ Functions & Streams Write a program that will demonstrate some of the C++ Library Functions, Stream Manipulators, and Selection Control Structures. The user will be given a menu of four choices. They can input a 1 for finding Cosines, 2 for finding Logarithms, 3 for converting between Decimal and Hexadecimal, or 4 to change the format of a cstring date. You must use the proper functions and/or stream manipulators to find the answers. If the user picks the cosine,...

  • in c++ please HW09: Read/Write File Ints Now that we've had a taste of what file...

    in c++ please HW09: Read/Write File Ints Now that we've had a taste of what file I/O is all about, here's your chance to try it out on your own! You're to write a program that will prompt the user if he/she would like to read ints from a file (and have them displayed to stdout) or write ints to a file for safekeeping. If the user wishes to save a set of numbers, then the file nums.txt is opened...

  • With your partner, brainstorm a program that will ask the user for a number of digits...

    With your partner, brainstorm a program that will ask the user for a number of digits to be stored. The program should then create an array of that size and then prompt the user for numbers to fill each position in the array. When all of the positions are filled, display the contents of the array to the user. Create a new Project named FillArray and a new class in the default packaged named FillArray.java. You and your partner should...

  • c++ The program will be recieved from the user as input name of an input file...

    c++ The program will be recieved from the user as input name of an input file and and output.file. then read in a list of name, id# and score from input file (inputFile.txt) and initilized the array of struct. find the student with the higher score and output the students info in the output file obtain the sum of all score and output the resurl in output file. prompt the user for a name to search for, when it find...

  • In this assignment, you will write one (1) medium size C program. The program needs to...

    In this assignment, you will write one (1) medium size C program. The program needs to be structured using multiple functions, i.e., you are required to organize your code into distinct logical units. The following set of instructions provide the specific requirements for the program. Make sure to test thoroughly before submitting. Write   a   program,   named   program1.c,   that   reads   and   processes   employee   records   (data   about   an   employee).   Each   employee   record   must   be   stored   using   a   struct   that   contains   the   following  ...

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

  • Using FLA arrays For this exercise, I want you to read 20 integer numbers from a...

    Using FLA arrays For this exercise, I want you to read 20 integer numbers from a given data file and average them. You must use an array and 2 functions. The first function will load an array with the data from the input file. The second function will average the data in the file. FILE* and the naming and location (path) of the text file for input. The mode of the user defined file stream. The function declaration. Ensure you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT