Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I NEED THIS IN C, NOT C++, ALSO PLEASE DONT USE POINTERS OR MALLOC FUNCTIONS In

ID: 3834754 • Letter: I

Question

I NEED THIS IN C, NOT C++, ALSO PLEASE DONT USE POINTERS OR MALLOC FUNCTIONS

In this assignment you will write a data maintenance program for the Police Traffic Dept. in the town of SUD.

The police department wants to have a program that keeps track of illegal driving actions. Theses actions include general parking tickets, speeding ticket, and being charged for drinking and driving. The information is kept in a file called “actions.txt” where the first field is the license number (8 digit of type long), the second field refers to the number of parking tickets, the third field is the number of speed tickets and the last field is the number of times the car has been stopped for drinking and driving violence. A sample of such a file is shown below:

102241

10

3

1

102242

4

0

0

992943

20

7

2

992944

8

2

0

The data should be stored in four parallel arrays for processing. The entries in the arrays correspond to one another. For example, this record shows the driver with the plate number 102242 has been a fairly good driver because it only has 4 parking ticket, and has no record of speed or drunk driving. However, the driver with the plate number 992943 is not a good driver because it has 20 parking tickets, 7 speed tickets and has been cut twice for drunk driving.

When you start your program, you need to initialize the four arrays with the data of the below table .The name of arrays are: Plates, ParkingTicket, SpeedTicket, and DrunkTicket, respectively. The first column of the Table is the data for the Plates array, the second column of the Table is the data for the ParkingTicket array and so on.

After reading the data read into array, you will prompt the user on the screen to enter commands (single characters). Your interface should look like this:

                                           P:           Adding a parking ticket

                                           S:           Adding a speed ticket

                                           D:          Adding a drunk driving ticket

                                           R:           Print history of a particular car

                                           A:          Print history of all cars

                                           Q:          Quit the program

                                           -------------------------------------------------

                                           Enter a Command:

If the user enter P (capital P and Small p should be accepted), your program should ask the user for a plate number. This plate number should be searched and the corresponding value of the parking tickets in ParkingTicket array should be incremented. For example if the user enters, 992943, your program should find out that the person with the plate number 992943 has already 20 parking tickets and should increment it by one to become 21.

Similarly if the user picks S option in the menu, the program should ask the user for the plate number and add one to the corresponding speed ticket. For example, if the plate number entered is 102241, you need to ensure that the speed ticket in SpeedTicket Array for this plate number is changed to 4.

Option D words as option P and S.

Option Q should quit your program

If the user chooses option R (or r), your program again asks for the plate number from the user and prints the associated history on the screen. For example, if the user enters 992944, your program should print:

The plate number is:                        992944

Number of parking tickets:              8

Number of speed tickets:                 2

Number of drunk driving:               0

If the user chooses option A (or a), your program should print all the information in a table format on the screen as follow (you need to enter the following information into your arrays)

Plate                     No of                                 No of                                  No of

Number                Parking                               Speeding                            Drinking

------------------------------------------------------------------------------------------------

102241                 10                                       3                                         1

102242                 4                                         0                                         0

992943                 20                                       7                                         2

992944                 8                                         2                                         0

112200                 10                                       3                                         1

112201                 4                                         0                                         0

112202                 20                                       7                                         1

102203                 2                                         3                                         2

102204                 5                                         3                                         2

102205                 10                                       3                                         1

102206                 11                                       2                                         1

102207                 22                                       8                                         3

102208                 0                                         0                                         0

102209                 0                                         0                                         0

102210                 1                                         3                                         1

102211                 2                                         2                                         0

102212                 4                                         2                                         1

102213                 6                                         2                                         0

102214                 8                                         1                                         0

102215                 9                                         1                                         0

102216                 21                                       2                                         0

102217                 13                                       2                                         0

102218                 4                                         1                                         0

102219                 4                                         1                                         0

102220                 34                                       22                                       4

Testing your program

Add a parking ticket for plate number 102207

Print history of record 102207 on the screen

Add a parking ticket for plate number 102219

Print history of record 102219 on the screen

Add a parking ticket for plate number 102221

In this case, your program should print a message that plate 102221 cannot be found and asks the user to re-enter the plate number again

Add a speed ticket for plate number 102200

Print history of record 102200 on the screen

Add a parking ticket for plate number 102205

Print history of record 102205 on the screen

Add a parking ticket for plate number 102119

In this case, your program should print a message that plate 102119 cannot be found and asks the user to re-enter the plate number again

