Airline Reservation System

hi guys im a newbie in programing... im geting a very hard time just to understand this course all about.. i just tried to visit this site to learn more about proraming.. and our first acitvity is to make a simple airline reservation system... the problem goes like this:

A small airline has just purchased a computer for its new automated reservation system. You have been asked to program the new system. You are to write a program to assign seats n each flight of the airlines only plane (capacity 10 seats).

the program should display the following menu of alternatives:

Please type 1 for "smoking"
Please type 2 fon "nonsmoking"

if the person types 1 then your program should assign a seat in the smoking section (seats 1-5)
if the person types 2 then the program should assign a seat in the nonsmoking section (seats 6-10)
the program should then print boarding pass idicating the persons seat no. and whether it is in the smoking or nonsmoking section of the plane.

the program should of course never assign a seat that has already been assigned.
when smoking section is full the program should ask the person if it is acceptabel fo be placed in the nonsmoking section (vice versa)
if then make the appropriate seat assignment if no then prin the message "Next Flight Will Leave In 3 Hours"
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
i hope you guys can help me out on this simple but very difficult problem for me...
Have you even tried programming this assignment, or do you want me to do all of your homework for you?
closed account (S6k9GNh0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//Airplane.h
#include <vector.h>

class Airplane
{
	std::vector<bool> mSeats;

	public:
		Airplane(int Seats) { setNumSeats(Seats); }
		int getNumSeats();
		void setNumSeats(int _mSeats);
		bool assignSeats(int numSeat);
		bool unassignSeat();
}


1
2
3
4
5
6
7
//Airplane.cpp
#include "Airplane.h"

int getNumSeats() { return mSeats.size(); } 
void setNumSeats(int _mSeats) { mSeats.resize(_mSeats); }
bool assignSeat(int numSeat) { if (!mSeats.at(numSeat)) mSeats[numSeat] = true; }
bool unassignSeat(int numSeat { if (mSeats.at(numSeat)) mSeats[numSeat] = false; }


The above are a couple of functions. Probably the best method for you is to make each seat a boolean. If that seat is true then it's full. Else, it's empty and you can assign that seat.

This should help you get started. Might I add that this isn't your program. It doesn't include the User Interface, and it doesn't include the algorithm to place each customer. My advice on that is take your time, think about what method is best, then try and implement that method. If you have more trouble, feel free to ask what your having problems about.
Last edited on
He's is a newbie at programming so he is probably not looking to use vectors or classes for this assignment, post some code so we can help.
closed account (S6k9GNh0)
Maybe he needs to learn. They aren't hard to learn and the function I posted are simple. He doesn't even have to look at them really since a vector works the same way as an array. He just needs to make an algorithm to call my functions in the right order. That should work...That and create user interface but he can do that in main()
Last edited on
ya but vectors are still a bit different than an array, but we should wait until he decides to actually post some of his code
i really dont know how to do this guys.. i started making my own code.. dont know if this are real ones... here it goes.. note: its not finished... i dont know whats nex..

#include <iostream>
using namespace std;

int main()

{
int seats[10], smoking, nonsmoking, select;
char name[7], lastName[8];
cout << "Enter your name: \n";
cin >> name;
cout << "Enter your lastName: \n";
cin >> lastName;

do
cout << " select: \n";
cout << " type [1] smoking \n"
<< " type [2] nonsmoking \n";
cin >> select;

{

[1] = rand()%5
[2] = rand()%10-4


if (select=[1])
_____________________________________________

but any ways... thnx for the comments guys..
its handful to have a website like this..
I'll try and help you =]
Normally I wouldn't help someone do their homework but you've attempted it so I will rewrite it. I'm not that good a programmer but I think I can do this :l
Please put your code in between [cod e] and [/cod e], and remove the spaces.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream> // input/output (i/o) stream - allows input and output to the OS
using namespace std; /* Namespace declaration allows you to use std::cout, std::cin, std::endl,
std::string and more without typing std::*/

int main() { /* This is the first function executed, so other functions should be called from main --
the program will go back to main so you do not need to call main from other functions */

int seats[10],  smoking, nonsmoking, select, i=5; // Arrays are created with 0 all elements.

// char name[7], lastName[8]; // These could be replaced by strings:
string name, lastName;
cout << "Enter your first name:\n";
getline(cin, name); // You should use getline() when working with strings
cout << "Enter your last name:\n";
getline(cin, lastName);

cout << "Select:\n";
cout << "Enter 1 to select smoking\n"
       << "Enter 2 to select nonsmoking\n";
cin >> select;

if (select==1) {
    do {
        seats[i]=1;
        i++
    } while (i<5); /* Do the above code until the variable 'i' is equal to or more than 5. It will be 
executed even if 'i' started as 6 because the code is executed in sequence. */
}
seats=6;
else if (select==2) {
    do {
        seats[i]=1;
        i++
    } while (i<10); /* Do the above code until the variable 'i' is equal to or more than 5. It will be 
executed even if 'i' started as 6 because the code is executed in sequence. */
}

cin.get(); // Wait for the user to input enter. Literally 'get' the enter key.
return 0;
}


I think that is what you want.
I could not complete it as I was in school and ran out of time.
I'll finish now.

Please don't copy and paste it though. Try it, and if it works, rewrite it yourself. If it does not work please tell me and I'll try and fix it. It should work though.
Last edited on
thnx for the help... im using the microsoft visual v6... so the get line word is undeclared identifier...
well ill try so study it.. thnx a lot.. it really helps..
thats because your mixxing formated and unformated, getline & cin. Choose what one your going to use and stick with it
closed account (S6k9GNh0)
jloundy, cin and getline have two different functionalities.
... ill try to fix it... thnx a lot guys...
haai... it realy helps me a lot...
Finally ive done my codes.. its just simple...
now my next exercise is to convert our C++ codes to java.. and i dont have a single piece of idea how to do it... and my code goes like this...

#include<iostream>
#include<stdlib.h>
#include<stdio.h>

using namespace std;

int x=1,y=6,ans;
char check,con;

int main()

{
cout <<"type [1] Smoking Section\n";
cout <<"type [2] Non Smoking Section\n";
cout <<"type [3] Quit program.\n\n";

do
{


cout<<"Pls. Select \n";
cin>>ans;

if (ans == 1 && x<=5)
{
cout<<"Pls. occupy seat no. "<<x<<" Enjoy!!!.\n\n";
x++;
cout<<"\tWould You Like To Continue? (y/n)\n";
cin>>check;
}

else if (ans == 1 && x>5)
{
cout<<"\t\tSmoking Area is full!\n";
cout<<"\tDo you want a seat in the Non-Smoking Area? (y/n)\n";
cin>>con;

if ((con == 'Y' || con =='y') && y<=10)
{
cout<<"Your seat number is "<<y<<".\n";
y++;
cout<<"Do you want to continue sir/maam? (y/n)\n";
cin>>check;
}
else if ((con == 'Y' || con =='y') && y>10)
{
cout<<"Sorry,all seats are taken!!\n\n";
cout<<"The next flight leaves in 3 hours;)!\n";
return 0;
}
else if (con != 'y' || con != 'Y')
{
cout <<"The next flight leaves in 3 hours!\n";
return 0;
}



}

if (ans == 2 && y<=10)
{
cout<<"Your seat number is "<<y<<".\n\n";
y++;
cout<<"Do you want to continue sir/maam? (y/n)\n";
cin>>check;
}

else if (ans == 2 && y>10)
{
cout<<"\t\tNon-Smoking Area is full!\n";
cout<<"\tDo you want a seat in the Smoking Area?(y/n)\n";
cin>>con;

if ((con == 'Y' || con =='y') && x<=5)
{
cout<<"Your seat number is "<<x<<".\n";
x++;
cout<<"Do you want to continue sir/maam? (y/n)\n";
cin>>check;
}
else if ((con == 'Y' || con =='y') && x>5)
{
cout<<"Soryy,all seats are taken!!\n\n";
cout<<"The next flight leaves in 3 hours!\n";
return 0;
}
else if (con != 'y' || con != 'Y')
{
cout<<"The next flight leaves in 3 hours!\n";
return 0;
}

}
else if (ans>3)
{
cout<<"Incorrect Input!!\n\n\n";
cout<<"\n";
cout<<"\n";
return main();
}



}
while (check == 'y' || check == 'Y');
return 0;
}









thnx for the help... well i finally done it...
Flight Reservation program was our Project ..
but it was really HUGE code ..

if you want it , I'll attach it :)
Umm... do you know Java? If so why write this in C++ first? This is a very basic program and would be easy to rewrite in Java.
closed account (S6k9GNh0)
There are a couple of problems with coding in Java.

Though a Virtual Machine creates a large amount of portability and throwing portability upon those who develop Java, it's an inconvenience to run the code through the virtual machine. You need to download the virtual machine as a result. Plus, some people want a much more simple executable as a result.

Although it's very often that you'll see an original executable execute the Java for the user as long as the user has the VM on there PC.

I personally see the reasons for coding for Java but I don't currently think it's worth it and until then I don't recommend it.
i think im going to study again... whew... it was out of my expectations, that c++, java, visual basic and pasacal,,,,,,,,,,,,,,,,, im on a training... training on these pragram application for 1 month only.. ahehehe... wish me luck.. well LOLY can u atached ur file to me? i guess i need to study it.. thnx for the advice and teachings COMPUTERQUIP...
here it is:
http://uploads.bizhat.com/file/406520

hope to benefit
Topic archived. No new replies allowed.