Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For c++ Write a program that can be used to assign seats for a commercial airpla

ID: 3717278 • Letter: F

Question

For c++

Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with six seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business class, and rows 8 rows through 13 are economy class. Your program must prompt the user to enter the following information: Ticket type (first class, business class, or economy class) Desired seat a. b. Output the seating plan in the following form: Row 1 Row 2 Row 3 Row 4 X Row5 Row 6 Row7 X Row 8 Row 9 X Row 10 Row 11 Row 12 . Row 13 Here, indicates that the seat is available; X indicates that the seat is occupied. Make this a menu- driven program; show the user's choices and allow the user to make the appropriate choices

Explanation / Answer

Code:

#!/usr/bin/perl

# script name: seating_plan.pl
# script to book seats in a commercial airplane

use strict;
use warnings;

my @seat_cols = qw( A B C D E F);

open(FH, "<", "seating.txt") or die "file seating.txt cannot be opened: $!";
my @seating = <FH>;
close(FH);

my $usr_choice = "";
while($usr_choice !~ /QUIT/i ){
   # printing seat plan chart for the user  
   print " ";
   print $_, " " foreach(@seat_cols);
   print " ";
   for(my $i=0; $i < scalar @seating; $i++){
       my @row = split(/,/, $seating[$i]);
       print "Row ",$i+1, " ";
       foreach (@row){
           print $_, " ";
       }
       print " ";
   }
   print " First Class: rows 1 through 2";
   print " Business Class: rows 3 through 7";
   print " Economy Class: rows 8 through 13";
   print " ";

   # Taking the ticket type and seat number as input
   print " Enter ticket type : ";
   my $type = <STDIN>;
   print " Enter seat number : ";
   my $seat = <STDIN>;
   chomp($seat);
   $seat=~/(d+)([A-F])/;
   my ($row, $col) = ($1,$2);
   my $class;
   $class = 'First' if($row >=1 && $row <=2);
   $class = 'Business' if($row >=3 && $row <=7);  
   $class = 'Economy' if($row >=8 && $row <=13);
   my $i;

   # blocking the seat number if available
   if(defined $seating[$row-1]){
       my @tarr = split(/,/, $seating[$row-1]);
       foreach($i=0; $i<scalar @tarr; $i++){
           if($seat_cols[$i] eq $col && $tarr[$i] eq '*'){
               $tarr[$i] = 'X';
               $seating[$row-1] = join(',', @tarr);
               print " Seat number $seat available for class $class and is booked... ";
               #print " ", $seating[$row-1];
               last;
           }
           elsif($seat_cols[$i] eq $col && $tarr[$i] eq 'X'){
               print " Sorry seat not available for seat number $seat. Try another seat... ";
           }
       }       
   }

   # checking if user want to continue, otherwise user can provide 'quit' to exit
   print " Do you want to continue booking ?(Type 'QUIT' to exit from menu and 'Yes' to continue) ";
$usr_choice = <STDIN>;
chomp($usr_choice);
}

Script input file:
186590cb0725:Chegg bonkv$ cat seating.txt
*,*,X,*,X,X
*,X,X,*,X,X
*,*,X,X,X,X
*,*,X,*,*,X
*,*,X,*,X,X
X,*,X,*,X,X
*,X,X,*,X,X
*,*,*,*,X,X
*,*,X,*,X,X
*,*,*,X,X,X
*,*,X,*,*,X
*,*,X,*,X,X
186590cb0725:Chegg bonkv$

Script execution and output:
186590cb0725:Chegg bonkv$ perl seating_plan.pl
   A   B   C   D   E   F  
Row 1   *   *   X   *   X   X
  
Row 2   *   X   X   *   X   X
  
Row 3   *   *   X   X   X   X
  
Row 4   *   *   X   *   *   X
  
Row 5   *   *   X   *   X   X
  
Row 6   X   *   X   *   X   X
  
Row 7   *   X   X   *   X   X
  
Row 8   *   *   *   *   X   X
  
Row 9   *   *   X   *   X   X
  
Row 10   *   *   *   X   X   X
  
Row 11   *   *   X   *   *   X
  
Row 12   *   *   X   *   X   X
  

   First Class: rows 1 through 2
   Business Class: rows 3 through 7
   Economy Class: rows 8 through 13

Enter ticket type : First

Enter seat number : 1D

Seat number 1D available for class First and is booked...

Do you want to continue booking ?(Type 'QUIT' to exit from menu and 'Yes' to continue) yes
   A   B   C   D   E   F  
Row 1   *   *   X   X   X   X
  
Row 2   *   X   X   *   X   X
  
Row 3   *   *   X   X   X   X
  
Row 4   *   *   X   *   *   X
  
Row 5   *   *   X   *   X   X
  
Row 6   X   *   X   *   X   X
  
Row 7   *   X   X   *   X   X
  
Row 8   *   *   *   *   X   X
  
Row 9   *   *   X   *   X   X
  
Row 10   *   *   *   X   X   X
  
Row 11   *   *   X   *   *   X
  
Row 12   *   *   X   *   X   X
  

   First Class: rows 1 through 2
   Business Class: rows 3 through 7
   Economy Class: rows 8 through 13

Enter ticket type : First

Enter seat number : 1D

Sorry seat not available for seat number 1D. Try another seat...

Do you want to continue booking ?(Type 'QUIT' to exit from menu and 'Yes' to continue) quit
186590cb0725:Chegg bonkv$

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote