/*
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