Computing.Net > Forums > Programming > C++ Homework Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ Homework Help

Reply to Message Icon

Name: Tammy Woolard
Date: February 28, 2005 at 16:30:05 Pacific
OS: Windows XP
CPU/Ram: x86
Comment:

I am new at C++ and I am having a lot of trouble understanding it. The following is a homework assignment due this week and I have not idea how to even start it much less finish coding it. Can anyone out there help?

(Airline Reservatins System) A small airline has just purchased a computer for its new automated reservations system. You have been asked to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats).
Your program should display the following menu of alternatives - Please type 1 for "First Class" and Please type 2 for "Economy". If the person types 1, your program should assign a seat in the first class section (seats 1-5). If the person types 2, your program should assign a seat in the economy section (seats 6-10). Your program should print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane.
Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available.
Your program should, of course, never assign a seat that has already been assigned. When the first class sections is full, your program should ask the person if it is acceptable to be placed in the economy section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message "Next flight leaves in 3 hours."

I keep thinking if I can see the correct code for this assignment then maybe I will start understandin this class better. I just have been at a loss so far.

I appreciate any help I can get!!!




Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: March 1, 2005 at 20:52:38 Pacific
Reply:

I think that a logic class is in order, because if seeing "correct code" all term in class hasn't helped, I don't think that seeing "...the correct code for this assignment..." will help you "...start understandin this class better."

Be sure to come back and let us know if our suggestions helped!


0

Response Number 2
Name: Chi Happens
Date: March 2, 2005 at 12:47:10 Pacific
Reply:

The real issue is that there is no "correct" code for this assignment. Programming is not like English, or Math even. There are an infinite number of ways to get the final result. This is part of the joy of programming, creating something out of nothing.

I will give you some help, tho.

The first thing you need to do is write down (on paper) all the things (actions) that your program needs to do.

Then write down (on paper) all the elements that need to do things and match them to the actions.

For instance:
ActionS
----------
Display Menu Items
Check for empty seats
Assign First Class Seat
Assign Economy Class Seat
Print Boarding Pass
...

Elements
----------
Seats
User
Passenger
...


then you can worry about the actual code:

#include "stdafx.h"

using namespace std;

// prototypes
int StartSystem(void);
int AddToEcomonyClass(int Seat[10]);
int AddToFirstClass(int Seat[10]);
bool CheckBoardingStatus(int Seat[10]);
void PrintBoardingPass(int SeatNumber,int FlightNumber);

// main
int main(int argc, _TCHAR* argv[])
{
StartSystem();
return 0;
}

