Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define SIZE 12
- extern int Pedestrian[];
- extern int MotorCyclist[];
- extern int MotorCar[];
- extern int LightTruck[];
- extern int Truck[];
- void showMenu(void)
- {
- printf("Please choose one of the following options\n");
- printf("A: Total number of injuries of a selected road user.\nB: Difference between Motor Cyclists injuries and combined injuries of Motor Car, Light truck and Truck.\nC: Percentage of road users' injuries for a selected month.\nD: Difference of road users' injuries between consecutive months for a selected road user type.\nE: Lowest monthly total number of injuries from Jan to Dec.\nF: Highest to lowest number of injuries for a selected road user type.\nQ: Quit the programme\n\n");
- }
- void function1(void)
- {
- int j, total, choice;
- total = 0;
- j = 0;
- {
- printf("Select a Road User\n");
- printf("1)Pedestrian\n2)Motor Cyclists\n3)Motor Car\n4)Light Truck\n5)Truck\n");
- scanf_s(" %d", &choice);
- if (choice == 1)
- {
- for (j = 0; j < 12; j++)
- total += Pedestrian[j];
- printf("The total number of injuries for Pedestrian is %d\n\n", total);
- }
- else if (choice == 2)
- {
- for (j = 0; j < 12; j++)
- total += MotorCyclist[j];
- printf("The total number of injuries for Motor Cyclists is %d\n\n", total);
- }
- else if (choice == 3)
- {
- for (j = 0; j < 12; j++)
- total += MotorCar[j];
- printf("The total number of injuries for Motor Car is %d\n\n", total);
- }
- else if (choice == 4)
- {
- for (j = 0; j < 12; j++)
- total += LightTruck[j];
- printf("The total number of injuries for Light Truck is %d\n\n", total);
- }
- else if (choice == 5)
- {
- for (j = 0; j < 12; j++)
- total += Truck[j];
- printf("The total number of injuries for Truck is %d\n\n", total);
- }
- else
- {
- printf("Invalid, try again\n\n");
- }
- }
- }
- void function2(void)
- {
- int j, difference;
- j = 0;
- difference = 0;
- {
- for (j = 0; j < 12; j++)
- difference += MotorCyclist[j] - (MotorCar[j] + LightTruck[j] + Truck[j]);
- printf("The difference between MotorCyclists injuries and combined injuries of Motor Car, Light Truck and Truck is %d\n\n", difference);
- }
- }
- void function3(void)
- {
- int j, choice, total;
- float percentage;
- total = 0;
- j = 0;
- percentage = 0.0;
- {
- printf("Select a month\n");
- printf("1)Jan\n2)Feb\n3)Mar\n4)Apr\n5)May\n6)Jun\n7)Jul\n8)Aug\n9)Sep\n10)Oct\n11)Nov\n12)Dec\n");
- scanf_s(" %d", &choice);
- if (choice == 1)
- {
- for (j = 0; j < 12; j++)
- total = total + Pedestrian[j] + MotorCyclist[j] + MotorCar[j] + LightTruck[j] + Truck[j];
- percentage = (percentage + Pedestrian[0] + MotorCyclist[0] + MotorCar[0] + LightTruck[0] + Truck[0]) / total * 100;
- printf("The percentage of road users' injuries in January is %.2f%%\n", percentage);
- }
- else if (choice == 2)
- {
- for (j = 0; j < 12; j++)
- total = total + Pedestrian[j] + MotorCyclist[j] + MotorCar[j] + LightTruck[j] + Truck[j];
- percentage = (percentage + Pedestrian[1] + MotorCyclist[1] + MotorCar[1] + LightTruck[1] + Truck[1]) / total * 100;
- printf("The percentage of road users' injuries in February is %.2f%%\n", percentage);
- }
- else if (choice == 3)
- {
- for (j = 0; j < 12; j++)
- total = total + Pedestrian[j] + MotorCyclist[j] + MotorCar[j] + LightTruck[j] + Truck[j];
- percentage = (percentage + Pedestrian[2] + MotorCyclist[2] + MotorCar[2] + LightTruck[2] + Truck[2]) / total * 100;
- printf("The percentage of road users' injuries in March is %.2f%%\n", percentage);
- }
- else if (choice == 4)
- {
- for (j = 0; j < 12; j++)
- total = total + Pedestrian[j] + MotorCyclist[j] + MotorCar[j] + LightTruck[j] + Truck[j];
- percentage = (percentage + Pedestrian[3] + MotorCyclist[3] + MotorCar[3] + LightTruck[3] + Truck[3]) / total * 100;
- printf("The percentage of road users' injuries in April is %.2f%%\n", percentage);
- }
- else if (choice == 5)
- {
- for (j = 0; j < 12; j++)
- total = total + Pedestrian[j] + MotorCyclist[j] + MotorCar[j] + LightTruck[j] + Truck[j];
- percentage = (percentage + Pedestrian[4] + MotorCyclist[4] + MotorCar[4] + LightTruck[4] + Truck[4]) / total * 100;
- printf("The percentage of road users' injuries in May is %.2f%%\n", percentage);
- }
- else if (choice == 6)
- {
- for (j = 0; j < 12; j++)
- total = total + Pedestrian[j] + MotorCyclist[j] + MotorCar[j] + LightTruck[j] + Truck[j];
- percentage = (percentage + Pedestrian[5] + MotorCyclist[5] + MotorCar[5] + LightTruck[5] + Truck[5]) / total * 100;
- printf("The percentage of road users' injuries in June is %.2f%%\n", percentage);
- }
- else if (choice == 7)
- {
- for (j = 0; j < 12; j++)
- total = total + Pedestrian[j] + MotorCyclist[j] + MotorCar[j] + LightTruck[j] + Truck[j];
- percentage = (percentage + Pedestrian[6] + MotorCyclist[6] + MotorCar[6] + LightTruck[6] + Truck[6]) / total * 100;
- printf("The percentage of road users' injuries in July is %.2f%%\n", percentage);
- }
- else if (choice == 8)
- {
- for (j = 0; j < 12; j++)
- total = total + Pedestrian[j] + MotorCyclist[j] + MotorCar[j] + LightTruck[j] + Truck[j];
- percentage = (percentage + Pedestrian[7] + MotorCyclist[7] + MotorCar[7] + LightTruck[7] + Truck[7]) / total * 100;
- printf("The percentage of road users' injuries in August is %.2f%%\n", percentage);
- }
- else if (choice == 9)
- {
- for (j = 0; j < 12; j++)
- total = total + Pedestrian[j] + MotorCyclist[j] + MotorCar[j] + LightTruck[j] + Truck[j];
- percentage = (percentage + Pedestrian[8] + MotorCyclist[8] + MotorCar[8] + LightTruck[8] + Truck[8]) / total * 100;
- printf("The percentage of road users' injuries in September is %.2f%%\n", percentage);
- }
- else if (choice == 10)
- {
- for (j = 0; j < 12; j++)
- total = total + Pedestrian[j] + MotorCyclist[j] + MotorCar[j] + LightTruck[j] + Truck[j];
- percentage = (percentage + Pedestrian[9] + MotorCyclist[9] + MotorCar[9] + LightTruck[9] + Truck[9]) / total * 100;
- printf("The percentage of road users' injuries in October is %.2f%%\n", percentage);
- }
- else if (choice == 11)
- {
- for (j = 0; j < 12; j++)
- total = total + Pedestrian[j] + MotorCyclist[j] + MotorCar[j] + LightTruck[j] + Truck[j];
- percentage = (percentage + Pedestrian[10] + MotorCyclist[10] + MotorCar[10] + LightTruck[10] + Truck[10]) / total * 100;
- printf("The percentage of road users' injuries in November is %.2f%%\n", percentage);
- }
- else if (choice == 12)
- {
- for (j = 0; j < 12; j++)
- total = total + Pedestrian[j] + MotorCyclist[j] + MotorCar[j] + LightTruck[j] + Truck[j];
- percentage = (percentage + Pedestrian[11] + MotorCyclist[11] + MotorCar[11] + LightTruck[11] + Truck[11]) / total * 100;
- printf("The percentage of road users' injuries in December is %.2f%%\n", percentage);
- }
- else
- {
- printf("Invalid, try again\n\n");
- }
- }
- }
- void function4(void)
- {
- int difference[11];
- int choice;
- printf("Please select a Road User\n");
- printf("1)Pedestrian\n2)Motor Cyclists\n3)Motor Car\n4)Light Truck\n5)Truck\n\n");
- scanf_s("%d", &choice);
- if (choice == 1)
- {
- difference[0] = Pedestrian[0] - Pedestrian[1];
- difference[1] = Pedestrian[2] - Pedestrian[1];
- difference[2] = Pedestrian[2] - Pedestrian[3];
- difference[3] = Pedestrian[4] - Pedestrian[3];
- difference[4] = Pedestrian[4] - Pedestrian[5];
- difference[5] = Pedestrian[6] - Pedestrian[5];
- difference[6] = Pedestrian[7] - Pedestrian[6];
- difference[7] = Pedestrian[7] - Pedestrian[8];
- difference[8] = Pedestrian[9] - Pedestrian[8];
- difference[9] = Pedestrian[9] - Pedestrian[10];
- difference[10] = Pedestrian[11] - Pedestrian[10];
- printf("The difference between January and February is %d\n", difference[0]);
- printf("The difference between February and March is %d\n", difference[1]);
- printf("The difference between March and April is %d\n", difference[2]);
- printf("The difference between April and May is %d\n", difference[3]);
- printf("The difference between May and June is %d\n", difference[4]);
- printf("The difference between June and July is %d\n", difference[5]);
- printf("The difference between July and August is %d\n", difference[6]);
- printf("The difference between August and September is %d\n", difference[7]);
- printf("The difference between September and October is %d\n", difference[8]);
- printf("The difference between October and November is %d\n", difference[9]);
- printf("The difference between November and December is %d\n", difference[10]);
- }
- else if (choice == 2)
- {
- difference[0] = MotorCyclist[1] - MotorCyclist[0];
- difference[1] = MotorCyclist[2] - MotorCyclist[1];
- difference[2] = MotorCyclist[2] - MotorCyclist[3];
- difference[3] = MotorCyclist[3] - MotorCyclist[4];
- difference[4] = MotorCyclist[4] - MotorCyclist[5];
- difference[5] = MotorCyclist[6] - MotorCyclist[5];
- difference[6] = MotorCyclist[7] - MotorCyclist[6];
- difference[7] = MotorCyclist[7] - MotorCyclist[8];
- difference[8] = MotorCyclist[9] - MotorCyclist[8];
- difference[9] = MotorCyclist[10] - MotorCyclist[9];
- difference[10] = MotorCyclist[10] - MotorCyclist[11];
- printf("The difference between January and February is %d\n", difference[0]);
- printf("The difference between February and March is %d\n", difference[1]);
- printf("The difference between March and April is %d\n", difference[2]);
- printf("The difference between April and May is %d\n", difference[3]);
- printf("The difference between May and June is %d\n", difference[4]);
- printf("The difference between June and July is %d\n", difference[5]);
- printf("The difference between July and August is %d\n", difference[6]);
- printf("The difference between August and September is %d\n", difference[7]);
- printf("The difference between September and October is %d\n", difference[8]);
- printf("The difference between October and November is %d\n", difference[9]);
- printf("The difference between November and December is %d\n", difference[10]);
- }
- else if (choice == 3)
- {
- difference[0] = MotorCar[0] - MotorCar[1];
- difference[1] = MotorCar[1] - MotorCar[2];
- difference[2] = MotorCar[3] - MotorCar[2];
- difference[3] = MotorCar[4] - MotorCar[3];
- difference[4] = MotorCar[4] - MotorCar[5];
- difference[5] = MotorCar[6] - MotorCar[5];
- difference[6] = MotorCar[7] - MotorCar[6];
- difference[7] = MotorCar[7] - MotorCar[8];
- difference[8] = MotorCar[9] - MotorCar[8];
- difference[9] = MotorCar[9] - MotorCar[10];
- difference[10] = MotorCar[10] - MotorCar[11];
- printf("The difference between January and February is %d\n", difference[0]);
- printf("The difference between February and March is %d\n", difference[1]);
- printf("The difference between March and April is %d\n", difference[2]);
- printf("The difference between April and May is %d\n", difference[3]);
- printf("The difference between May and June is %d\n", difference[4]);
- printf("The difference between June and July is %d\n", difference[5]);
- printf("The difference between July and August is %d\n", difference[6]);
- printf("The difference between August and September is %d\n", difference[7]);
- printf("The difference between September and October is %d\n", difference[8]);
- printf("The difference between October and November is %d\n", difference[9]);
- printf("The difference between November and December is %d\n", difference[10]);
- }
- else if (choice == 4)
- {
- difference[0] = LightTruck[1] - LightTruck[0];
- difference[1] = LightTruck[1] - LightTruck[2];
- difference[2] = LightTruck[2] - LightTruck[3];
- difference[3] = LightTruck[4] - LightTruck[3];
- difference[4] = LightTruck[4] - LightTruck[5];
- difference[5] = LightTruck[5] - LightTruck[6];
- difference[6] = LightTruck[7] - LightTruck[6];
- difference[7] = LightTruck[7] - LightTruck[8];
- difference[8] = LightTruck[9] - LightTruck[8];
- difference[9] = LightTruck[9] - LightTruck[10];
- difference[10] = LightTruck[10] - LightTruck[11];
- printf("The difference between January and February is %d\n", difference[0]);
- printf("The difference between February and March is %d\n", difference[1]);
- printf("The difference between March and April is %d\n", difference[2]);
- printf("The difference between April and May is %d\n", difference[3]);
- printf("The difference between May and June is %d\n", difference[4]);
- printf("The difference between June and July is %d\n", difference[5]);
- printf("The difference between July and August is %d\n", difference[6]);
- printf("The difference between August and September is %d\n", difference[7]);
- printf("The difference between September and October is %d\n", difference[8]);
- printf("The difference between October and November is %d\n", difference[9]);
- printf("The difference between November and December is %d\n", difference[10]);
- }
- else if (choice == 5)
- {
- difference[0] = Truck[0] - Truck[1];
- difference[1] = Truck[1] - Truck[2];
- difference[2] = Truck[3] - Truck[2];
- difference[3] = Truck[3] - Truck[4];
- difference[4] = Truck[5] - Truck[4];
- difference[5] = Truck[5] - Truck[6];
- difference[6] = Truck[7] - Truck[6];
- difference[7] = Truck[7] - Truck[8];
- difference[8] = Truck[8] - Truck[9];
- difference[9] = Truck[10] - Truck[9];
- difference[10] = Truck[10] - Truck[11];
- printf("The difference between January and February is %d\n", difference[0]);
- printf("The difference between February and March is %d\n", difference[1]);
- printf("The difference between March and April is %d\n", difference[2]);
- printf("The difference between April and May is %d\n", difference[3]);
- printf("The difference between May and June is %d\n", difference[4]);
- printf("The difference between June and July is %d\n", difference[5]);
- printf("The difference between July and August is %d\n", difference[6]);
- printf("The difference between August and September is %d\n", difference[7]);
- printf("The difference between September and October is %d\n", difference[8]);
- printf("The difference between October and November is %d\n", difference[9]);
- printf("The difference between November and December is %d\n", difference[10]);
- }
- else
- {
- printf("Invalid,Please try again\n\n");
- }
- }
- void function5(void)
- {
- int total[12];
- total[0] = Pedestrian[0] + MotorCyclist[0] + MotorCar[0] + LightTruck[0] + Truck[0];
- total[1] = Pedestrian[1] + MotorCyclist[1] + MotorCar[1] + LightTruck[1] + Truck[1];
- total[2] = Pedestrian[2] + MotorCyclist[2] + MotorCar[2] + LightTruck[2] + Truck[2];
- total[3] = Pedestrian[3] + MotorCyclist[3] + MotorCar[3] + LightTruck[3] + Truck[3];
- total[4] = Pedestrian[4] + MotorCyclist[4] + MotorCar[4] + LightTruck[4] + Truck[4];
- total[5] = Pedestrian[5] + MotorCyclist[5] + MotorCar[5] + LightTruck[5] + Truck[5];
- total[6] = Pedestrian[6] + MotorCyclist[6] + MotorCar[6] + LightTruck[6] + Truck[6];
- total[7] = Pedestrian[7] + MotorCyclist[7] + MotorCar[7] + LightTruck[7] + Truck[7];
- total[8] = Pedestrian[8] + MotorCyclist[8] + MotorCar[8] + LightTruck[8] + Truck[8];
- total[9] = Pedestrian[9] + MotorCyclist[9] + MotorCar[9] + LightTruck[9] + Truck[9];
- total[10] = Pedestrian[10] + MotorCyclist[10] + MotorCar[10] + LightTruck[10] + Truck[10];
- total[11] = Pedestrian[11] + MotorCyclist[11] + MotorCar[11] + LightTruck[11] + Truck[11];
- if (total[0] < total[1] && total[0] < total[2] && total[0] < total[3] && total[0] < total[4] && total[0] < total[5] && total[0] < total[6] && total[0] < total[7] && total[0] < total[8] && total[0] < total[9] && total[0] < total[10] && total[0] < total[11])
- {
- printf("The lowest monthly total number of injuries is January %d\n", total[0]);
- }
- else if (total[1] < total[0] && total[1] < total[2] && total[1] < total[3] && total[1] < total[4] && total[1] < total[5] && total[1] < total[6] && total[1] < total[7] && total[1] < total[8] && total[1] < total[9] && total[1] < total[10] && total[1] < total[11])
- {
- printf("The lowest monthly total number of injuries is February %d\n", total[1]);
- }
- else if (total[2] < total[0] && total[2] < total[1] && total[2] < total[3] && total[2] < total[4] && total[2] < total[5] && total[2] < total[6] && total[2] < total[7] && total[2] < total[8] && total[2] < total[9] && total[2] < total[10] && total[2] < total[11])
- {
- printf("The lowest monthly total number of injuries is March %d\n", total[2]);
- }
- else if (total[3] < total[0] && total[3] < total[1] && total[3] < total[2] && total[3] < total[4] && total[3] < total[5] && total[3] < total[6] && total[3] < total[7] && total[3] < total[8] && total[3] < total[9] && total[3] < total[10] && total[3] < total[11])
- {
- printf("The lowest monthly total number of injuries is April %d\n", total[3]);
- }
- else if (total[4] < total[0] && total[4] < total[1] && total[4] < total[2] && total[4] < total[3] && total[4] < total[5] && total[4] < total[6] && total[4] < total[7] && total[4] < total[8] && total[4] < total[9] && total[4] < total[10] && total[4] < total[11])
- {
- printf("The lowest monthly total number of injuries is May %d\n", total[4]);
- }
- else if (total[5] < total[0] && total[5] < total[1] && total[5] < total[2] && total[5] < total[3] && total[5] < total[4] && total[5] < total[6] && total[5] < total[7] && total[5] < total[8] && total[5] < total[9] && total[5] < total[10] && total[5] < total[11])
- {
- printf("The lowest monthly total number of injuries is June %d\n", total[5]);
- }
- else if (total[6] < total[0] && total[6] < total[1] && total[6] < total[2] && total[6] < total[3] && total[6] < total[4] && total[6] < total[5] && total[6] < total[7] && total[6] < total[8] && total[6] < total[9] && total[6] < total[10] && total[6] < total[11])
- {
- printf("The lowest monthly total number of injuries is July %d\n", total[6]);
- }
- else if (total[7] < total[0] && total[7] < total[1] && total[7] < total[2] && total[7] < total[3] && total[7] < total[4] && total[7] < total[5] && total[7] < total[6] && total[7] < total[8] && total[7] < total[9] && total[7] < total[10] && total[7] < total[11])
- {
- printf("The lowest monthly total number of injuries is August %d\n", total[7]);
- }
- else if (total[8] < total[0] && total[8] < total[1] && total[8] < total[2] && total[8] < total[3] && total[8] < total[4] && total[8] < total[5] && total[8] < total[6] && total[8] < total[7] && total[8] < total[9] && total[8] < total[10] && total[8] < total[11])
- {
- printf("The lowest monthly total number of injuries is September %d\n", total[8]);
- }
- else if (total[9] < total[0] && total[9] < total[1] && total[9] < total[2] && total[9] < total[3] && total[9] < total[4] && total[9] < total[5] && total[9] < total[6] && total[9] < total[7] && total[9] < total[8] && total[9] < total[10] && total[9] < total[11])
- {
- printf("The lowest monthly total number of injuries is October %d\n", total[9]);
- }
- else if (total[10] < total[0] && total[10] < total[1] && total[10] < total[2] && total[10] < total[3] && total[10] < total[4] && total[10] < total[5] && total[10] < total[6] && total[10] < total[7] && total[10] < total[8] && total[10] < total[9] && total[10] < total[11])
- {
- printf("The lowest monthly total number of injuries is November %d\n", total[10]);
- }
- else if (total[11] < total[0] && total[11] < total[1] && total[11] < total[2] && total[11] < total[3] && total[11] < total[4] && total[11] < total[5] && total[11] < total[6] && total[11] < total[7] && total[11] < total[8] && total[11] < total[9] && total[11] < total[10])
- {
- printf("The lowest monthly total number of injuries is December %d\n", total[11]);
- }
- else
- {
- printf("Invalid option!, Please try again\n");
- }
- }
- void function6(void)
- {
- int z, choice, j, temp;
- printf("Select a Road User\n");
- printf("1)Pedestrian\n2)Motor Cyclists\n3)Motor Car\n4)Light Truck\n5)Truck\n");
- scanf_s(" %d", &choice);
- if (choice == 1)
- {
- for (z = 0; z < 12; z++)
- {
- for (j = 0; j < 12; j++)
- {
- if (Pedestrian[j] < Pedestrian[j + 1])
- {
- temp = Pedestrian[j];
- Pedestrian[j] = Pedestrian[j + 1];
- Pedestrian[j + 1] = temp;
- }
- }
- }
- printf("The sorted array for Pedestrian in descending order is \n");
- for (z = 0; z < 12; z++)
- {
- printf("%d\n", Pedestrian[z]);
- }
- }
- else if (choice == 2)
- {
- for (z = 0; z < 12; z++)
- {
- for (j = 0; j < 12; j++)
- {
- if (MotorCyclist[j] < MotorCyclist[j + 1])
- {
- temp = MotorCyclist[j];
- MotorCyclist[j] = MotorCyclist[j + 1];
- MotorCyclist[j + 1] = temp;
- }
- }
- }
- printf("The sorted array for Motor Cyclist in descending order is \n");
- for (z = 0; z < 12; z++)
- {
- printf("%d\n", MotorCyclist[z]);
- }
- }
- else if (choice == 3)
- {
- for (z = 0; z < 12; z++)
- {
- for (j = 0; j < 12; j++)
- {
- if (MotorCar[j] < MotorCar[j + 1])
- {
- temp = MotorCar[j];
- MotorCar[j] = MotorCar[j + 1];
- MotorCar[j + 1] = temp;
- }
- }
- }
- printf("The sorted array for Motor Car in descending order is \n");
- for (z = 0; z < 12; z++)
- {
- printf("%d\n", MotorCar[z]);
- }
- }
- else if (choice == 4)
- {
- for (z = 0; z < 12; z++)
- {
- for (j = 0; j < 12; j++)
- {
- if (LightTruck[j] < LightTruck[j + 1])
- {
- temp = LightTruck[j];
- LightTruck[j] = LightTruck[j + 1];
- LightTruck[j + 1] = temp;
- }
- }
- }
- printf("The sorted array for Light Truck in descending order is \n");
- for (z = 0; z < 12; z++)
- {
- printf("%d\n", LightTruck[z]);
- }
- }
- else if (choice == 5)
- {
- for (z = 0; z < 12; z++)
- {
- for (j = 0; j < 12; j++)
- {
- if (Truck[j] < Truck[j + 1])
- {
- temp = Truck[j];
- Truck[j] = Truck[j + 1];
- Truck[j + 1] = temp;
- }
- }
- }
- printf("The sorted array for Truck in descending order is \n");
- for (z = 0; z < 12; z++)
- {
- printf("%d\n", Truck[z]);
- }
- }
- else
- {
- printf("Invalid! Please try again\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment