45
Introduction The primary objective of this lab project was to create three programs using three different programming languages. The programs were to be made in such a manner so that they produce the same output for a certain input. In simpler terms the programs created were to be identical in terms of utilization. Enforcing one of the suggested topics, the programs created for this project were a set of simple airplane booking systems. The program had specific guidelines stating that the airplane was to be capable of seating up to 200 passengers. Out of these 200, 20 will be seated in first class which is divided into 5 rows of 4 columns each with an aisle in the middle. Similar to this, the 180 remaining passengers will be seated in economy class which is a set of 30 rows of 6 seats each with an aisle in the middle. The program was required to perform three basic tasks including adding passengers, viewing seating arrangement and exiting. The following project report contains a detailed description of the design and logic utilized in order to create the programs. It also contains an appendix section that contains all the code utilized in the programming phase in a well commented order. This is to allow the reader to view and mark the code with ease. The report also discusses the similarities and the differences between the various languages and how they relate to each other performing same tasks. Software Design and Implementation We were required to program our software on three different programming languages. We chose C, C# and Java respectively for that purpose. As described before the languages were to perform the same tasks. C: C is a commonly used programming language in the global industry. Unlike Java and C# also used in the project, it is not object oriented and does not support classes. It supports a console based command prompt in order to communicate with the user. The program used in this project relies heavily on nested loops and functions only. In this scenario, the following functions are used: Dispfir: This function was designed to display the seating in first class. It takes in a five by four array as input. This represents the seats in the first class. All 0 values in the array represents the empty seats whereas the 1s represent the occupied seats. The function utilizes a nested loop in order to scan through the array elements and prints an E or O respectively for empty and occupied seats. It also organizes the seats based on the row and columns alongside their location in the plane. Dispsec: This function is almost the same as dispfir. The only major difference is that it takes in a set of thirty by six array instead. The overall function is the same with the displaying a different set of seats. Printseat: Printseat is an extra function that relies on a case statement. It takes in two integers as input arguments. These represent the location of the seat in the array. The values are passed through a case statement which then based on the location prints the seat number.

coe808 proj repot

Embed Size (px)

Citation preview

Page 1: coe808 proj repot

Introduction

The primary objective of this lab project was to create three programs using three

different programming languages. The programs were to be made in such a manner so that they

produce the same output for a certain input. In simpler terms the programs created were to be

identical in terms of utilization.

Enforcing one of the suggested topics, the programs created for this project were a set of

simple airplane booking systems. The program had specific guidelines stating that the airplane

was to be capable of seating up to 200 passengers. Out of these 200, 20 will be seated in first

class which is divided into 5 rows of 4 columns each with an aisle in the middle. Similar to this,

the 180 remaining passengers will be seated in economy class which is a set of 30 rows of 6 seats

each with an aisle in the middle. The program was required to perform three basic tasks

including adding passengers, viewing seating arrangement and exiting.

The following project report contains a detailed description of the design and logic

utilized in order to create the programs. It also contains an appendix section that contains all the

code utilized in the programming phase in a well commented order. This is to allow the reader to

view and mark the code with ease. The report also discusses the similarities and the differences

between the various languages and how they relate to each other performing same tasks.

Software Design and Implementation

We were required to program our software on three different programming languages.

We chose C, C# and Java respectively for that purpose. As described before the languages were

to perform the same tasks.

C:

C is a commonly used programming language in the global industry. Unlike Java and C#

also used in the project, it is not object oriented and does not support classes. It supports a

console based command prompt in order to communicate with the user. The program used in this

project relies heavily on nested loops and functions only. In this scenario, the following functions

are used:

Dispfir: This function was designed to display the seating in first class. It takes in a five

by four array as input. This represents the seats in the first class. All 0 values in the array

represents the empty seats whereas the 1s represent the occupied seats. The function

utilizes a nested loop in order to scan through the array elements and prints an E or O

respectively for empty and occupied seats. It also organizes the seats based on the row

and columns alongside their location in the plane.

Dispsec: This function is almost the same as dispfir. The only major difference is that it

takes in a set of thirty by six array instead. The overall function is the same with the

displaying a different set of seats.

Printseat: Printseat is an extra function that relies on a case statement. It takes in two

integers as input arguments. These represent the location of the seat in the array. The

values are passed through a case statement which then based on the location prints the

seat number.

Page 2: coe808 proj repot

Booksinglefir: This is used to book a single passenger into first class seating. It takes in

the array representing the seating in first class. It asks for the user input after displaying

the available options asking if the user prefers window or aisle seat. Once the user

decides and inputs the relevant choice, the program will run a set of nested for loops in

order find the relevant empty seat. Once the seat is found, the seat is booked and the

corresponding value in the array is set to 1. The printseat function is called to display the

seat number by sending the coordinates of the location of the seat in the array.

Booksingleeco: Similar to booksinglefir, this function was designed to book a single

passenger into economical class seating. It uses a bigger array representing the

economical class instead of the twenty seat array. Another major difference would

include adding another option that allows the passenger to choose the center seat

alongside the other options of choosing window or aisle seating. Similar to the

booksinglefir, it calls printseat function after booking a seat.

Bookmultifir: This function is used to book multiple passengers into first class seating. It

can allow up to twenty people to book seats in first class. The function takes in the first

class integer array and a number representing the number of passengers to be booked into

the plane. It uses an integer which is initially set to 0. This is the count. A set of for loops

is used to scan through the seats in the array. For every seat that can be booked as a part

of a group, the function increases the count value. If the count value equals too the

number of passengers to be booked, it sets a flag to notify that the booking is available

and notes the value of the last available seat on the array. Another set of for loops is used

in a different manner that goes from the last seat to the first and sets value of every

element in the array to 1 calling the printseat function with every value. This is done till

the number of required seats is booked.

Bookmultieco: This is the multiple booking function of the economy class. Similar to the

bookmultifir function, it takes an integer and the actual economy class array and follows

the same steps as the bookmultifir. Since the economy class allows up to 180 passengers,

up to 180 passengers may be booked into economy class in one turn.

Addpass: this function is used to book passengers into the airplane. The function itself

takes in both the arrays (first class and economy class) as input arguments. The user is

inquired about the number of people travelling together. The user may input an integer

representing the number of passengers to be booked. If the number is not greater than 1,

the user is asked to input if they prefer using first class or economy class in order to

travel. Based on the choice entered, booksinglefir or booksingleeco functions are called

with their respective arrays. If the user has input more than one passenger to be booked, a

similar approach is used however bookmultifir and bookmultieco functions are used

instead. Once the seats are booked and the function finishes executing, the seating

arrangement is displayed.

Main: The main function is executed as the program is run. The function contains a set

of variable declarations that include the arrays representing the first and economy class

Page 3: coe808 proj repot

seating in the plane. The main function begins by running a set of nested for loops to

initialize both seating arrays to zero. This makes sure that there is no value at the array

locations. A while loop is set to run until the user decides to exit and the choices of either

booking seats, displaying seats or exiting is displayed. User input is awaited and based on

the choice of the user, a relevant function is called within the while loop.

Java:

Java is a multiplatform language which is used in various areas such as smart phones and

internet browser based programs. It is highly object oriented and utilizes classes and methods for

executing tasks. In the current project, the following was used for Java programming:

SeatBookingSystem Class: This class is the main class of the whole program. In this

class all the other classes are called in some way shape or form. This class is responsible

for the presentation in the console command window. This class displays the options

available to the user then prompts for input from the user. This class uses the Scanner

class, the boolean class and the AirplaneLayout class. The Scanner class was used to

access the functions for getting user input, the boolean class was used to create variables

used for exiting the program, and lastly the AirplaneLayout class was used for creating

the whole airplane seating layout, seats, grouping logic, and booking logic.

AirplaneLayout Class: This class is the airplane seating layout class, which is

responsible for containing the logic of printing out the layout of the seats. This class

contains and uses 2 variables, 1 variable is from the FirstClass class and the second

variable is from the EconomyClass class. This class contains 5 functions, which are

printfirst, printeconomy, printplane, groupfirst, and grouppeasant. The printfirst function

is used for printing out the seat layout for the first class seats. The printeconomy function

is used for printing out the seat layout for economy class seats. The printplane function is

used for printing out the seat layout for both first class and economy class seats. The

groupfirst function is used for prompting user input for the number of people they are

traveling with. If the user inputs 1 for the number of people traveling, the groupfirst

function would then ask the user if they want a window seat or aisle seat, then book the

seat accordingly. If the user inputs a number greater than 1 for the number of people

traveling, it would then check to see if there are enough seats available to accommodate

the number of people traveling specified and then book the seats accordingly if there are

enough seats, otherwise it would display that there are not enough seats and bring the

user back to the original set of options, which asks if the user wants to book a seat or quit.

The groupeconomy function has the same functionality as the groupfirst function, the

only difference is that it has one more seating option (centre seat) than groupfirst

function.

FirstClass Class: This class is used for creating the seating layout for first class seats

only. This class contains 4 variables, 1 seating class variable and 3 integer variables for

keeping track of the number of available seats. This class contains 3 functions, getTotal,

setTotal, and setSeat. The getTotal function is used for returning the total number of

Page 4: coe808 proj repot

available seats back to the caller of the function. The setTotal function is used for

manually modifying the total number of available seats. The setSeat function is used for

booking a seat.

EconomyClass Class: This class has the exact same functionality as the FirstClass class.

The functions used in this class are the exact same functions used in the FirstClass class.

The variables and the functionality of these variables are also the same as that of

FirstClass class. This class and FirstClass class are the exact same, the only difference

between the FirstClass class and this class is the initial value of the total number of

available seats.

seating Class: This class is used for creating an array of seats according to the

parameters passed to this class. This class contains 1 seats array variable, which is then

given a static size at initialization. This class creates an array of seats according to the

parameters passed to this class at initialization. This class contains 3 functions, getSeat,

setSeat, and getSeating. The getSeat function is used to return the taken value of the seat

located at the array index that was specified by the parameters passed to this function.

The setSeat function is used to book the seat located at the array index that was specified

by the parameters passed to this function. The getSeating function is used for returning

the whole seat array to the caller of the function.

seat Class: This class is used to create the seat object. This class contains 2 variables, an

integer variable and a string variable. The integer variable is used for storing the taken

value, and the string variable is used for identifying the seat type. This class contains 3

functions, getTaken, setTaken, and getPlacement. The getTaken function is used for

returning the taken status of the seat, where ‘1’ stands for taken and ‘0’ stands for not

taken. The setTaken function is used for setting the taken value of the seat to ‘1’ to

signify that the seat has been booked. The getPlacement function is used for returning the

seat type to the caller. There are 3 types of seats, window, centre and aisle.

C#:

C# or C Sharp is another object oriented language which is mostly used in programming

Microsoft based software or framework. Hence making it another important tool in the global

industry. It relies on classes and functions. The C# language is a multi-paradigm programming

language that uses many programming disciplines, such as, strong typing, imperative,

declarative, functional, generic, object-oriented programming, and component-oriented

programming. C# was intended to be suitable for writing applications for both hosted and

embedded systems.

Since C# is very similar to C and C++ in its structure and is an object-oriented language,

several classes were created for this project, a Plane class, Firstseat class and Ecoseat class. The

Plane object creates two 2-D arrays of seat objects that represent the two types of seats, first class

seats and economy class seats that can be booked based on the user’s preference. The Plane class

contains three methods that complete the objectives of the project.

Page 5: coe808 proj repot

showseats: this function shows the seats of the plane according to the occupancy of each

seat and the row it is in. This is done by using a for loop that goes through each of the

arrays and displays the occupancy with an ‘e’ for empty and ‘o’ for occupied.

bookseat: the inputs from the user are used in the parameters. The method takes the seat

class and the position of the seat, it then loops through the chosen class to check for an

available seat that matches the seating selected by the user.

bookseatmany: similar to the book seat function inputs from the user are used as

parameters, but different parameters are used because this function only books the

multiple seats next to each other rather than letting the user pick the position of the seats.

This is done by first checking through the seat class for empty seats, if there are enough

seats then it books the seats. The firstseat class and ecoseat class are the classes that the

plane object uses to manage the seats on the plane. They both use the same functions, but

differ slightly as the two classes handle values differently.

setoccupancy: this function allows the bookseat functions to set the occupancy of the

seat to occupied.

getrow: this function is used to return the row number of the seat.

getseatposition: this function shows the position of the seat object, it shows ‘a’ for the

aisle seat, ‘w’ for the window seat and in the economy class there is also a ‘m’ the middle

seat that is in both columns of seats

getoccupancy: the function is used by the showseat function to show the seats occupancy

Functioning (Booking a Ticket) :

Java:

1. SeatBookingSystem displays 2 options, “book a seat” and “quit”.

Figure 1: Main Menu In Java

2. SeatBookingSystem then prompts user for input.

3. When “book a seat” is selected, SeatBookingSystem calls upon the printplane function

from AirplaneLayout class to display the plane layout, then displays 3 options, “first

class”, “economy class”, and “go back”.

4. If “first class” is chosen SeatBookingSystem would then call the printfirst function from

AirplaneLayout class to display the first class seats, then asks the user how many people

are traveling. If “economy class” is chosen SeatBookingSystem would then call the

printeconomy function from the AirplaneLayout class to display the economy class seats,

then asks the user how many people are traveling.

Page 6: coe808 proj repot

Figure 2: First Class Option

5. If the user inputs ‘1’ as the number of people traveling, the group(first/economy) function

would then ask the user the type of seat is desired (window/aisle for first class and

window/centre/aisle for economy class). Then the function would book the seat accordingly,

by calling the setSeat function from the (First/Economy)Class class, which then calls the

setSeat function from the seating class, which calls the setTaken from the seat class.

6. If the user inputs a number greater than 1 for the number of people traveling, the

group(first/economy) function would then check to see if the number specified exceeds the

number of available seats. If the specified group number is less than or equal to the number

of available seats then the function would book the number of seats specified by calling the

setSeat function from the (First/Economy)Class class, which then calls the setSeat function

from the seating class, which calls the setTaken from the seat class. If the specified group

number exceeds the total available seats, then the group function would display a not

enough seats message and make the user start all over again from the beginning.

Figure 3: Seat Booking for more than 1 Persons

7. After all the seats are booked, the control goes back to the SeatBookingSystem class which

will display all the seats and their availability by calling the printplane function from

AirplaneLayout class again, then display the options available to the user.

Page 7: coe808 proj repot

Figure 4: Quitting in Java

C:

Figure 5: Main Menu in C

1. In C, the program execution is started with the calling of the main function that declares the

arrays to be used and the various variables that will be required for the operation. An

infinitely long loop is run asking the user the action they wish to commence. The options

provided including exiting the program, displaying the seating arrangement and booking

seats.

2. Based on the user input, the main function may call upon addpass, dispfir, dispsec or exit

functions. For adding passengers, addpass is called. In this case, addpass function will be

called upon since the user is booking a seat.

Figure 6: Choosing Passengers and Class

Figure 7: Choosing Window or Aisle Seat

3. Addpass further asks the user the number of passengers that may travel and uses that in

order to set up the next set of questions for user. Once the number is chosen, question

regarding first or economy class is asked and booksinglefir, booksingleeco, bookmultifir or

bookmultieco is called.

4. Either of these functions follow a similar setup of finding a correct match as per the user’s

preferences and then booking the seats. The seat numbers are displayed as the seats are

booked for the user’s convenience. Once the seats are booked, dispfir and ispsec functions

are called in order to display the updated seating arrangement of the airplane.

Page 8: coe808 proj repot

Figure 8: Seat Confirmation

5. The addpass function ends and the while loop is rewound to the main menu asking what the

user would like to do.

C#:

1. The program runs in the Main function, in this function the terminal is used to display

messages that prompts the user to input what they want. It begins by asking the user what

they want to do, the user types in ‘1’ to enter the add a passenger menu, or ‘2’ to show the

plane’s current seating arrangement, or ‘3’ to exit the program.

Figure 9: Main Menu

2. If the add a passenger option is chosen the user is then asked to choose which class they

want ‘f’ for first class and ‘e’ for economy class.

Figure 10: Choosing Class

3. After the class is chosen the program then asks for the number of seats the user wishes to

book.

Figure 11: Choosing Number of Seats

4. If one passenger is inputted the program will then ask for the users seating preference, aisle

or window seat for first class, aisle, window, or middle for economy class.

Figure 12: Choosing Window or Aisle Seat or Middle Seat for Economy Class

Page 9: coe808 proj repot

5. Otherwise the program would book the specified number of passengers, if the seat cannot be

booked the user is notified either no specified seats available or not enough seats available.

Once the seats are booked the program returns to the main menu so that the user can

continue to book more seats or to view the seat they just booked.

Comparison

The following portion discusses the similarities and the differences in the functioning and

the programming of the three programs.

One can observe by the functioning portion of the project, all the programs provided

almost identical output for similar inputs. This makes it easy to conclude that the programs are

behaving in an identical manner in terms of user interaction and output however, we observed

how each one of the programs utilized a similar yet unique approach to the problem provided.

Even though the programs work in a similar manner, they are not exactly the same. Each

program follows a different set of rules along with its syntax which challenges the programmer

to follow a unique manner of programming.

As defined before, C is not object oriented and thus does not support classes. This makes

it difficult for the C language to create structures. Structures are an important building block of

almost any major program and difficulty creating them would definitely impact the program in a

negative manner especially in terms of memory allocation. Compared to Java and C# which rely

on classes, C deals with the problem by declaring and allocating memory within the main

function. Any variable used by a function in C is usually temporary unless stated otherwise. The

program in this case relies heavily on functions and values assigned by functions to be used in

main. Another major difference between C, C# and Java is that the compiler in C does not check

if every called method is correct (Strongly Typed), which increases the overall chances of faults

while programming.

C# has many similarities to C and C++ languages in terms of the structure of code, but

we can also point out that C# uses a completely different means of declaring and initializing two

dimensional arrays that make it a little unconventional for that purpose. Being an object oriented

language does allow room for classes and easy structure definition which is extremely helpful for

the program.

Java takes the best of both worlds and combines them together. It is a multi-platform

object oriented language. It is highly dependent on its use of classes and objects. Creating

structures in Java to perform in a certain manner is extremely simple compared to the other two

languages and thus allows a large amount of flexibility to the programmer. Even though the

extensive ability of Java to create a GUI by simple means wasn’t utilized fully in this program

and major commands were based on a console, having those abilities also makes java more user

friendly than its competitors.

Page 10: coe808 proj repot

Conclusion

The objective of this project was to create the same program using three different

programming languages. The three different programming languages used were C programming

language, the object oriented C# programming language, and lastly the object oriented JAVA

programming language. The purpose of writing the same program in three different

programming languages, was to do a comparison of the three different programming languages.

This project was designed to compare the three different programming languages, to observe the

differences between the three different programming languages and to observe the similarities

between the three different programming languages.

The major difference between C programming language and JAVA and C# was that C is

not object oriented where JAVA and C# are. This means that C programming languages does not

support Classes, which are essentially an easier way of creating structures. This also affects the C

program negatively as it adds to the lines of code in order to initialize values and variables. Apart

from the differences mentioned above, majority of the programming portion of the project was

similar in many ways including the logic used in order to book seats and display seating

arrangement.

References:

[1]C. Yang, 'Lecture Notes Coe 808', Dept. of Electrical and Computer Engineering © Ryerson

University, Toronto, Canada, 2015., 2015., ee.ryerson.ca

Page 11: coe808 proj repot

Appendix 1

The following portion of the report contains the full set of code which is commented and

indented for easy viewing and marking. This code was utilized in order to create the three

programs used in this project. They are as follows:

Java:

AirplaneLayout Class

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package seatbookingsystem;

import java.util.*;

/**

*

* @author Yuming

*/

public class AirplaneLayout {

FirstClass first; //array of first class seats

EconomyClass peasant; //array of economy class seats

public AirplaneLayout() { //object constructor

this.first=new FirstClass();

this.peasant=new EconomyClass();

}

public void printfirst(){ //prints first class seat layout

int i;

System.out.println("\t\tFirst Class");

System.out.println("\tRows\tA B\tC D\tRows");

for(i=0;i<5;i++){

System.out.println("\t"+i+"\t"+first.first.getSeat(i, 0)+" "+first.first.getSeat(i,

1)+"\t"+first.first.getSeat(i, 2)+" "+first.first.getSeat(i, 3)+"\t"+i);

}

System.out.println("\tRows\tA B\tC D\tRows");

}

public void printeconomy(){ //prints economy class layout

int i;

System.out.println("\t\tEconomy Class");

Page 12: coe808 proj repot

System.out.println("\tRows\tABC\tDEF\tRows");

for(i=0;i<30;i++){

System.out.println("\t"+i+"\t"+peasant.economy.getSeat(i,

0)+peasant.economy.getSeat(i, 1)+peasant.economy.getSeat(i,

2)+"\t"+peasant.economy.getSeat(i, 3)+peasant.economy.getSeat(i,

4)+peasant.economy.getSeat(i, 5)+"\t"+i);

}

System.out.println("\tRows\tABC\tDEF\tRows");

}

public void printplane(){ //prints both first and economy class layout

printfirst();

printeconomy();

}

public void groupfirst(){ //function used to deal with booking seats in first class

Scanner userinput = new Scanner(System.in);

int group, options, i=0, j=0, x;

group=userinput.nextInt();

x=group;

if(group>this.first.total){

System.out.println("Sorry, not enough First Class seats are available.");

return;

}

else if(group==1){

System.out.println("Please enter desired seating:\n1) Aisle\n2) Window");

options=userinput.nextInt();

if(options==1){

if(this.first.aisle==0){

System.out.println("Sorry, all aisle seats have been booked.");

return;

}

else{

for(i=0;i<5;i++){

for(j=0;j<4;j++){

if(this.first.first.seats[i][j].taken==0 &&

this.first.first.seats[i][j].placement.equalsIgnoreCase("aisle") && x!=0){

this.first.first.setSeat(i, j);

x--;

this.first.aisle--;

}

Page 13: coe808 proj repot

}

}

this.first.total--;

}

}

else if(options==2){

if(this.first.window==0){

System.out.println("Sorry, all window seats have been booked.");

return;

}

else{

for(i=0;i<5;i++){

for(j=0;j<4;j++){

if(this.first.first.seats[i][j].taken==0 &&

this.first.first.seats[i][j].placement.equalsIgnoreCase("window") && x!=0){

this.first.first.setSeat(i, j);

x--;

this.first.window--;

}

}

}

this.first.total--;

}

}

return;

}

else if(group<=this.first.total && group>1){

for(i=0;i<5;i++){

for(j=0;j<4;j++){

if(this.first.first.seats[i][j].taken==0 && x!=0){

this.first.first.setSeat(i, j);

x--;

this.first.total--;

}

}

}

return;

}

else{

System.out.println("Group size not accepted.");

Page 14: coe808 proj repot

return;

}

}

public void grouppeasant(){ //function used to deal with booking seats in economy class

Scanner userinput = new Scanner(System.in);

int group, options, i=0, j=0, x;

group=userinput.nextInt();

x=group;

if(group>this.peasant.total){

System.out.println("Sorry, not enough Economy Class seats are available.");

return;

}

else if(group==1){

System.out.println("Please enter desired seating:\n1) Aisle\n2) Centre\n3) Window");

options=userinput.nextInt();

if(options==1){

if(this.peasant.aisle==0){

System.out.println("Sorry, all aisle seats have been booked.");

return;

}

else{

for(i=0;i<30;i++){

for(j=0;j<6;j++){

if(this.peasant.economy.seats[i][j].taken==0 &&

this.peasant.economy.seats[i][j].placement.equalsIgnoreCase("aisle") && x!=0){

this.peasant.economy.setSeat(i, j);

x--;

this.peasant.aisle--;

}

}

}

this.peasant.total--;

}

}

else if(options==2){

if(this.peasant.centre==0){

System.out.println("Sorry, all centre seats have been booked.");

return;

}

else{

Page 15: coe808 proj repot

for(i=0;i<30;i++){

for(j=0;j<6;j++){

if(this.peasant.economy.seats[i][j].taken==0 &&

this.peasant.economy.seats[i][j].placement.equalsIgnoreCase("centre") && x!=0){

this.peasant.economy.setSeat(i, j);

x--;

this.peasant.centre--;

}

}

}

this.peasant.total--;

}

}

else if(options==3){

if(this.peasant.window==0){

System.out.println("Sorry, all window seats have been booked.");

return;

}

else{

for(i=0;i<30;i++){

for(j=0;j<6;j++){

if(this.peasant.economy.seats[i][j].taken==0 &&

this.peasant.economy.seats[i][j].placement.equalsIgnoreCase("window") && x!=0){

this.peasant.economy.setSeat(i, j);

x--;

this.peasant.window--;

}

}

}

this.peasant.total--;

}

}

return;

}

else if(group<=this.peasant.total && group>1){

for(i=0;i<30;i++){

for(j=0;j<6;j++){

if(this.peasant.economy.seats[i][j].taken==0 && x!=0){

this.peasant.economy.setSeat(i, j);

x--;

Page 16: coe808 proj repot

this.peasant.total--;

}

}

}

return;

}

else{

System.out.println("Group size not accepted.");

return;

}

}

}

EconomyClass Class

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package seatbookingsystem;

/**

*

* @author Yuming

*/

public class EconomyClass {

seating economy; //economy seating arrangement

int total = 180, window=60, centre=60, aisle=60; //variables for number of seats

available

public EconomyClass() { //object constructor

this.economy = new seating(30,6);

}

public int getTotal() { //gets total remaining seats

return total;

}

public void setTotal(int total) { //sets total of remaining seats

this.total = total;

}

Page 17: coe808 proj repot

public void setSeat(int i, int j){ //books a seat

this.economy.setSeat(i, j);

}

}

FirstClass Class

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package seatbookingsystem;

/**

*

* @author Yuming

*/

public class FirstClass {

seating first; //array of seats

int total=20, aisle=10, window=10; //variables for number of available seats

public FirstClass() { //object constructor

this.first = new seating(5,4);

}

public int getTotal() { //return total available seats

return total;

}

public void setTotal(int total) { //changes number of available seats

this.total = total;

}

public void setSeat(int i,int j){ //books seat

this.first.setSeat(i, j);

}

}

SeatBookingSystem Class

/*

Page 18: coe808 proj repot

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package seatbookingsystem;

import java.util.*;

/**

*

* @author Yuming

*/

public class SeatBookingSystem {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

Scanner userinput = new Scanner(System.in); //scanner variable used to get user

input

boolean quit=false, quit2=false; //boolean variables used for quiting menu

loops

AirplaneLayout plane = new AirplaneLayout(); //airplanelayout class variable used

to create layout and contains booking methods

int options, options2; //used for menu

System.out.println("Welcome to the airplane seat booking system.\nPlease select the

desired option");

System.out.println("1) Book a seat\n2) Quit");

options=userinput.nextInt(); //user input for menu selection

while(quit!=true){ //continue until user states quit

if(options==1){ //1st option

quit2=false; //set exit parameter for 2nd set of options to false for extra measure

System.out.println("option 1");

plane.printplane(); //prints seating layout of whole plane

System.out.println("1) First Class\n2) Economy Class\n3) Go Back");

options2=userinput.nextInt();

while(quit2!=true){ //loop for 2nd set of options

if(options2==1){ //1st option for 2nd set of options

plane.printfirst(); //printf layout for first class only

System.out.println("Enter the amount of people of travel:");

plane.groupfirst(); //function used to book seat(s) for first class only

plane.printfirst();

Page 19: coe808 proj repot

options2=3; //third option used to go back to 1st set of options

}

else if(options2==2){ //2nd option for 2nd set of options

plane.printeconomy(); //print layout for economy class only

System.out.println("Enter the amount of people of travel:");

plane.grouppeasant(); //function used to book seat(s) for economy class only

plane.printeconomy();

options2=3;

}

else{ //exit option

quit2=true; //used to exit 2nd set of options

options=3; //used to display 1st set of options

}

}

}

else if(options==2){ //2nd option for 1st set of options

System.out.println("Thank you for using the airplane seat booking system, have a

nice day.");

quit=true; //set quit to true to exit program

}

else{

System.out.println("Welcome to the airplane seat booking system.\nPlease select the

desired option");

System.out.println("1) Book a seat\n2) Quit");

options=userinput.nextInt();

}

}

}

}

seat Class

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package seatbookingsystem;

/**

*

* @author Yuming

Page 20: coe808 proj repot

*/

public class seat {

int taken; //variable for identifying if seat is taken or not

String placement; //seat placement variable (eg. window, aisle, or centre)

public seat(int taken, String placement) { //object constructor

this.taken = taken;

this.placement = placement;

}

public int getTaken() { //returns taken variable

return taken;

}

public void setTaken(int taken) { //sets the seat to booked

this.taken = taken;

}

public String getPlacement() { //gets what kind of seat it is (eg. window, aisle, or

centre)

return placement;

}

}

seating Class

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package seatbookingsystem;

/**

*

* @author Yuming

*/

public class seating { //seating array class

seat[][] seats; //array of seats

public seating(int i, int j) { //object constructor

this.seats = new seat[i][j];

Page 21: coe808 proj repot

int x,y;

if(j==4){

for(x=0;x<i;x++){

for(y=0;y<j;y++){

if(y==0){

this.seats[x][y]=new seat(0,"window");

}

else if(y==1){

this.seats[x][y]=new seat(0,"aisle");

}

else if(y==2){

this.seats[x][y]=new seat(0,"aisle");

}

else{

this.seats[x][y]=new seat(0,"window");

}

}

}

}

else if(j==6){

for(x=0;x<i;x++){

for(y=0;y<j;y++){

if(y==0){

this.seats[x][y]=new seat(0,"window");

}

else if(y==1){

this.seats[x][y]=new seat(0,"centre");

}

else if(y==2){

this.seats[x][y]=new seat(0,"aisle");

}

else if(y==3){

this.seats[x][y]=new seat(0,"aisle");

}

else if(y==4){

this.seats[x][y]=new seat(0,"centre");

}

else{

this.seats[x][y]=new seat(0,"window");

}

Page 22: coe808 proj repot

}

}

}

}

public int getSeat(int i, int j){ //returns seat taken value

return this.seats[i][j].getTaken();

}

public void setSeat(int i, int j){ //books the seat

this.seats[i][j].setTaken(1);

}

public seat[][] getSeating(){ //returns the array

return this.seats;

}

}

C#:

using System.IO;

using System;

namespace FlightBooking{

class Plane{

public int i,j;

firstseat[,] firstclass = new firstseat [5,4]{ //initializing the array for the first class seating

{new firstseat('w',1), new firstseat('a',1), new firstseat('a',1), new firstseat('w',1)},

{new firstseat('w',2), new firstseat('a',2), new firstseat('a',2), new firstseat('w',2)},

{new firstseat('w',3), new firstseat('a',3), new firstseat('a',3), new firstseat('w',3)},

{new firstseat('w',4), new firstseat('a',4), new firstseat('a',4), new firstseat('w',4)},

{new firstseat('w',5), new firstseat('a',5), new firstseat('a',5), new firstseat('w',5)}

};

ecoseat[,] economyclass = new ecoseat [30,6]{ //initializing the array for the economy

class seating

{new ecoseat('w',1), new ecoseat('m',1), new ecoseat('a',1), new ecoseat('a',1),

new ecoseat('m',1), new ecoseat('w',1)},

Page 23: coe808 proj repot

{new ecoseat('w',2), new ecoseat('m',2), new ecoseat('a',2), new ecoseat('a',2),

new ecoseat('m',2), new ecoseat('w',2)},

{new ecoseat('w',3), new ecoseat('m',3), new ecoseat('a',3), new ecoseat('a',3),

new ecoseat('m',3), new ecoseat('w',3)},

{new ecoseat('w',4), new ecoseat('m',4), new ecoseat('a',4), new ecoseat('a',4),

new ecoseat('m',4), new ecoseat('w',4)},

{new ecoseat('w',5), new ecoseat('m',5), new ecoseat('a',5), new ecoseat('a',5),

new ecoseat('m',5), new ecoseat('w',5)},

{new ecoseat('w',6), new ecoseat('m',6), new ecoseat('a',6), new ecoseat('a',6),

new ecoseat('m',6), new ecoseat('w',6)},

{new ecoseat('w',7), new ecoseat('m',7), new ecoseat('a',7), new ecoseat('a',7),

new ecoseat('m',7), new ecoseat('w',7)},

{new ecoseat('w',8), new ecoseat('m',8), new ecoseat('a',8), new ecoseat('a',8),

new ecoseat('m',8), new ecoseat('w',8)},

{new ecoseat('w',9), new ecoseat('m',9), new ecoseat('a',9), new ecoseat('a',9),

new ecoseat('m',9), new ecoseat('w',9)},

{new ecoseat('w',10), new ecoseat('m',10), new ecoseat('a',10), new

ecoseat('a',10), new ecoseat('m',10), new ecoseat('w',10)},

{new ecoseat('w',11), new ecoseat('m',11), new ecoseat('a',11), new

ecoseat('a',11), new ecoseat('m',11), new ecoseat('w',11)},

{new ecoseat('w',12), new ecoseat('m',12), new ecoseat('a',12), new

ecoseat('a',12), new ecoseat('m',12), new ecoseat('w',12)},

{new ecoseat('w',13), new ecoseat('m',13), new ecoseat('a',13), new

ecoseat('a',13), new ecoseat('m',13), new ecoseat('w',13)},

{new ecoseat('w',14), new ecoseat('m',14), new ecoseat('a',14), new

ecoseat('a',14), new ecoseat('m',14), new ecoseat('w',14)},

{new ecoseat('w',15), new ecoseat('m',15), new ecoseat('a',15), new

ecoseat('a',15), new ecoseat('m',15), new ecoseat('w',15)},

{new ecoseat('w',16), new ecoseat('m',16), new ecoseat('a',16), new

ecoseat('a',16), new ecoseat('m',16), new ecoseat('w',16)},

{new ecoseat('w',17), new ecoseat('m',17), new ecoseat('a',17), new

ecoseat('a',17), new ecoseat('m',17), new ecoseat('w',17)},

{new ecoseat('w',18), new ecoseat('m',18), new ecoseat('a',18), new

ecoseat('a',18), new ecoseat('m',18), new ecoseat('w',18)},

{new ecoseat('w',19), new ecoseat('m',19), new ecoseat('a',19), new

ecoseat('a',19), new ecoseat('m',19), new ecoseat('w',19)},

{new ecoseat('w',20), new ecoseat('m',20), new ecoseat('a',20), new

ecoseat('a',20), new ecoseat('m',20), new ecoseat('w',20)},

{new ecoseat('w',21), new ecoseat('m',21), new ecoseat('a',21), new

ecoseat('a',21), new ecoseat('m',21), new ecoseat('w',21)},

Page 24: coe808 proj repot

{new ecoseat('w',22), new ecoseat('m',22), new ecoseat('a',22), new

ecoseat('a',22), new ecoseat('m',22), new ecoseat('w',22)},

{new ecoseat('w',23), new ecoseat('m',23), new ecoseat('a',23), new

ecoseat('a',23), new ecoseat('m',23), new ecoseat('w',23)},

{new ecoseat('w',24), new ecoseat('m',24), new ecoseat('a',24), new

ecoseat('a',24), new ecoseat('m',24), new ecoseat('w',24)},

{new ecoseat('w',25), new ecoseat('m',25), new ecoseat('a',25), new

ecoseat('a',25), new ecoseat('m',25), new ecoseat('w',25)},

{new ecoseat('w',26), new ecoseat('m',26), new ecoseat('a',26), new

ecoseat('a',26), new ecoseat('m',26), new ecoseat('w',26)},

{new ecoseat('w',27), new ecoseat('m',27), new ecoseat('a',27), new

ecoseat('a',27), new ecoseat('m',27), new ecoseat('w',27)},

{new ecoseat('w',28), new ecoseat('m',28), new ecoseat('a',28), new

ecoseat('a',28), new ecoseat('m',28), new ecoseat('w',28)},

{new ecoseat('w',29), new ecoseat('m',29), new ecoseat('a',29), new

ecoseat('a',29), new ecoseat('m',29), new ecoseat('w',29)},

{new ecoseat('w',30), new ecoseat('m',30), new ecoseat('a',30), new

ecoseat('a',30), new ecoseat('m',30), new ecoseat('w',30)}

};

//bookseat a method that books a seat based on the class and position stated

//by checking for an open seat that matches the position and

//class to be empty and the same as what the user wants

//then books the seat

void bookseat(char classtype, char position){

int booked=0;

if(classtype=='f'){

for(i=0;i<5;i++){

for(j=0;j<4;j++){

if(booked==1){

break;

}

if(firstclass[i,j].getseatposition()==position &&

firstclass[i,j].getoccupancy()=='e'){

firstclass[i,j].setoccupancy('o');

booked++;

}

}

}

}

Page 25: coe808 proj repot

if(classtype=='e'){

for(i=0;i<30;i++){

for(j=0;j<6;j++){

if(booked==1){

break;

}

if(economyclass[i,j].getseatposition()==position &&

economyclass[i,j].getoccupancy()=='e'){

economyclass[i,j].setoccupancy('o');

booked++;

}

}

}

}

if(booked==0){

Console.WriteLine("Sorry no seat found please try again");

}

}

//bookseatmany a method that books a seat based on the class and

//the number of people by checking for the same number of open

//seats that the user inputs then books the seats in order

void bookseatmany(char classtype, int numpeople){

int i,j,k,l=0;

int booking=0;

int booked=3;

int check=numpeople;

Console.WriteLine(classtype);

Console.WriteLine(numpeople);

if(booking==0){

if(classtype=='f'){

for(i=0;i<5;i++){

for(j=0;j<4;j++){

if(firstclass[i,j].getoccupancy()=='e'){

booking++;

if(booking==check){

booked=0;

for(k=0;k<5;k++){

for(l=0;l<4;l++){

if(booked==numpeople){

Page 26: coe808 proj repot

break;

}

if(firstclass[k,l].getoccupancy()=='e'){

firstclass[k,l].setoccupancy('o');

booked++;

}

}

}

}

Console.WriteLine(booking);

}

}

}

}

if(classtype=='e'){

for(i=0;i<30;i++){

for(j=0;j<6;j++){

if(economyclass[i,j].getoccupancy()=='e'){

booking++;

if(booking==check){

booked=0;

for(k=0;k<30;k++){

for(l=0;l<6;l++){

if(booked==numpeople){

break;

}

if(economyclass[k,l].getoccupancy()=='e'){

economyclass[k,l].setoccupancy('o');

booked++;

}

}

}

}

Console.WriteLine(numpeople);

}

Page 27: coe808 proj repot

}

}

}

}

if(booking==0){

Console.WriteLine("Sorry no seats available");

}

}

//showseats method prints out the seats of the plane showing

//empty and booked seats and indicates the row number

void showseats(){

Console.WriteLine(" Seats Row");

for(i=0;i<5;i++){

Console.Write(" ");

for(j=0;j<4;j++){

if(j==2){

Console.Write(" ");

}

Console.Write(firstclass[i,j].getoccupancy());

}

Console.Write(" "+(i+1));

Console.WriteLine();

}

Console.WriteLine();

for(i=0;i<30;i++){

Console.Write(" ");

for(j=0;j<6;j++){

if(j==3){

Console.Write(" ");

}

Console.Write(economyclass[i,j].getoccupancy());

}

Console.Write(" "+(i+1));

Console.WriteLine();

}

}

static void Main(string [] args){

int menu=0;

int chose=0;

int numpassengers=0;

Page 28: coe808 proj repot

char seattype='f';

int seatchosen=0;

char seatposition;

string input;

Plane flight = new Plane(); //create a plane object

flight.showseats();

Console.WriteLine("Hello, Welcome to our plane booking program");

while(menu>=0){

if(menu==0){ //main menu

Console.WriteLine("Enter Menu:");

Console.WriteLine("1.Add Passenger");

Console.WriteLine("2.Show Seating");

Console.WriteLine("3.Exit Program");

input = Console.ReadLine(); //taking user input

chose = Convert.ToInt32(input); //converting input to integer

if(chose==1){

menu=1;

}

else if(chose==2){

menu=0;

flight.showseats();

}

else if(chose==3){

return;

}

else{

Console.WriteLine("Please Enter a valid input");

menu=0;

}

}

else if(menu==1){ //options for type of seating first or economy class

Console.WriteLine("Please Enter Seat Class:");

Console.WriteLine("First Class (f)");

Console.WriteLine("Economy Class (e)");

Console.WriteLine("To Go Back to Previous Menu (b)");

input = Console.ReadLine();

seattype = Convert.ToChar(input);//converting input to char

if(seattype=='f'){

menu=2;

seatchosen=1;

Page 29: coe808 proj repot

}

else if(seattype=='e'){

menu=2;

seatchosen=2;

}

else if(seattype=='b'){

menu=0;

}

else{

Console.WriteLine("Please Enter a valid input");

menu=1;

}

}

else if(menu==2){ //asking for the number of passenger

Console.WriteLine("Please Enter The Number of Seats to Book:");

Console.WriteLine("To Go Back to Previous Menu (0)");

input = Console.ReadLine();

numpassengers = Convert.ToInt32(input);

if(numpassengers==0){

menu=1;

}

else if(numpassengers==1){

menu=3;

}

else if(numpassengers>=2){

flight.bookseatmany(seattype, numpassengers);

menu=0;

}

else{

Console.WriteLine("Please Enter a valid input");

menu=2;

}

}

else if(menu==3){ //choosing the preferred seating in the class

Console.WriteLine("Please Enter The Preference of Seat to Book:");

if(seatchosen==1){

Console.WriteLine("Window Seat (w)");

Console.WriteLine("Aisle Seat (a)");

}

else if(seatchosen==2){

Page 30: coe808 proj repot

Console.WriteLine("Window Seat (w)");

Console.WriteLine("Middle Seat (m)");

Console.WriteLine("Aisle Seat (a)");

}

Console.WriteLine("To Go Back to Previous Menu (0)");

input = Console.ReadLine();

seatposition = Convert.ToChar(input);

flight.bookseat(seattype, seatposition);

menu=0;

}

}

}

//defining the object of first class seat and its methods

public class firstseat(char position, int inrow){

char positiontype=position;

char occupancy='e';

int row=inrow;

public void setoccupancy(char input){

occupancy = input;

}

public int getrow(){

return row;

}

public char getseatposition(){

return positiontype;

}

public char getoccupancy(){

return occupancy;

}

}

//defining the object of economy class seat and its methods

public class ecoseat(char position, int inrow){

char positiontype=position;

char occupancy='e';

int row=inrow;

public void setoccupancy(char input){

occupancy = input;

}

Page 31: coe808 proj repot

public int getrow(){

return row;

}

public char getseatposition(){

return positiontype;

}

public char getoccupancy(){

return occupancy;

}

}

}

}

C:

#include<stdio.h>

/*Function to Display Seating in first class*/

void dispfir(int arr[5][4])

{

int i, j;

printf("\nFirst Class \n");

printf(" AB CD \n"); //Alphabetical Desiplay of Columns in Seating

for(i = 0; i < 5; i++) //Loop to go through Rows of Seats

{

for(j = 0; j < 4; j++) //Loop to go through Seats in each Row

{

if(j == 2)

{

printf(" "); //Aisle Difference

}

else if(j == 0)

{

printf("%d |",(i + 1)); //Printing Plane Outline With Row Num

}

if(arr[i][j] == 0) //0 Represents Unoccupied

{

printf("E"); //Displaying Seat is empty

}

else

{

printf("O"); //Displaying Seat is Occupied

}

if(j == 3) //Reaching End of Column in a row

Page 32: coe808 proj repot

{

printf("| %d",(i + 1)); //Displaying Plane Outlinewith Row Num

}

}

printf("\n");

}

}

/*Display Function for Economy Class*/

void dispsec(int arr[30][6])

{

int i,j;

printf("\nEconomy Class \n");

printf("Rows \n");

printf(" ABC DEF \n"); //Alphabetical Desiplay of Columns in Seating

for(i = 0; i < 30; i++) //Loop to go through Rows of Seats

{

for(j = 0; j < 6; j++)

{

if(j == 3)

{

printf(" "); //Aisle Spacing

}

else if((j == 0)&&( i< 9))

{

printf("%d |",(i + 1)); //Plane Outline Alongside Row Num

}

else if((j == 0)&&(i >= 9))

{

printf("%d|",(i + 1));

}

if(arr[i][j] == 0) //0 Represents Unnoccupied

{

printf("E"); //Printing that the seat is empty

}

else if(arr[i][j]==1)

{

printf("O"); //Printing That the Seat is occupied

}

if((j == 5) && (i < 9))

{

printf("| %d",(i + 1)); //Plane OutLine and Row Num

}

else if((j == 5) && (i>=9))

{

Page 33: coe808 proj repot

printf("|%d",(i + 1)); //Plane outline and Row num

}

}

printf("\n");

}

}

/*Function for printing Seat Number*/

void printseat(int i, int j)

{

switch(j) //Function uses the Value of J in a switch statement

and determines the corrusponding Column

{

case 0 :

printf("A %d", (i + 1));

break; case 1:

printf("B %d",(i + 1));

break;

case 2 :

printf("C %d",(i + 1));

break;

case 3 :

printf("D %d",(i + 1));

break;

case 4 :

printf("E %d",(i + 1));

break;

case 5 :

printf("F %d",(i + 1));

break; }

printf("\n");

}

/*Function To Book A single Person in First Class*/

void booksinglefir(int arr[5][4])

{

int i, j, n, flag;

flag = 0;

printf("\nFlight Seat Booking System \n");

Page 34: coe808 proj repot

printf("Would you Prefer a Window Seat or an Aisle Seat?");//Message to User

printf("\nPlease Enter -> \n");

printf("1: Window \n");

printf("2: Aisle \n");

scanf("%d",&n); //User's Preference Input

if(n == 1) //Window Selected

{

for(i = 0; i < 5; i++)

{

for(j = 0; j < 4; j++)

{

if(((j==0)||(j==3))&&(arr[i][j]==0)) //Searching for Empty Window S

{

arr[i][j] = 1; //Occupying Seat

flag = 1; //Setting up Flag

break;

}

if(flag == 1) //If seat is found, break out of loop

{

break;

}

}

if(flag == 1) //If seat is found, break out of loop

{

break;

}

}

}

else if(n == 2)

{

for(i == 0; i < 5; i++)

{

for(j = 0; j < 4; j++)

{

if(((j == 1) || (j==2))&&(arr[i][j]==0))//Searching For Empty Aisle S

{

arr[i][j] = 1; //Occupying Seat

flag = 1; //Setting up flag

break;

}

if(flag == 1) //If seat is found, break out of loop

{

break;

}

}

if(flag == 1) //If seat is found, break out of loop

Page 35: coe808 proj repot

{

break;

}

}

}

if(flag == 1)

{

printf("Your seat has been confirmed in our first class \n");

printseat(i,j);

}

else

{

printf("We're Sorry but we seem to be overbooked for that seating preference \n");

printf("Redirecting to Main Menu \n");

printf("Please Try again with a different preference \n");

}

}

/*Function to Book a Single Person in Economy Class*/

void booksingleecon(int arr[30][6])

{

int i, j, n, flag;

flag = 0;

printf("\nFlight Seat Booking System \n");

printf("Would you Prefer a Window Seat, Center Or an Aisle Seat?");

printf("\nPlease Enter -> \n");

printf("1: Window \n");

printf("2: Aisle \n");

printf("3: Center \n");

scanf("%d",&n); //User's Preference Input

if(n == 1) //Window Selected

{

for(i = 0; i < 30; i++)

{

for(j = 0; j < 6; j++)

{

if(((j==0)||(j==5))&&(arr[i][j]==0)) //Searching for Empty Window S

{

arr[i][j] = 1; //Occupying Seat

flag = 1; //Setting up flag

break;

}

if(flag == 1) //If seat is found, Break out of loop

{

break;

}

}

Page 36: coe808 proj repot

if(flag == 1) //If seat is found, break out of loop

{

break;

}

}

}

else if(n == 2)

{

for(i == 0; i < 30; i++)

{

for(j = 0; j < 6; j++)

{

if(((j == 2) || (j==3))&&(arr[i][j]==0))//Searching For Empty Aisle S

{

arr[i][j] = 1; //Occupying Seat

flag = 1; //Setting up flag

break;

}

if(flag == 1) //If seat is found, break out of loop

{

break;

}

}

if(flag == 1) //If seat is found, break out of loop

{

break;

}

}

}

else if(n == 3)

{

for(i == 0; i < 30; i++)

{

for(j = 0; j < 6; j++)

{

if(((j == 1) || (j==4))&&(arr[i][j]==0))//Searching For Empty Aisle S

{

arr[i][j] = 1; //Occupying Seat

flag = 1; //Setting up Flag

break;

}

if(flag == 1) //If seat is found, break out of loop

{

break;

}

}

Page 37: coe808 proj repot

if(flag == 1) //If seat is found, break out of loop

{

break;

}

}

}

if(flag == 1) //Message in Case Seat is Booked

{

printf("Your seat has been confirmed in our first class \n");

printseat(i,j);

}

else //Message in case seat is

unavailable.

{

printf("We're Sorry but we seem to be overbooked for that seating preference \n");

printf("Redirecting to Main Menu \n");

printf("Please Try again with a different preference \n");

}

}

/*First Class Group Bookings*/

void bookmultifir(int arr[5][4], int n)

{

int i, j, flag, count;

int pot, ato;

int flo = 0;

count = 0;

flag = 0;

for( i = 0; i < 5; i++)

{

for(j = 0; j < 4; j++)

{

if(arr[i][j]==0)

{

++count;

}

else

{

count = 0;

}

if(count == n)

{

flag = 1;

pot = i;

ato = j;

break;

Page 38: coe808 proj repot

}

}

if(flag == 1)

{

break;

}

}

if(flag == 1)

{

printf("Seats are available. Beginning booking \n");

printf("Your seats are -> \n");

for(i = 4; i >= 0; i--)

{

for(j = 3; j >= 0; j--)

{

if((i==pot)&&(j==ato))

{

flo = 1;

}

if(flo == 1)

{

arr[i][j] = 1;

printseat(i,j);

printf("\n");

count--;

}

if(count == 0)

{

break;

}

}

if(count == 0)

{

break;

}

}

}

else

{

printf("Group booking isn't avaialbe for the number of passengers\n");

printf("Please Try Individual Booking \n");

}

}

/*Function for Booking Multiple Passengers on Economy class*/

void bookmultieco(int arr[30][6], int n)

{

Page 39: coe808 proj repot

int i, j, flag, count;

int pot, ato;

int flo = 0;

flag = 0;

count = 0;

for(i = 0; i < 30; i++)

{

for(j = 0; j < 6; j++)

{

if(arr[i][j] == 0)

{

count++;

}

else

{

count = 0;

}

if(count == n)

{

flag = 1;

pot = i;

ato = j;

break;

}

}

if(flag == 1)

{

break;

}

}

if(flag == 1)

{

printf("Seats are available. Beginning booking \n");

printf("Your seats are -> \n");

for(i = 29; i >= 0; i--)

{

for(j = 5; j >= 0; j--)

{

if((i==pot)&&(j==ato))

{

flo = 1;

}

if(flo == 1)

{

arr[i][j] = 1;

printseat(i,j);

Page 40: coe808 proj repot

printf("\n");

count--;

}

if(count == 0)

{

break;

}

}

if(count == 0)

{

break;

}

}

}

else

{

printf("Group booking isn't avaialbe for the number of passengers\n");

printf("Please Try Individual Booking \n");

}

}

/*Function to Add Passenger*/

void addpass(int arr[5][4], int brr[30][6])

{

int i, j;

int n, m;

printf("Welcome to Flight Seat Booking System \n");

printf("Please Enter the number of passengers you wish to book in ->\n");

scanf("%d",&n);

if(n == 1)

{

printf("Do you Prefer to Travel first class or Economy? \n");

printf("1 : First \n");

printf("2 : Economy \n");

scanf("%d",&n);

if(n == 1)

{

booksinglefir(arr);

}

else if(n == 2)

{

booksingleecon(brr);

}

}

else

{

printf("Do you prefer first class or economy ? \n");

Page 41: coe808 proj repot

printf("1 : First \n");

printf("2 : Economy \n");

scanf("%d",&m);

if(m == 1)

{

bookmultifir(arr,n);

}

else

{

bookmultieco(brr,n);

}

}

dispfir(arr);

dispsec(brr);

}

/*main Function*/

void main()

{

int i, j;

int brr[30][6]; //Array representing

economy class Seating

int arr[5][4]; //Array representing first

class Seating

int flag = 0;

int choice = 0;

for(i = 0; i < 5; i++) //Loop to empty the array

{

for(j = 0; j < 4; j++)

{

arr[i][j] = 0;

}

}

for(i = 0; i < 30; i++) //Loops to empty the array

{

for(j = 0; j < 6; j++)

{

brr[i][j] = 0;

}

}

while(flag != 1)

{

printf("\nWelcome to Flight Seat Booking System \n\n");

printf("what would you like to do? \n");

printf("1 : Display Seating \n");

printf("2 : Book Seats \n");

printf("3 : Exit\n");

Page 42: coe808 proj repot

scanf("%d",&choice);

if(choice == 1)

{

dispfir(arr);

dispsec(brr);

}

else if(choice == 2)

{

addpass(arr,brr);

}

else if(choice == 3)

{

flag = 1;

break;

}

}

}

Page 43: coe808 proj repot

Appendix 2

The following section of the project contains the UMLs utilized in the creation of the

Java portion of the project. They act as a means to provide an easier understanding of the

functioning and the configuration of the program.

A- Figure 1 : Activity Diagram

A-Figure 2 : Use Case Diagram

Page 44: coe808 proj repot

A Figure 3: Class Diagram

Page 45: coe808 proj repot

A Figure 4: Sequence Diagram