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>
Output File Format
Your output file format will be:
<day>-<3-character Month>-<Year> <citation> $<fine>
Restrictions / Hints
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
Assignment You will be developing a speeding ticket fee calculator. This program will ask for a t...
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 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 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, 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 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 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 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 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 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 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...