Write a C program to keep track of frequency of flights (number of trips per flight) taken by different passengers of an airlines company. You are not allowed to use array index notation in the program. Instead, you must use a pointer notation to access different elements of an array. A for loop and a do/while loop are not allowed to be used in the main function. The program design should use main and the below functions.
Consider the constant PASSENGER_SIZE with value equal to your section number plus three and FLIGHT_SIZE with value equal to the sum of digits of your student ID. For example, if your section number is O4 and your student ID is 31020, the value of PASSENGER_SIZE should be 7 (4+3) and the value of FLIGHT_SIZE should be 6 (3+1+0+2+0=6).

In the program, we consider the following arrays named as follows:
IDs_passengers: is a 1D array of integer of size PASSENGER_SIZE that stores the IDs of passengers. Each passenger should have a unique positive ID.
IDs_flights: is a 1D array of integer of size FLIGHT_SIZE that stores the IDs of different flights. Each flight should have a unique positive ID.
Flight_frequency: is a 2D array with size equal to PASSENGER_SIZE x FLIGHT_SIZE that stores the number of trips for each flight per passenger. The number of trips should be greater or equal to zero. The number of rows represents the number of passengers while the number of the columns represents the number of flights. In the following example, the passenger with ID = 33 (Row index =0) has 5 trips for flight ID = 222 (Column index = 0), 7 trips for flight ID = 333 (Column index =1), etc.
Freq_flyers: is a 1D array of character with size equal to PASSENGER_SIZE that stores the frequent flyer for each passenger. ‘P’ for Platinum, ‘S’ for Silver, or ‘R’ for Regular.
programming-in-c-assigments-8-10-2021-1706.JPG
1. Define a void function O_F1_10 that takes a 1D 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 -9. If the user enters -9, the function should stop reading and assign -10 to all elements of the array arr. For example, if the user enters successfully one, two, or three values from FLIGHT_SIZE values terminated by -9, the program should assign -10 to all elements of the array and stop the reading from the standard input. (20 points)
2. Define a function O_F2_10 that takes a 1D array arr as formal parameter. The array arr represents the number of trips for each flight per passenger. The function calculates and returns the average number of trips. (15 points)
3. Define a function O_F3_10 that takes three formal parameters: a 1D array arr of size FLIGHT_SIZE, a 1D array IDs_flights of size FLIGHT_SIZE 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 return the flight Id corresponding to the first occurrence of num_trips if found; otherwise, return -1. (20 points)
4. Define a void function O_F4_10 that takes one 2D array Flight_frequency and two 1D arrays, IDs_passengers and Freq_flyers as formal parameters. The function should fill the Freq_flyers with the frequent flyer character value for each passenger according to the following table. The function then prints the frequent flyer description for each passenger, as shown in sample output below. (20 points)
programming-in-c-assigments-8-10-2021-1708.JPG
5. Write a main function to do the following by using the above functions: (25 points)
• Declare and initialize the array Freq_fyers with ‘e’.
• Declare and initialize the arrays IDs_passengers, IDs_flights, and Flight_frequency with your ID student times -1. For example, if your student ID is 31020, IDs_passengers, IDs_flights, and Flight_frequency should be initializing with the value -31020.
• Defines 5 character variables named A1, A2, A3, A4 and A5. Initialize A1 with the first digit of your student ID, A2 with the second digit of your student ID, A3 with the third digit of your student ID, A4 with the fourth digit of your student ID and A5 with the fifth digit of your student ID. For example, If your student ID is 42357, A1 should contain the character ‘4’, A2 should contains characters ‘2’, A3 should contain the character ‘3’, A4 should contain the character ‘5’, and A5 should contains the character ‘7’. Prints the values of these variables on the screen as below. You can use only assignment and printf instructions in this part. (5 points)
STUDENT ID:
A1 is equal to 4 A2 is equal to 2 A3 is equal to 3 A4 is equal to 5 A5 is equal to 7
• Prompt the user to initialize the arrays IDs_passengers and IDs_flights. Note that when the user enters -9, the main function should stop reading and assign -10 to the remaining elements of the array.
• Prompt the user to initialize the array Flight_frequency by calling O_F1_10 for every row in the 2D array. If user enters -9, the main function should fill the remaining elements of the array with -10.
• Call O_F2_10 for every row in the 2D array and print the average trips for each passenger returned as in sample output below.
• Call O_F4_10 to find out and print the frequent flyer descriptions for each passenger.
• Prompt the user to enter passenger ID and frequency (number) of trips for a flight and call O_F3_10 to find the flight ID and print it. If passenger ID or frequency of trips is not found, it should display a message that required information is not found.
• Print in the screen 5 lines that contains only the character “*”. The number of “*” to be printed per line depends on your students ID number. If your student ID is 42357, the first line should contain 4 characters “*”, the second line should contain 2 characters “*”, the third line should contain 3 characters “*”, the fourth line should contain 5 characters “*” and the fifth line should contain 7 characters “*”. You can use only printf instruction in this part. To print each line you need to use a loop
• The main function should run successfully with different scenarios.
• The name of the .C file is equal to your student ID. For example, if your student ID = 42357, the name of the file will be "42357.c".
• Write your first name, your last name, the course code CS159, your section number and your ID as comments at the top of the code as shown below:
If your name is xxx yyy, your ID is 42357and your section is O7, comments should be:
/*
Assignment 4 solution is created by:
a- ID = 42357
b- Student name= xxx yyy
c- Section O7
d- Semester: Summer 2021
e- Course code : CS159
*/
programming-in-c-assigments-8-10-2021-1710.JPG
programming-in-c-assigments-8-10-2021-1711.JPG