Add a drunken driving ticket for plate number 102201

Print history of record 102201 on the screen

Add a drunken driving ticket for plate number 102203

Print history of record 102203 on the screen

Add a drunken driving ticket for plate number 112204

In this case, your program should print a message that plate 112204 cannot be found and asks the user to re-enter the plate number again

Choose option A to print the information of all plates on the screen.

Quit the program

102241

10

3

1

102242

4

0

0

992943

20

7

2

992944

8

2

0

Explanation / Answer

#include <stdio.h>

#define SIZE 24

int get_plate_no() {

int plate_no;

printf("Ener plate number: ");

scanf("%d", &plate_no);

return plate_no;

}

void add_parking_tkt(int plate_no[], int parking_tkt[]) {

int pno, i;

pno = get_plate_no();

for(i = 0; i < SIZE; i++) {

if( plate_no[i] == pno ) {

parking_tkt[i]++;

printf(" Parking ticket added. ");

break;

}

}

if( i == SIZE )

printf(" Plate number not found! ");

}

void add_speed_tkt(int plate_no[], int speed_tkt[]) {

int pno, i;

pno = get_plate_no();

for(i = 0; i < SIZE; i++) {

if( plate_no[i] == pno ) {

speed_tkt[i]++;

printf(" Speed ticket added. ");

break;

}

}

if( i == SIZE )

printf(" Plate number not found! ");

}

void add_drunk_tkt(int plate_no[], int drunk_tkt[]) {

int pno, i;

pno = get_plate_no();

for(i = 0; i < SIZE; i++) {

if( plate_no[i] == pno ) {

drunk_tkt[i]++;

printf(" Drunk ticket added. ");

break;

}

}

if( i == SIZE )

printf(" Plate number not found! ");

}

void show_history(int plate_no[], int parking_tkt[], int speed_tkt[], int drunk_tkt[]) {

int pno, i;

pno = get_plate_no();

for(i = 0; i < SIZE; i++) {

if( plate_no[i] == pno ) {

printf(" The plate number is: %d ", plate_no[i]);

printf("No of parking tickets: %d ", parking_tkt[i]);

printf("No of speed tickets: %d ", speed_tkt[i]);

printf("No of drunk driving: %d ", drunk_tkt[i]);

break;

}

}

if( i == SIZE )

printf(" Plate number not found! ");

}

void show_all_history(int plate_no[], int parking_tkt[], int speed_tkt[], int drunk_tkt[]) {

int i;

printf(" Plate No of No of No of ");

printf("Number Parking Speeding Drinking ");

printf("------------------------------------- ");

for(i = 0; i < SIZE; i++) {

printf("%6d ", plate_no[i]);

printf("%7d ", parking_tkt[i]);

printf("%8d ", speed_tkt[i]);

printf("%8d ", drunk_tkt[i]);

}

}

int main() {

int plate_no[SIZE], parking_tkt[SIZE], speed_tkt[SIZE], drunk_tkt[SIZE];

int i;

char choice = 'a';

// to take input for plate no, parking_tkt, speed_tkt and drunk_tkt

for(i = 0; i < SIZE; i++) {

scanf("%d %d %d %d", &plate_no[i], &parking_tkt[i], &speed_tkt[i], &drunk_tkt[i]);

}

  

while(choice != 'q' || choice != 'Q') {

getchar();

printf(" P: Adding a parking ticket ");

printf("S: Adding a speed ticke ");

printf("D: Adding a drunk driving ticket ");

printf("R: Print history of a particular car ");

printf("A: Print history of all cars ");

printf("Q: Quit the program ");

printf("-------------------------------------------------- ");

printf("Enter a command: ");

scanf("%c", &choice);

  

if( choice == 'p' || choice == 'P' )

add_parking_tkt(plate_no, parking_tkt);

else if( choice == 's' || choice == 'S' )

add_speed_tkt(plate_no, speed_tkt);

else if( choice == 'd' || choice == 'D' )

add_drunk_tkt(plate_no, drunk_tkt);

else if( choice == 'r' || choice == 'R' )

show_history(plate_no, parking_tkt, speed_tkt, drunk_tkt);

else if( choice == 'a' || choice == 'A' )

show_all_history(plate_no, parking_tkt, speed_tkt, drunk_tkt);

else if( choice == 'q' || choice == 'Q' )

break;

else

printf("Invalid choice! Try again. ");

}

return 0;

}