Question

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

Console User Interaction

You must ask the user on the console for an input ticket file, an output report file, a report starting date, and a report ending date. The following prompts must be used:

"Enter a ticket file: "
"Enter a report file: "
"Enter report start date (mm dd yyyy): "
"Enter report end date   (mm dd yyyy): "

Input File Format

Each line will contain the following information:

 

The citation number may contain numbers and letters.

The month is an integer between 1 (January) and 12 (December).

The day and year are integers.

The clocked speed is an integer in miles per hour.

The speed limit is an integer in miles per hour.

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:

-<3-character Month>-  $

The day must be exactly two digits. If the day is 1 - 9, it must be 01 - 09.

The 3-character month must be the three-character month: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, or Dec.

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.

The citation is exactly the citation given in the input file, but it will be in a left justified field, 10 characters wide.

The $ must follow the citation field.

The fine will be a dollar amount in a right justified field, 9 characters wide.

You will only output those citations that occur between the given report start date and end dates (inclusively).

Restrictions / Hints

You must use I/O manipulators to force the day to be exactly two digits.

You must use I/O manipulators to set the fine to two decimal points.

You must use a constant ARRAY to store (and determine) the 3-character month.

You must use constants for the fine multiplier.

You must use a switch statement to apply the fine multiplier.

You must use I/O manipulators to set the field justifications (right and/or left).

The minimum fine is $0.00. If you calculate a negative fine, you must round it up to exactly $0.00.

Example

Valid input example:

./lab6
Enter a ticket file: ticket
Enter a report file: output
Enter report start date (mm dd yyyy): 7 1 2017
Enter report end date   (mm dd yyyy): 8 11 2018

ticket 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

Missing file example:

./lab6 
Enter a ticket file: somebadfilename
Unable to open somebadfilename.

Can someone look at my code and fix my code to where it matches the output file in the assignment because my output file is only outputting the first part but it's not right and the second part is not outputting at all!!! DO NOT USE ANY BOOL STATEMENTS ONLY IF AND ELSE!!

My code:

#include

#include

#include

#include

using namespace std;

int main(){

string month_char[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

const double interstate = 5.2252;

const double highway = 9.4412;

const double residential = 17.1525;

const double non = 12.152;

int month1,day1,year1;

int month2,day2,year2;

ifstream input_f;

ofstream output_f;

char ticket[20];

char report[20];

string citationnum;

int month;

int day;

int year;

int clockedspeed;

int speedlimit;

char typeroad;

int checkdate;

int startdate;

int enddate;

cout <<"Enter a ticket file: ";

cin >>ticket;

input_f.open(ticket);

if (input_f.is_open()){

input_f.close();

cout << "Enter a report file: ";

cin >>report;

output_f.open(report);

cout <<"Enter report start date (mm dd yyyy): ";

cin >>month1>>day1>>year1;

cout <<"Enter report end date (mm dd yyyy): ";

cin>>month2>>day2>>year2;

input_f.open(ticket);

while (input_f>>citationnum>>month>>day>>year>>clockedspeed>>speedlimit>>typeroad){

checkdate= (year*10000)+(month*100)+day;

startdate =(year1 *10000)+(month1 * 100)+day1;

enddate=(year2*10000)+(month2*100)+day2;

if ((year<100)&&(year<900)){

year= 2000+year;

}

if(checkdate>=startdate&&checkdate<=enddate) {

output_f<

if (day>=1&&day<=9){

output_f<

}

output_f<

output_f<

output_f<

output_f<

output_f<<"$";

double fine=0.00;

switch(typeroad){

case 'i':

case 'I':

fine= (clockedspeed-speedlimit)*interstate;

break;

case 'r':

case 'R':

fine = (clockedspeed-speedlimit)*residential;

break;

case 'h':

case 'H':

fine = (clockedspeed-speedlimit)*highway;

break;

default:

fine =(clockedspeed-speedlimit)*non;

break;

}

if (fine<0)

fine=0;

output_f<

output_f<

output_f<

output_f<

output_f<

cout<

}

}

}

else{

cout <<"unable to open";

}

return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM:

#include <iostream>
#include <string>
#include<stdlib.h>
#include<fstream>
#include<iomanip>
using namespace std;


//function for checking whether the given year is a four digit else it is a two digit number
bool is_four_digit(int year){
   if(year>999 && year<=9999)return true;
   else return false;
}


//to check whether given date is between start report date and end report date
// it can be done using following formula
// (year * 10000) + (month * 100) + day
// the date 22/10/2014 (day/month/year) becomes 20141022 do it for the start date, end date and the date you want to compare and compare them

bool is_date_in_the_given_range(int day, int month, int year, int dd1, int mm1, int yyyy1, int dd2, int mm2, int yyyy2){
    int to_check_date = (year * 10000) + (month * 100) + day;
    int start_date = (yyyy1 * 10000) + (mm1 * 100) + dd1;
    int end_date = (yyyy2 * 10000) + (mm2 * 100) + dd2;

    if (to_check_date >= start_date && to_check_date <= end_date){
        return true;
    }
    else{
        return false;
    }
}

int main(){

   //month array 3 character month name
   string month_3_character[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

   //constant for different fine amount based on type
   const double interstat = 5.2252;
   const double highway = 9.4412;
   const double residential = 17.1525;
   const double non = 12.152;

   //file stream for reading the input file
   ifstream input_file;
   char ticket[20];
   cout<<"Enter a ticket file:";
   cin>>ticket;
   input_file.open(ticket);  

   //file stream for output the file
   ofstream output_file;

   if(input_file.is_open()){
        input_file.close();
        char report[20];
        cout<<"Enter a report file:";
        cin>>report;

         output_file.open(report);

        cout<<"Enter report start date (mm dd yyyy):";
        int mm1,dd1,yyyy1;
        cin>>mm1>>dd1>>yyyy1;

        cout<<"Enter report end date   (mm dd yyyy):";
           int mm2,dd2,yyyy2;
        cin>>mm2>>dd2>>yyyy2;

        string citation_number;
        int month,day,year,clocked_speed,speed_limit;
        char type_of_road;

        input_file.open(ticket);

        while(input_file>>citation_number>>month>>day>>year>>clocked_speed>>speed_limit>>type_of_road){
            //check the no of digits in year
            //if 4 digit then its ok otherwise we have to make it preceded by 21st century
            if(!is_four_digit(year)){
               //if year = 10 then after below line it became 2010
               year = 2000+year;
            }

            if(is_date_in_the_given_range(day,month,year,dd1,mm1,yyyy1,dd2,mm2,yyyy2)){
             
               //set width for day 2 digit
               output_file.width(2);
               //if(digit is 1 digit use 0 befor date)
               if(day>=1 && day<=9)
               output_file<<setfill('0')<<day<<"-";
               else output_file<<day<<"-";

               //output month
               output_file<<month_3_character[month-1]<<"-";

               //output year
               output_file<<year<<" ";

               //output citation no
               output_file.width(10);
               output_file<<setfill(' ')<<citation_number<<" ";

               output_file<<"$";
             
               double fine_amount =0.00;

               //calculate fine amount based on different road type
               if(type_of_road=='I' || type_of_road=='i')fine_amount = (clocked_speed-speed_limit)*interstat;
               else if(type_of_road=='R' || type_of_road=='r')fine_amount = (clocked_speed-speed_limit)*residential;
               else if(type_of_road=='H' || type_of_road=='h')fine_amount = (clocked_speed-speed_limit)*highway;
               else fine_amount = (clocked_speed-speed_limit)*non;
             
               // if fine is negative set fine amount to 0
               if(fine_amount<0)fine_amount=0;
              

               //output fine amount
               output_file.width(9);
               output_file<<::std::fixed;
               output_file << std::right;
               output_file<<std::setprecision(2);
               output_file<<fine_amount<<"\n";

            }

         }
      }
   else{
         cout<<"Unable to open somebadfilename.\n";
   }


   return 0;
}

Add a comment
Know the answer?
Add Answer to:
The assignment : Assignment You will be developing a speeding ticket fee calculator. This program will...
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
  • 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...

  • -can you change the program that I attached to make 3 file songmain.cpp , song.cpp ,...

    -can you change the program that I attached to make 3 file songmain.cpp , song.cpp , and song.h -I attached my program and the example out put. -Must use Cstring not string -Use strcpy - use strcpy when you use Cstring: instead of this->name=name .... use strcpy ( this->name, name) - the readdata, printalltasks, printtasksindaterange, complitetasks, addtasks must be in the Taskmain.cpp - I also attached some requirements below as a picture #include <iostream> #include <iomanip> #include <cstring> #include <fstream>...

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

  • // Enter your name as a comment for program identification // Program assignment testEmployeeAB.cpp // Enter...

    // Enter your name as a comment for program identification // Program assignment testEmployeeAB.cpp // Enter your class section, and time /* The program testEmployeeAB.cpp tests the class Employee. The class Date is included so that the Employee class can use the Date data type. */ /* Data is entered to create an employee data file. */ /* A payroll report and equal employment opportunity report showing ethnicity data is displayed. */ //header files /* use the correct preprocessor directives...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • 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,...

  • C++ Project Modify the Date Class: Standards Your program must start with comments giving your name...

    C++ Project Modify the Date Class: Standards Your program must start with comments giving your name and the name of the assignment. Your program must use good variable names. All input must have a good prompt so that the user knows what to enter. All output must clearly describe what is output. Using the date class, make the following modifications: Make the thanksgiving function you wrote for project 1 into a method of the Date class. It receive the current...

  • n this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A...

    n this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A test driver for testing the class defined in the other 2 files. You can name your file in the way you like. Remember it must be a .cpp file. In DateType.h file, type these lines: // To declare a class for the Date ADT // This is the header file DateType.h class DateType { public: void Initialize(int newMonth, int newDay, int newYear); int GetYear()...

  • Need help writing beginner C# program, I will make sure to provide feedback to whoever can...

    Need help writing beginner C# program, I will make sure to provide feedback to whoever can help me figure it out! No public or global variables should be used. You need to consider passing arguments between the methods according to the ways described in the lecture. i.e. all variables should be declared inside the methods and passed to other methods by value/ref/out as needed Description: We want to design a Date class to represent a date using three integer numbers...

  • This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a fun...

    This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...

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