Answer:


/*
Assignment 4 solution is created by:
a-Student name=yourname
b-Id=yourid
c-Section 010
d-Semester:
e-Course code:
*/
#include stdio.h

#define PASSENGER_SIZE 13
#define FLIGHT_SIZE 24


//function O_F1_10
void O_F1_10(int arr[],int N){
printf("Enter the number of trips for each passenger:\n");
int trips;
for(N=0;N<7;N++){
printf("Enter passenger Number of trips:\n");
scanf("%d",&trips);
arr[N]=trips;
}

}

//function O_F2_10
void O_F2_10( int arr[PASSENGER_SIZE],int IDs_passengers[PASSENGER_SIZE]){
int *g,*u;
g=arr;
u=IDs_passengers;
int i,v;
float average;
int sum=0,count=0;
int element,mypassenger;

printf(" Enter the number of Trips for each passenger:\n");
for(i=0;i<7;i++){
for(v=0;v<7;v++){
mypassenger=IDs_passengers[v];
printf(" Enter passenger ID: %d=",mypassenger);
scanf("%d",&element);
count=count+1;
sum=sum+element;
}
}

//output average trips
printf("Passenger ID \t\t Average Trips:\n");
average=sum/count;
int s;
for(s=0;s<7;s++){
printf("%d \t\t\t\t %.2f\n",mypassenger,average);
}


}

//function O_F3_10
int O_F3_10(int arr[FLIGHT_SIZE],int IDs_flights[FLIGHT_SIZE], int num_trips){
int c,k,*element_found_in_arr=arr,*element_found_in_Ids=IDs_flights,count;
for(c=0;c for(k=0;k *(element_found_in_arr+c)=arr[c];
*(element_found_in_Ids+k)=IDs_flights[k];
}
}
return *(element_found_in_arr+c),*(element_found_in_Ids+k);
}


//function O_F4_10
void O_F4_10(int Flight_frequency[PASSENGER_SIZE][FLIGHT_SIZE],int IDs_passengers[PASSENGER_SIZE],char Freq_flyers[PASSENGER_SIZE]){
int *a,*b;
char *c; //define pointers to access the arrays
a=Flight_frequency;
b=IDs_passengers;
c=Freq_flyers;
int i,j,k,r;
int passID,trip,sum=0;
for(i=0;i for(j=0;j for(k=0;k trip=Flight_frequency[j][k];
sum=sum+trip;
}

}

}
//initialize frequent flyer
for(r=0;r if(sum<250){
Freq_flyers[r]='R';
}else if(sum>=250 && sum<=1150){
Freq_flyers[r]='S';
}else if(sum>1150 && sum<2150){
Freq_flyers[r]='P';
}
}
//print frequent description for each passenger.
printf("Passeger ID \t\t Frequent Flyers\n");
int h,g,pass;
char freq;
for(h=0;h
for(g=0;g pass=IDs_passengers[h];
freq=Freq_flyers[g];
}
//print the flyers
printf("%d \t\t\t\t %c",pass,freq);
printf("\n");

}
}

//main function
int main(){
//arrays declarations.
char Freq_flyers[PASSENGER_SIZE]={'e'}; //stores frequent flyer for each passenger.
int IDs_passengers[PASSENGER_SIZE]={-47364}; //stores ids of passengers
int IDs_flights[FLIGHT_SIZE]={-47364}; //stores ids of flights
int Flight_frequency[PASSENGER_SIZE][FLIGHT_SIZE]={{-47364}}; //stores number of flights of trips for each flight per passenger

//character variables
char A1='4';
char A2='7';
char A3='3';
char A4='6';
char A5='4';

printf("STUDENT ID:\n");
printf("A1 is equal to %c A2 is equal to %c A3 is equal to %c A4 is equal to %c A5 is equal to %c\n",A1,A2,A3,A4,A5);

//initialze array IDs_passengers from keyboard
int number_of_passenger=1,Id,counter=0,ID_flight,counter_flight=0,number_of_flights=1;
printf("Enter Ids of 7 passengers:\n");
while(number_of_passenger<=7){
if(Id !=-9){ //check whether entered value is -9
scanf("%d",&Id);
IDs_passengers[counter]=Id; //assign entered value as Passenger ID.
counter++;
}else{
IDs_passengers[counter]=-10;
break;
}
}

//initilize array IDs_flights from keyboard
printf("Enter Ids of 6 flights:\n");
while(number_of_flights<=6){
if(ID_flight !=-9){ //check whether entered value is -9
scanf("%d",&ID_flight);
IDs_flights[counter_flight]=ID_flight; //assign entered value as flight ID.
counter_flight++;
}else{
IDs_flights[counter_flight]=-10;
counter_flight++;
break;
}
}
//function O_F2_10, average trips
int arr[PASSENGER_SIZE];
O_F2_10(arr,IDs_passengers);


//call function O_F4_10
O_F4_10(Flight_frequency,IDs_passengers,Freq_flyers);


//print characters on screen.
//print line of characters as per ID
int myid[5]={4,7,3,6,4};

int k;
int f;

for(k=0;k<5;k++){
int digit_encounter=myid[k];
for(f=1;f<=digit_encounter;f++){
printf("*");
}
printf("\n");
}

}// end main


