Question

Your customer needs an automated system to patrol the highways. The job of the system is to collect the following information

module/function before attempting your code on the computer. Be sure the follow the user- interface as specified. Extra Credi

just the extra credit part please

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>


int total=0, charged=0, fare=0;

void calculation(char *s, int diff)               //function which performs calculation part
{
       if(diff>50)                                         // if mph exceeds speed limit by 50
       {
          cout<<"a ticket of $1000 is issued to "<<s<<endl;
          charged++;                                  // counting the number of charged vehicles
          fare=fare+1000;                           // charged $1000 and we add it to total amount charged
       }else if(diff>20)
       {
                
           int ticket=150+10*diff;                // applying formula, base=$150, fee=$10
           cout<<"a ticket of $"<<ticket<<" is issued to "<<s<<endl;
           charged++;                                //counting the number of charged vehicles
           fare=fare+ticket;                        // storing the ticket charge to total amount charged
       }else if(diff>=5)
       { 
           int ticket=150+5*diff;                //applying formula, base=$150, fee=$5
           cout<<"a ticket of $"<<ticket<<" is issued to "<<s<<endl;
           charged++;                              // counting number of charged vehicles
           fare=fare+ticket;                      // add ticket charge to total amout charged
       }else
       {
           cout<<"no ticket is issued to "<<s<<endl;  // if no amount charged
       }
}

void display()        // function which display the overall result about total vehicles charges, percentage
{
       cout<<"tickets were given to "<<charged<<" out of "<<total<<" vehicles"<<endl;
       cout<<"percentage of ticketed vehicles: "<<charged*100/total<<endl;
       cout<<"average ticket amount: "<<fare/charged<<endl;
       cout<<"thankyou for using our AHP program"<<endl;
}


int main()
{
        char lno[50];
        char e[5]="QUIT"; 
        int csp,sl;
    clrscr();
        while(1)
        {

            // lno is a character array variable. csp and sl are integer variable
            cout<<"Enter license plate number: ";
            cin>>lno;
            if(strcmp(lno,e)==0) break;  //break the while loop if license number gets QUIT
            cout<<"Enter current vehicle speed: ";
            cin>>csp;
            cout<<"Enter speed limit: ";
            cin>>sl;
            int diff=csp-sl;                      // calculating the difference between mph and speed limit
            cout<<"vehicle travelled "<<diff<<" miles over the speed limit"<<endl;
            calculation(lno, diff);
            total++;                //counting total vehicles
        }
        display();
    getch();
        return 0;
}

Please have a look on the C++ code above, although i have explained complete logic using java and pseudo code.

This is a good question, lets analyze the conditions in the given question:

The ticket will only be issued if the speed (miles/hrs) exceeds the speed limit by atleast 5 mph.

We also know that ticket prices are calculated on the following formula.

Ticket Price = Base+Fee*<number of mph over the speed limit>

Base is always $150, and Fee depends on the number of mph over the speed limit

No fee charges if mph over the speed limit is less than 5mph.

Fee charges per mph is $5 if mph over the speed limit not more than 20mph

Fee charges per mph is $10 if mph over the speed limit lies between 20mph and 50mph

However an additional $1000 charged, if number of mph exceeds speed limit more than 50mph.

Now lets analyze the pseudocode and understand it with java program.

import java.util.Scanner;    //importing Scanner class for taking input
class Ticket                  //name of class is ticket
{
    int total=0, charged=0, fare=0;            //variable used for counting total,charged vehicles and total amount                                                                              //charged
    public static void calculation(String s, int diff)               //function which performs calculation part
    {
        if(diff>50)                                         // if mph exceeds speed limit by 50
        {
            System.out.println("a ticket of $1000 is issued to "+s);
            charged++;                                  // counting the number of charged vehicles
            fare=fare+1000;                           // charged $1000 and we add it to total amount charged
        }else if(diff>20)
        {
            int ticket=150+10*diff;                // applying formula, base=$150, fee=$10
            System.out.println("a ticket of $"+ticket+" is issued to "+s);
            charged++;                                //counting the number of charged vehicles
            fare=fare+ticket;                        // storing the ticket charge to total amount charged
        }else if(diff>=5)
        { 
            int ticket=150+5*diff;                //applying formula, base=$150, fee=$5
            System.out.println("a ticket of $"+ticket+" is issued to "+s);
            charged++;                              // counting number of charged vehicles
            fare=fare+ticket;                      // add ticket charge to total amout charged
        }else
        {
            System.out.println("no ticket is issued to "+s);  // if no amount charged
        }
    }
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        String lno; int csp,sl;
        //taking input
        while(true)
        {

            // lno is a string variable. csp and sl are integer variable
            System.out.println("Enter license plate number: ");
            lno=sc.nextLine();
            if(lno=="QUIT") break;  //break the while loop if license number gets QUIT
            System.out.println("Enter current vehicle speed: ");
            csp=sc.nextInt();
            System.out.println("Enter speed limit: ");
            sl=sc.nextInt();
            int diff=csp-sl;                      // calculating the difference between mph and speed limit
            System.out.println("vehicle travelled "+diff+" miles over the speed limit");
            calculation(lno, diff);
            total++;                //counting total vehicles
        }
        display();
    }
    public static void display()        // function which display the overall result about total vehicles charges, percentage
    {
        System.out.println("tickets were given to "+charged+" out of "+total+" vehicles);
        System.out.println("percentage of ticketed vehicles: "+charged*100/total);
        System.out.println("average ticket amount: "+fare/charged);
        System.out.println("thankyou for using our AHP program");
    }
    
}
Add a comment
Know the answer?
Add Answer to:
just the extra credit part please Your customer needs an automated system to patrol the highways....
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:...

  • in java PART ONE ================================================== Write a program that will read employee earnings data from an...

    in java PART ONE ================================================== Write a program that will read employee earnings data from an external file and then sort and display that data. Copy and paste the input file data below into an external file, which your program will then read. You will want to use parallel arrays for this program. Modify the select sort algorithm to receive both arrays as parameters as well as the size of the arrays. Use the algorithm to sort your earnings array....

  • Janice Morgan, age 24, is single and has no dependents. She is a freelance writer. In...

    Janice Morgan, age 24, is single and has no dependents. She is a freelance writer. In January 2018, Janice opened her own office located at 2751 Waldham Road, Pleasant Hill, NM 88135. She called her business Writers Anonymous. Janice is a cash basis taxpayer. She lives at 132 Stone Avenue, Pleasant Hill, NM 88135. Her Social Security number is 123-45-6789. Janice’s parents continue to provide health insurance for her under their policy. Janice wants to contribute to the Presidential Election...

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