int StartSystem(void)
{
int Seat[10]={0,0,0,0,0,0,0,0,0,0};
bool Boarding;
int item;
int SeatNumber;
int FlightNumber;

FlightNumber = 0;

while(true)
{
cout << "BOARDING PASS PROGRAM" << endl;
cout << "Type 1 to begin, or 2 to end." << endl;
cin >> item;
try
{
if(item == 2)
return 1;
}
catch(exception err)
{
cout << "ERROR: " << err.what() << endl;
return 1;
}
Boarding = true;
for(int t=0;t<24;t++)
cout << endl;
while(Boarding)
{
FlightNumber++;
cout << "Welcome to the automated boarding system for Flight #" << FlightNumber << endl;
cout << endl;

bool InvalidKey = true;
while(InvalidKey)
{
cout << "Please type 1 for \"First Class\"" << endl;
cout << "Please type 2 for \"Economy Class\"" << endl;

try
{
cin >> item;
if(item == 1)
{
InvalidKey = false;
SeatNumber = AddToFirstClass(Seat);
if(SeatNumber == -1)
{
cout << "The first Class cabin is full." << endl;
cout << "Please type 1 to be placed into \"Economy\" Class" << endl;
cout << "Please type 2 to wait for next flight." << endl;
try
{
cin >> item;
if(item == 1)
{
SeatNumber = AddToEcomonyClass(Seat);
if(SeatNumber == -1)
{
cout << "This flight is full." << endl;
cout << "The next flight leaves in 3 hours.";
Boarding = false;
}
else
{
Seat[SeatNumber] = 1;
PrintBoardingPass(SeatNumber,FlightNumber);
}
}
else
{
cout << "The next flight leaves in 3 hours.";
}
}
catch(exception err)
{
cout << "ERROR: " << err.what() << endl;
return 1;
}
}
else
{
Seat[SeatNumber] = 1;
PrintBoardingPass(SeatNumber,FlightNumber);
}
}
else if(item == 2)
{
InvalidKey = false;
SeatNumber = AddToEcomonyClass(Seat);
if(SeatNumber == -1)
{
cout << "The first Class cabin is full." << endl;
cout << "Please type 1 to be placed into \"First\" Class" << endl;
cout << "Please type 2 to wait for next flight." << endl;
try
{
cin >> item;
if(item == 1)
{
SeatNumber = AddToFirstClass(Seat);
if(SeatNumber == -1)
{
cout << "This flight is full." << endl;
cout << "The next flight leaves in 3 hours.";
Boarding = false;
}
else
{
Seat[SeatNumber] = 1;
PrintBoardingPass(SeatNumber,FlightNumber);
}
}
else
{
cout << "The next flight leaves in 3 hours.";
}
}
catch(exception err)
{
cout << "ERROR: " << err.what() << endl;
return 1;
}
}
else
{
Seat[SeatNumber] = 1;
PrintBoardingPass(SeatNumber,FlightNumber);
}
}
else
{
cout << "Invalid entry." << endl;
return 1;
}
}
catch(exception err)
{
cout << "ERROR: " << err.what() << endl;
return 1;
}
cout << endl;
cout << endl;
if(Boarding)
Boarding = CheckBoardingStatus(Seat);
}
}
}

}

bool CheckBoardingStatus(int Seat[10])
{
for(int t=0;t<10;t++)
{
if(Seat[t] == 0)
return true;
}
return false;
}
int AddToFirstClass(int Seat[10])
{
for(int t=0;t<5;t++)
{
if(Seat[t] == 0)
return t;
}
return -1;
}
int AddToEcomonyClass(int Seat[10])
{
for(int t=5;t<10;t++)
{
if(Seat[t] == 0)
return t;
}
return -1;
}
void PrintBoardingPass(int SeatNumber,int FlightNumber)
{
cout <&-------" << endl;
cout << "BOARDING PASS" << endl;
cout <&-------" << endl;
cout << "FLIGHT #" << FlightNumber << endl;
cout << "You have been assigned seat #" << SeatNumber+1 << endl;
if(SeatNumber < 5)
cout << "This is in the First Class cabin." << endl;
else
cout << "This is in the Economy Class section." << endl;
cout << "============================================================" << endl;
for(int t=0;t<8;t++)
cout << endl;

}

lol
Chi

They mostly come at night...mostly


0

Response Number 3
Name: brendon.pilott
Date: March 2, 2005 at 13:09:06 Pacific
Reply:

i wish someone gave me the answers to my homework when i did my programming degree :)


0

Response Number 4
Name: Chi Happens
Date: March 15, 2005 at 12:26:03 Pacific
Reply:

brendon,
Here is an update. lol

cminusminus pointed out my hipocrisy (sp?) today because i told someone to try it first before asking for help. He pointed out that I wrote this app for this person (and figured i did it because she is a she)..hmmm

Well here is the reason why I posted this.

It is a joke.

My posting started like all my other rants to people who don't try it and then I was going to just leave it at that...but I decided to code it quickly (and poorly i might add) and post that code just as a joke.

Sure, Tammy might use my code to complete this assignment...but it won't help her in the end. I guess the humor aspect was lost.

I really wanted IR or one of the old posters to read this...they would have gotten the joke.

oh well...
Chi

They mostly come at night...mostly


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ Homework Help

c++ homework help - vector for loop www.computing.net/answers/programming/c-homework-help-vector-for-loop/17650.html

C++ homework help www.computing.net/answers/programming/c-homework-help/12334.html

C++ Homework Help www.computing.net/answers/programming/c-homework-help/6501.html