Share To Friends Via:
        






More Questions For Programming in C:



  What are the types of errors that occur in C program? (Answered)
What are the types of errors that occur in C program? .
Posted On:Sat 13, March 2021 10:32:24 am
  Which level is C language belonging to? (Answered)
Which level is C language belonging to? .
Posted On:Sat 13, March 2021 10:35:35 am
  What is the difference between C and C++? (Answered)
What is the difference between C and C++? .
Posted On:Sat 13, March 2021 10:36:55 am
  Who developed C language? (Answered)
Who developed C language? .
Posted On:Sat 13, March 2021 10:38:43 am
  C language has been developed in which language? (Answered)
C language has been developed in which language? .
Posted On:Sat 13, March 2021 10:40:38 am
  Is C a structured programming language? (Answered)
Is C a structured programming language? .
Posted On:Sat 13, March 2021 10:42:58 am
  What is structured programming? (Answered)
What is structured programming? .
Posted On:Sat 13, March 2021 10:43:41 am
  What is meant by programming language? (Answered)
What is meant by programming language? .
Posted On:Sat 13, March 2021 10:45:05 am
  What is the difference between C and Java? (Answered)
What is the difference between C and Java? .
Posted On:Sat 13, March 2021 10:48:01 am
  State Whether C language is low level language, or middle level language? (Answered)
State Whether C language is low level language, or middle level language? .
Posted On:Sat 13, March 2021 10:49:17 am
  What is modular programming? (Answered)
What is modular programming? .
Posted On:Sat 13, March 2021 10:51:49 am
  Is C language case sensitive? (Answered)
Is C language case sensitive? .
Posted On:Sat 13, March 2021 10:52:38 am
  What is data type in C? (Answered)
What is data type in C? .
Posted On:Sat 13, March 2021 10:53:51 am
  What is the difference between interpreter and compiler? (Answered)
What is the difference between interpreter and compiler? .
Posted On:Sat 13, March 2021 10:56:44 am
  What is the difference between declaration and definition of a variable? (Answered)
What is the difference between declaration and definition of a variable? .
Posted On:Sat 13, March 2021 10:57:38 am
  What is a program flowchart? (Answered)
What is a program flowchart? .
Posted On:Sat 13, March 2021 11:00:32 am
  What is the syntax for comments in C? (Answered)
What is the syntax for comments in C? .
Posted On:Sat 13, March 2021 11:03:14 am
  List out some of C compilers? (Answered)
List out some of C compilers? .
Posted On:Sat 13, March 2021 11:04:10 am
  What is the difference between exit() and return() in C? (Answered)
What is the difference between exit() and return() in C? .
Posted On:Sat 13, March 2021 11:05:18 am
  What is the difference between calloc and malloc? (Answered)
What is the difference between calloc and malloc? .
Posted On:Sat 13, March 2021 11:07:06 am
  What are the different types of modifiers in C? (Answered)
What are the different types of modifiers in C? .
Posted On:Sat 13, March 2021 11:09:20 am
  What is a constant in C? (Answered)
What is a constant in C? .
Posted On:Sat 13, March 2021 11:10:14 am
  What are the types of constants in C? (Answered)
What are the types of constants in C? .
Posted On:Sat 13, March 2021 11:11:03 am
  What are dangling pointers in C? (Answered)
What are dangling pointers in C? .
Posted On:Sat 13, March 2021 11:11:51 am
  What is the difference between rand(), random(), and randomize()? (Answered)
What is the difference between rand(), random(), and randomize()? .
Posted On:Sat 13, March 2021 11:14:32 am
  What is bebugging? (Answered)
What is bebugging? .
Posted On:Sat 13, March 2021 11:15:50 am
  What is a compiler? (Answered)
What is a compiler? .
Posted On:Sat 13, March 2021 11:18:24 am
  What are all decisions control statements in C? (Answered)
What are all decisions control statements in C? .
Posted On:Sat 13, March 2021 11:20:02 am
  What is mean by debugging? (Answered)
What is mean by debugging? .
Posted On:Sat 13, March 2021 11:22:17 am
  What is static function in C? (Answered)
What is static function in C? .
Posted On:Sat 13, March 2021 11:25:27 am

More Questions Categories:


About Us

Contact us

Terms of use | Privacy policy

Follow Us:               

All Rights Reserved © 2024; pscustudies.com