Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  comp project
Language: C/C++
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

     int flight_number[30], no_of_seats, customer_id[30], age[30], check, baggage[30], value, n, i, j, a, key, val_main_menu, menu;
     float weight[30], wt;
     char gender[2][30], date[100][30], source[100][30], destination[100][30],cust_name[30][30], clb_mem[5][30], str[500];
     float amount = 5000.0;
     int member[30];     
     
     void passenger_details();
     void airfare();
     void e_ticket();
     void passenger_data();
     void sorted();
    void swap(char *str1, char *str2); 
     
     

int main() {
     
     
     //Giving user info about availability
     printf("******************************************************************************\n");
     printf("           Welcome to Airways Management\n");
     printf("\n");
     printf("Flights available are :\nG123 Bangalore - Chennai\nH124 Bangalore - Pune\nK126 Bangalore to Mumbai\n567 Bangalore - Hyderabad\n");
     printf("Seats available are :\n123 Bangalore - Chennai (22)\n124 Bangalore - Pune (15)\n125 Bangalore to Mumbai (27)\n126 Bangalore - Hyderabad(6)\n");
     printf("******************************************************************************\n\n");
     
     
     //Taking customer count
     printf("Enter number of passengers to register   : ");
     scanf("%d", &n);
     printf("\n\n");
     
     
     //Initiatin loop for taking multiple paasenger details
     for(i = 0; i < n; i++){
          
               //Displaying details of seat availability
               printf("******************************************************************************\n");
               printf("           Welcome to Airways Management\n");
               printf("\n");
               printf("Flights available are :\nG123 Bangalore - Chennai\nH124 Bangalore - Pune\nK126 Bangalore to Mumbai\n567 Bangalore - Hyderabad\n");
               printf("Seats available are :\n123 Bangalore - Chennai (22)\n124 Bangalore - Pune (15)\n125 Bangalore to Mumbai (27)\n126 Bangalore - Hyderabad(6)\n");
               printf("******************************************************************************\n\n\n");
                    //Taking Input
               printf("*           Customer Registration           *\n\n");
               printf("*                 Passenger %d               *\n", (i + 1));//displaying the passenger number that the details are taken for
               printf("                _______________\n\n");
               printf("\nEnter customer name                      : ");
               scanf("%s", cust_name+i);
               printf("Enter your flight number                 : ");
               scanf("%d", flight_number+i);     
               printf("Enter your customer ID                   : ");
               scanf("%d", customer_id+i);
               printf("Enter your age                           : ");
               scanf("%d", age+i);
               printf("Enter the number of your baggages        : ");
               scanf("%d", baggage+i);
               printf("Enter the date                           : ");
               scanf("%s", date+i);
               printf("Enter your gender (F/M)                  : ");
               scanf("%s", gender+i);
               printf("Enter your source                        : ");
               scanf("%s", source+i);
               printf("Enter your destination                   : ");
               scanf("%s", destination+i);
               printf("Are you a member (1-Yes or 2-No)         : ");
               scanf("%d", member+i);
               printf("Enter the weight of your baggages(in Kg) : "); 
               scanf("%f", weight+i);
               
               system("cls");
}




do{

//Menu for displaying data
     printf("\nEnter :\n [1] for passenger booking data \n [2] Display list of registered passengers \n [3] Display flights that have been booked \n :");
     scanf("%d", &val_main_menu);
     
     switch(val_main_menu){
          
          case 1: do{
          
                         passenger_data();
                    
                      }
                    while(check==2);
                    break;
                    
          case 2: sorted();
                    for(i = 0; i < n; i++)
                         {
                              printf("Customer ID : %d\t - Passenger Name : %s\n", customer_id[i], cust_name[i]);
                         }
                    break;
                    
          case 3: sorted();
                    for(i = 0; i < n; i++)
                         {
                              printf("Flight number : %d\t - Source : %s\t - Destination : %s", flight_number, source, destination);
                         }
                    break;
                    
          default: printf("Please enter the correct option!");
                     break;
}
     //exit menu
          printf("\nDo you want to exit?\n1Yes\n2.No\n");
          scanf("%d", &menu);
}
while(menu == 2);
     
      
}

void sorted(){
     for(i = 0; i < n; i++)
                         {
                              for(j = (i + 1); j < n; j++)
                                   {
                                        if(customer_id[i] > customer_id[j])
                                             {
                                                  a = customer_id[i];
                                                  customer_id[i] = customer_id[j];
                                                  customer_id[j] = a;
                                                  
                                                  swap(cust_name[i], cust_name[j]);
                                                  
                                                  a = flight_number[i];
                                                  flight_number[i] = flight_number[j];
                                                  flight_number[j] = a;
                                                  
                                                  a = age[i];
                                                  age[i] = age[j];
                                                  age[j] = a;
                                                  
                                                  a = baggage[i];
                                                  baggage[i] = baggage[j];
                                                  baggage[j] = a;
                                                  
                                                  swap(date[i], date[j]);
                                                  
                                                  swap(gender[i], gender[j]);
                                                  
                                                  swap(source[i], source[j]);
                                                  
                                                  swap(destination[i], destination[j]);
                                                  
                                                  a = member[i];
                                                  member[i] = member[j];
                                                  member[j] = a;
                                                  
                                                  wt = weight[i];
                                                  weight[i] = weight[j];
                                                  weight[j] = wt;
                                             }
                                        
                                        }          
                         }
}


void passenger_data(){
     system("cls");
          
          //searching for a particular user
          printf("Enter a customer ID to search for       : ");
          scanf("%d", &key);
          
          for(i = 0; i < n; i++){
               
               if(customer_id[i] == key){
                    
                    //Menu for displaying data
                    printf("\nEnter :\n [1] for passenger details \n [2] for Airfare calculations \n [3] for e-ticket \n :");
                    scanf("%d", &value);
                    switch(value)
                     {
                         case 1: passenger_details();
                                 break;
                                 
                         case 2: airfare();
                                   break;
                                   
                         case 3: e_ticket();
                                   break;
                                                
                         default://Wrong option error message
                                   printf("Please enter your option: \n");
                                   break;
                    }
               }
          }
          //exit menu
          printf("\nDo you want to go back?\n1Yes\n2.No\n");
          scanf("%d", &check);
}

void swap(char *str1, char *str2) 
            { 
              char *temp = (char *)malloc((strlen(str1) + 1) * sizeof(char)); 
              strcpy(temp, str1); 
              strcpy(str1, str2); 
              strcpy(str2, temp); 
              free(temp); 
            }   



void passenger_details (){
               //Printing out form
                                        printf("\n\n\n******************************************************************************\n");
                                        printf("           Welcome to Airways Management\n");
                                        printf("\n");
                                        printf("Flights available are :\nG123 Bangalore - Chennai\nH124 Bangalore - Pune\nK126 Bangalore to Mumbai\n567 Bangalore - Hyderabad\n");
                                        printf("Seats available are :\nG123 Bangalore - Chennai (22)\nH124 Bangalore - Pune (15)\nK126 Bangalore to Mumbai (27)\n567 Bangalore - Hyderabad(6)\n");
                                        printf("******************************************************************************\n\n\n");
                                        printf("***                  Booking Details                  ***\n\n");
                                        printf("                     _______________\n\n");
                                   
                                        printf("\n"); 
                                        printf(" Customer Name  :   %s\n", *(cust_name+i));
                                        printf("\n Your flight Number is             : %d",*(flight_number+i));
                                       printf("\n Your customer ID is               : %d",*(customer_id+i));
                                        printf("\n Your age is                       : %d", *(age+i)); 
                                        printf("\n Your number of baggages are       : %d", *(baggage+i));
                                        printf("\n The date of travel                : %s", *(date+i));
                                        printf("\n The gender of the passanger       : %s", *(gender+i));
                                        printf("\n The source of the passenger       : %s", *(source+i));
                                        printf("\n The destination of the passeneger : %s\n", *(destination+i));
                                        printf(" Club Membership                    : %d\n\n\n", *(member+i));
                                             printf("******************************************************************************\n");
                                        printf("Thank You for using our Airway system! Have a safe journey!\n");
                                        printf("******************************************************************************\n\n\n");
     
}

void airfare(){
     //Fare Calcultions
                                        printf("                  Fare Details\n\n");
                    
                                        printf("\nYour basic fare is Rs. 5,000");
                                        
                                        if (age[i] >= 60 )
                                        {
                                             amount = amount - ((40.0 / 100.0) * amount);
                                             printf("\nYour Bill amount afer age discount is         : %7.2f Rs. only/-\n\n", amount);
                                        }
                                        if (member[i] == 1)
                                        {
                                             amount = amount - ((5.0 / 100.0) * amount);
                                             printf("\nYour Bill amount afer membership discount is  : %7.2f Rs. only/-\n\n", amount);
                                        }
                                        if (weight[i] > 15.0)
                                        {
                                             amount = amount + ((weight[i] - 15) * 20); 
                                             printf("\nYour Bill amount afer baggage fare is         : %7.2f Rs. only/-\n\n", amount);
                                        }
                                        
                                   
                                        printf("\nYour Total Bill amount is                      : %f Rs. only/-\n\n", amount);
                                             printf("******************************************************************************\n");
                                        printf("Thank You for using our Airway system! Have a safe journey!\n");
                                        printf("******************************************************************************\n");
}

void e_ticket(){
          //Printing out e-ticket
                                   printf(" Customer Name  :   %s\n", *(cust_name+i));
                                   printf("\n Your flight Number is             : %d",*(flight_number+i));
                                   printf("\n Your customer ID is               : %d",*(customer_id+i));
                                   printf("\n Your age is                       : %d", *(age+i)); 
                                  printf("\n The date of travel                : %s", *(date+i));
                                   printf("\n The gender of the passanger       : %s", *(gender+i));
                                   printf("\n The source of the passenger       : %s", *(source+i));
                                   printf("\n The destination of the passeneger : %s\n", *(destination+i));
                                  printf("\nYour total bill is                 : %7.2f Rs. only/-\n\n", amount); 
                                  printf("******************************************************************************\n");
                                   printf("Thank You for using our Airway system! Have a safe journey!\n");
                                   printf("******************************************************************************\n");
}
Comments: