Problem Write a C program to keep track of frequency of flights (number of trips per flight) for different passengers of
Posted: Sat May 14, 2022 3:57 pm
Problem Write a C program to keep track of frequency of flights (number of trips per flight) for different passengers of an airlines company. The program design should use main and the below functions. In the program, materials covered in the class until week 11, should only be used. In the program, constant statement, global variables, nested loop and else statement cannot be used. We consider in the program the following arrays named as follows: 1. A 1D array of integer of size 6 that stores the IDs of passengers. The name of the array is “IDs_pass” followed by the value of your student ID. If your student ID is 42357, the array name will be IDs_pass _42357. 2. A 1D array of integer of size 4 that stores the IDs of flights. The name of the array is "ID_Fli" followed by the value of your student ID. If your student ID is 42357, the array name will be IDs_Fli_42357. 3. A 2D array with size equal to 6 x 4 that stores the number of trips for each flight per passenger. The name of the array is "Fli_Freq" followed by the value of your section number. If your section number is F10, the array name will be Fli_Freq_F10. The number of row will represent the number of passengers while the number of the column will represent the number of flights. In the below example, the passenger with ID = 1111 (Row index =0) has 5 trips for flight ID = 11 (Column index = 0), 4 trips for flight ID = 22 (Column index =1), etc. 4. A 1D array of character with size equal to 6 that stores the frequent flyer for each passenger. 'P' for Platinum, 'S' for Silver, or 'R' for Regular. The name of the array is "Freq" followed by the value of your section number. If your section number is F10, the array name will be Freq_F10. 11 22 33 44 IDs_Fli_42357 0 1 2 3 0 5 4 6 4 1111 R 1 7 5 2 1 2222 R 2 5 4 7 1 3333 R 2 3 3 25 S 30 40 52 4444 4 500 P 500 100 300 5555 5 1 R 2 31 6666 1 Fli_Freq_F10 IDs_pass _42357 Freq_F10
1. Using pointer notation, define a void function F_read that takes a 10 array of integer arr and the size of the array N as formal parameters. The array arr represents the number of trips for N flights per passenger. The function should prompt the user to fill the array arr with number of trips until user enters EOF. If the user enters EOF, the function should stop reading and assign -12 to all elements of the array arr. For example, if the user enters successfully one, two, or three values from 4 values terminated by EOF, the program should assign -12 to all elements of the array and stop the reading from the standard input. (20 points) 2. Using pointer notation, define a non-void function F_total_trips that takes a 10 array arr as formal parameter. The array arr represents the number of trips for each flight per passenger. The function calculates and returns the total number of trips. (15 points) 3. Define a non-void function named F_freq_flyer that takes the sum of the trips sum_trip as formal parameter and returns the frequent flyer character value according to the following table. (10 points) Sum of trips < 100 >=100 and <=1000 > 1000 and < 2000 Frequent flyer R S Р 4. Using pointer notation, define a void function F_print that takes two 10 arrays, IDs_pass _42357 of size 6 and Freq_F10 of size 6 as formal parameters. The function then prints the frequent flyer description for each passenger, as shown in sample output below. (10 points) Frequent flyer R S Р Frequent flyer description Regular Silver Platinum 5. Using pointer notation, define a non-void function F_search that takes three formal parameters: a 10 array arr of size 4, a 10 array IDs_Fli_42357 of size 4 and the number of trips num_trips. The array arr represents the number of trips for each flight per passenger. The function should search for num_trips in arr and returns the ld of the flight of the first occurrence of num_trips if found; otherwise, returns-1. (15 points)
6. Write a main function to do the following by using the above functions: (30 points) Declare and initialize the array Freq_F10 with 'b'. • Declare and initialize the arrays IDs_pass _42357, IDs_Fli_42357, and Fli_Freq_F10 with - 20. Page 3 of 4 Prompt user to initialize the arrays IDs_pass _42357 and IDs_Fli_42357. Note that when the user enters -1, the main function should stop reading of the current array and assign -30 to the remaining elements of the array. Prompts user to initialize the array Fli_Freq_F10 by calling F_read for every row in the 2D array. If user enters EOF, the main function should fill the rest of elements of the array with-40. Call F_total_trips for every row in the 2D array and print the totals returned as in sample output below. • Call F_freq_flyer and F_print to find out and print the frequent flyer descriptions for each passenger. • Prompt the use to enter passenger ID and frequency (number) of trips for a flight and call F_search to find the flight ID and print it. If passenger ID or flight ID is not found, a message to state that should be displayed. • The main function should run successfully with different scenarios. • The sample output should contain your name, your CS 159 section number and your ID as shown below.
SAMPLE OUTPUT: Enter IDs of 6 passengers: 1111 2222 3333 4444 5555 6666 Enter IDs of 4 flights: 11 22 33 44 Enter the number of trips for each passenger: Passenger With ID - 1111: 5 4 6 4 Passenger With ID - 2222 : 75 21 Passenger With ID - 3333 : 5471 Passenger With ID - 4444 : 25 30 40 52 Passenger With ID - 5555 : see see 100 see Passenger With ID - 6666 : 1 2 35 Passenger ID Total Trips 19 15 17 1111 2222 3333 4444 5555 6666 147 1400 11 Passenger ID 1111 2222 3333 4444 5555 6666 Frequent Flyer Regular Regular Regular Silver Platinum Regular RRRR Enter passenger ID and frequency of trips for a flight: 5555 50e The flight Id is 11 Student XX YY Section F10 ID - 42357 - Semester SP22
1. Using pointer notation, define a void function F_read that takes a 10 array of integer arr and the size of the array N as formal parameters. The array arr represents the number of trips for N flights per passenger. The function should prompt the user to fill the array arr with number of trips until user enters EOF. If the user enters EOF, the function should stop reading and assign -12 to all elements of the array arr. For example, if the user enters successfully one, two, or three values from 4 values terminated by EOF, the program should assign -12 to all elements of the array and stop the reading from the standard input. (20 points) 2. Using pointer notation, define a non-void function F_total_trips that takes a 10 array arr as formal parameter. The array arr represents the number of trips for each flight per passenger. The function calculates and returns the total number of trips. (15 points) 3. Define a non-void function named F_freq_flyer that takes the sum of the trips sum_trip as formal parameter and returns the frequent flyer character value according to the following table. (10 points) Sum of trips < 100 >=100 and <=1000 > 1000 and < 2000 Frequent flyer R S Р 4. Using pointer notation, define a void function F_print that takes two 10 arrays, IDs_pass _42357 of size 6 and Freq_F10 of size 6 as formal parameters. The function then prints the frequent flyer description for each passenger, as shown in sample output below. (10 points) Frequent flyer R S Р Frequent flyer description Regular Silver Platinum 5. Using pointer notation, define a non-void function F_search that takes three formal parameters: a 10 array arr of size 4, a 10 array IDs_Fli_42357 of size 4 and the number of trips num_trips. The array arr represents the number of trips for each flight per passenger. The function should search for num_trips in arr and returns the ld of the flight of the first occurrence of num_trips if found; otherwise, returns-1. (15 points)
6. Write a main function to do the following by using the above functions: (30 points) Declare and initialize the array Freq_F10 with 'b'. • Declare and initialize the arrays IDs_pass _42357, IDs_Fli_42357, and Fli_Freq_F10 with - 20. Page 3 of 4 Prompt user to initialize the arrays IDs_pass _42357 and IDs_Fli_42357. Note that when the user enters -1, the main function should stop reading of the current array and assign -30 to the remaining elements of the array. Prompts user to initialize the array Fli_Freq_F10 by calling F_read for every row in the 2D array. If user enters EOF, the main function should fill the rest of elements of the array with-40. Call F_total_trips for every row in the 2D array and print the totals returned as in sample output below. • Call F_freq_flyer and F_print to find out and print the frequent flyer descriptions for each passenger. • Prompt the use to enter passenger ID and frequency (number) of trips for a flight and call F_search to find the flight ID and print it. If passenger ID or flight ID is not found, a message to state that should be displayed. • The main function should run successfully with different scenarios. • The sample output should contain your name, your CS 159 section number and your ID as shown below.
SAMPLE OUTPUT: Enter IDs of 6 passengers: 1111 2222 3333 4444 5555 6666 Enter IDs of 4 flights: 11 22 33 44 Enter the number of trips for each passenger: Passenger With ID - 1111: 5 4 6 4 Passenger With ID - 2222 : 75 21 Passenger With ID - 3333 : 5471 Passenger With ID - 4444 : 25 30 40 52 Passenger With ID - 5555 : see see 100 see Passenger With ID - 6666 : 1 2 35 Passenger ID Total Trips 19 15 17 1111 2222 3333 4444 5555 6666 147 1400 11 Passenger ID 1111 2222 3333 4444 5555 6666 Frequent Flyer Regular Regular Regular Silver Platinum Regular RRRR Enter passenger ID and frequency of trips for a flight: 5555 50e The flight Id is 11 Student XX YY Section F10 ID - 42357 - Semester SP22