How to solve this problem? I'm getting tired thinking abou this. Help me.

Write a C++ program to help the master reporter of a traffic centre to analyse the amount of traffic coming from all the different entry points to a city. The amount of traffic for each entry point is saved in the file traffic.dat in the following format:

Field Name Format
Entry Number Alphanumeric 4 characters
Time Period Alphabet, 2 characters maximum, i.e.
MP-Morning Peak,
MO-Morning Off Peak,
A-Afternoon,
AP-Afternoon Peak,
E-Evening, or
EM-Early Morning (6 times period altogether)
Number of Car Numeric
Number of Motorbike Numeric
Number of Van Numeric
Number of Heavy Vehicle Numeric

Assume a sample entry in the traffic.txt for the centre is as follows:

N101 MP 500 800 300 50

N102 MP 600 800 200 20

N103 MP 700 900 300 100

P101 MP 800 900 250 50

P102 MP 700 850 200 30

N101 MO 200 300 300 150

N102 MO 200 200 300 120

N103 MO 200 280 400 180

P101 MO 200 300 350 150

P102 MO 200 350 400 130

N101 E 300 600 300 90

N102 E 400 500 200 40

N103 E 500 550 300 50

P101 E 500 450 250 20

P102 E 400 480 200 50

where the first entry means the data is from Entry with code ‘N101’ for ‘Morning Peak’ Hours, and the volume of traffic are 500 cars, 800 motorbikes, 300 vans and 50 heavy vehicles.

The program should analyse the data for each entry, as well as produce subtotal and grand total for all types of vehicles for each time period. For the peak hours, the flag * should be printed under the Flag column if the number of heavy vehicles is > 5% of the total traffic, and the flag& should be printed if the number of motorbikes is > 45% of the total traffic for that Entry. For other periods, the flag ** should be printed under the Flag column if the number of heavy vehicles is > 15% of the total traffic, and the flag && should be printed if the number of motorbikes is > 40% of the total traffic. The program should produce output similar to what is shown below for the traffic data shown above.

For this example, the data shown are for three different time periods only. However, the program should handle all the six different periods as given in the specification given. You may assume that the volume of traffic is below 1000 vehicles for each of the column. The output should be saved into the output text file traffic_out.txt besides being displayed on the user’s screen.

Recommended Answers

All 2 Replies

We don't do homework.

...but we can help point you in the right direction.

Have you written any code yet? If you have, please post it and try to identify a specific problem you're having.

If not, here's a place to start: You'll need to read that data file into something. What kind of data structures do you think you might want for that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.