Visual C++.NET - Help!

Discussion in 'C++' started by Simon, Jun 26, 2004.

  1. Simon

    Simon Guest

    I am a programming student and have recently missed two weeks of school due
    to a serious injury in a car accident. I am completing all of my
    assignments (via Labs) but have come across the following lab and can't seem
    to put it all together. The scenario:


    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 in indicate that the 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 section 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."



    Any suggestions? I have a few ideas but I would rather hear some other
    ideas...

    Thanks in advance,

    Simon
    Simon, Jun 26, 2004
    #1
    1. Advertising

  2. On Sat, 26 Jun 2004 17:25:05 GMT, "Simon" <> wrote:

    >I am a programming student and have recently missed two weeks of school due
    >to a serious injury in a car accident. I am completing all of my
    >assignments (via Labs) but have come across the following lab and can't seem
    >to put it all together. The scenario:
    >
    >
    >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 in indicate that the 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 section 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."
    >
    >
    >
    >Any suggestions? I have a few ideas but I would rather hear some other
    >ideas...



    Your ideas first, please.


    --
    Bob Hairgrove
    Bob Hairgrove, Jun 26, 2004
    #2
    1. Advertising

  3. "Simon" <> wrote in message
    news:RjiDc.28896$...
    > I am a programming student and have recently missed two weeks of school

    due
    > to a serious injury in a car accident. I am completing all of my
    > assignments (via Labs) but have come across the following lab and can't

    seem
    > to put it all together. The scenario:
    >


    [snip]

    >
    > Any suggestions? I have a few ideas but I would rather hear some other
    > ideas...
    >


    My advice would be to do the assignment yourself. If you get stuck then post
    the code you have written here. This way of doing things has several
    advantages. It means that were know what you are stuck on because you have
    given us something specific to work with. Its means that we can judge your
    level of ability because we can see the code you have already written.
    Finally it proves that you aren't just trying to get others to do your work
    for you.

    This assignment does seem very easy, so I'm guessing that you are stuck
    because it is the first non-trivial program you have ever written, and you
    aren't sure where to start. If that is the case then just dive in and start
    writing code. Don't try to plan out the whole thing in your head and
    definitely don't try to write the whole program in one go. Instead be
    prepared to work gradually to the finished program, to experiment, and to
    throw code away and start again if things aren't working out.

    john
    John Harrison, Jun 26, 2004
    #3
  4. Simon

    JKop Guest

    Simon posted:

    > I am a programming student and have recently missed two weeks of school
    > due to a serious injury in a car accident. I am completing all of my
    > assignments (via Labs) but have come across the following lab and can't
    > seem to put it all together.


    Try another story, I'll still don't pity you enough to do your homework for
    you.


    -JKop
    JKop, Jun 26, 2004
    #4
  5. Simon

    rossum Guest

    On Sat, 26 Jun 2004 17:25:05 GMT, "Simon" <> wrote:

    >I am a programming student and have recently missed two weeks of school due
    >to a serious injury in a car accident. I am completing all of my
    >assignments (via Labs) but have come across the following lab and can't seem
    >to put it all together. The scenario:
    >
    >
    >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 in indicate that the 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 section 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."
    >
    >
    >
    >Any suggestions? I have a few ideas but I would rather hear some other
    >ideas...
    >
    >Thanks in advance,
    >
    >Simon
    >

    First make sure you understand the question. For example do you know
    what "single-subscripted array" means. Ask your instructor to explain
    anything that you do not understand.

    Start by writing a very simple version of the answer, for example
    allocate seats on a plane with just one passenger seat. It can help
    to run through things on paper before you start coding. Test this
    program, fix the faults. Post the code here if you get stuck.

    When it is working extend the program to a plane with five seats.
    Again test, fix faults and get it working.

    Add five more seats of a different class. Test and fix again.

    Finally go through the question again ans check that all the required
    elements such as menu options and messages are present.

    rossum


    --

    The Ultimate Truth is that there is no Ultimate Truth
    rossum, Jun 26, 2004
    #5
  6. Simon

    David Harmon Guest

    On Sat, 26 Jun 2004 21:49:28 +0100 in comp.lang.c++, rossum
    <> wrote,
    >Start by writing a very simple version of the answer, for example
    >allocate seats on a plane with just one passenger seat. It can help
    >to run through things on paper before you start coding. Test this
    >program, fix the faults. Post the code here if you get stuck.


    That is an excellent suggestion. In fact, go even simpler. For
    example, write the part that asks the user to enter his choice, and then
    do nothing with the answer. When that part compiles and works, add
    code in the smallest increment possible, and repeat. Add the code that
    checks if the input is recognizable, etc.

    Simon, please continue to ask questions here, but to get good answers
    you _must_ show what your code looks like as you go along and ask
    _specific_ questions about the part that is troubling you.

    This issue is covered in Marshall Cline's C++ FAQ. See the topic
    "[5.8] How do I post a question about code that doesn't work correctly?"
    It is always good to check the FAQ before posting. You can get the FAQ
    at:
    http://www.parashift.com/c -faq-lite/
    David Harmon, Jun 26, 2004
    #6
  7. Simon

    Simon Guest

    Simon wrote:
    > I am a programming student and have recently missed two weeks of school due
    > to a serious injury in a car accident. I am completing all of my
    > assignments (via Labs) but have come across the following lab and can't seem
    > to put it all together. The scenario:
    >
    >
    > 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 in indicate that the 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 section 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."
    >
    >
    >
    > Any suggestions? I have a few ideas but I would rather hear some other
    > ideas...
    >
    > Thanks in advance,
    >
    > Simon
    >
    >
    >


    Thank you for the advice so far. Looking at this original post I
    realize that it appeared like I just wanted someone to do the work for
    me. That's not the case at all. The fact is that I am a beginner
    programming student and I am finding that I have no problem learning the
    languages themselves, but have a bit of trouble coming up with the
    algorithms necessary to create solutions to problem. Is this something
    that comes with experience?

    The accident thing is true - I reinjured an already aggrivated condition
    in my spine (disk herniations, ffacet joint damage, and nerve damage in
    general). Lately I am on more narcotics than usual and seem to be
    having a harder time concentrating than usual.

    Anyway, this is what I have so far:

    Promt user for coach or first class:

    String *choice;

    //Prompt for First Class or Coach:
    Console::WriteLine(S"Please enter <1> for First Class ");
    Console::WriteLine(S"\nPlease enter <2> for Coach ");

    // Obtain number from user:
    choice = Console::ReadLine();


    The array for the seating chart:

    // Declare Array:
    Console::WriteLine(S"Seating Chart");
    int seatingArray[10];
    int i;

    for (i=0; i<10; i++) {
    seatingArray = i;
    Console::WriteLine(seatingArray);
    }


    return 0;


    I am planning on using if statements for the seat availability
    confirmations.

    My problem s are:

    - finding a way to assign the seats (maybe using random?)

    - initializing the array to zero

    These parts:
    "... 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..."

    Single subscripted array?

    "...Initialize all the elements of the array to 0 in indicate that the
    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...."

    Any suggestions?

    This is the full code (just a start):

    int _tmain()
    {
    String *choice;

    //Prompt for First Class or Coach:
    Console::WriteLine(S"Please enter <1> for First Class ");
    Console::WriteLine(S"\nPlease enter <2> for Coach ");

    // Obtain number from user:
    choice = Console::ReadLine();

    // Declare Array:
    Console::WriteLine(S"Seating Chart");
    int seatingArray[10];
    int i;

    for (i=0; i<10; i++) {
    seatingArray = i;
    Console::WriteLine(seatingArray);
    }


    return 0;
    }

    Thanks,

    Simon
    Simon, Jun 28, 2004
    #7
  8. Simon wrote:

    >
    >
    > Simon wrote:
    >
    >> I am a programming student and have recently missed two weeks of
    >> school due
    >> to a serious injury in a car accident. I am completing all of my
    >> assignments (via Labs) but have come across the following lab and
    >> can't seem
    >> to put it all together. The scenario:
    >>
    >>
    >> 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 in indicate that the
    >> 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 section 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."
    >>
    >>
    >>
    >> Any suggestions? I have a few ideas but I would rather hear some other
    >> ideas...
    >>
    >> Thanks in advance,
    >>
    >> Simon
    >>
    >>
    >>

    >
    > Thank you for the advice so far. Looking at this original post I
    > realize that it appeared like I just wanted someone to do the work for
    > me. That's not the case at all. The fact is that I am a beginner
    > programming student and I am finding that I have no problem learning the
    > languages themselves, but have a bit of trouble coming up with the
    > algorithms necessary to create solutions to problem. Is this something
    > that comes with experience?
    >
    > The accident thing is true - I reinjured an already aggrivated condition
    > in my spine (disk herniations, ffacet joint damage, and nerve damage in
    > general). Lately I am on more narcotics than usual and seem to be
    > having a harder time concentrating than usual.
    >
    > Anyway, this is what I have so far:
    >
    > Promt user for coach or first class:
    >
    > String *choice;
    >
    > //Prompt for First Class or Coach:
    > Console::WriteLine(S"Please enter <1> for First Class ");
    > Console::WriteLine(S"\nPlease enter <2> for Coach ");
    >
    > // Obtain number from user:
    > choice = Console::ReadLine();
    >
    >
    > The array for the seating chart:
    >
    > // Declare Array:
    > Console::WriteLine(S"Seating Chart");
    > int seatingArray[10];
    > int i;
    >
    > for (i=0; i<10; i++) {
    > seatingArray = i;
    > Console::WriteLine(seatingArray);
    > }
    >
    >
    > return 0;
    >
    >
    > I am planning on using if statements for the seat availability
    > confirmations.
    >
    > My problem s are:
    >
    > - finding a way to assign the seats (maybe using random?)
    >
    > - initializing the array to zero
    >
    > These parts:
    > "... 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..."
    >
    > Single subscripted array?
    >
    > "...Initialize all the elements of the array to 0 in indicate that the
    > 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...."
    >
    > Any suggestions?
    >
    > This is the full code (just a start):
    >
    > int _tmain()
    > {
    > String *choice;
    >
    > //Prompt for First Class or Coach:
    > Console::WriteLine(S"Please enter <1> for First Class ");
    > Console::WriteLine(S"\nPlease enter <2> for Coach ");
    >
    > // Obtain number from user:
    > choice = Console::ReadLine();
    >
    > // Declare Array:
    > Console::WriteLine(S"Seating Chart");
    > int seatingArray[10];
    > int i;
    >
    > for (i=0; i<10; i++) {
    > seatingArray = i;
    > Console::WriteLine(seatingArray);
    > }
    >
    >
    > return 0;
    > }




    You are using .NET framework API. You had better use the standard
    library facilities and restrict the system specific extensions only at a
    small portion of your code. In your code above there is no need for .NET
    facilities at all.


    Your above code in ISO C++:


    #include <string>
    #include <iostream>


    int main()
    {
    using namespace std;

    string choice;

    //Prompt for First Class or Coach:
    cout<<"Please enter <1> for First Class\n";
    cout<<"\nPlease enter <2> for Coach\n";

    // Obtain number from user:
    cin>>choice;

    // Declare Array:
    cout<<"Seating Chart"<<endl;

    int seatingArray[10];
    int i;

    for (i=0; i<10; i++) {
    seatingArray = i;
    cout<<seatingArray<<endl;
    }


    return 0;
    }






    Regards,

    Ioannis Vranos
    Ioannis Vranos, Jun 28, 2004
    #8
  9. Simon

    rossum Guest

    On Mon, 28 Jun 2004 04:40:58 GMT, Simon <> wrote:

    Simon, Ioannis' advice to use standard C++ is good. I do not have
    ..NET on my PC so I cannot compile the code you posted. With Ioannis'
    version I can compile it easily. Note also that he gave the required
    #include statements.

    [snip]

    > My problems are:
    >
    > - finding a way to assign the seats (maybe using random?)


    Why complicate things? Assign seats from 0 (or 5) as needed. Each
    new passenger gets the next vacant seat in the required class. There
    is no point in adding extra complication to the question. Keep it as
    simple as you can.

    > - initialising the array to zero


    You have already coded a loop to assign numbers to the array:

    > for (i=0; i<10; i++) {
    > seatingArray = i;
    > }


    This gives seatingArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    You need to change your loop so it gives
    seatingArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]


    - Boarding Pass

    Don't worry about the Boarding Pass yet, get the seat allocation
    working correctly first. Don't try to do too much in one lump. Break
    the problem down into small pieces and get each piece working before
    adding in the next. While you are still learning the pieces will be
    small, as David Harmon suggests your first piece might be just to get
    the menu and user choice working. With experience the size of the
    pieces you can deal with will increase.

    If you have done functions then you could write a "function stub" for
    printing the Boarding Pass to act as a place holder until you are
    ready to tackle it.

    The stub will look like:

    void print_boarding_pass(int seat_number) {
    std::cout << "Print Boarding Pass here.\n";
    return;
    }

    Call the stub from the appropriate place in your code. Having the
    stub in place lets you compile and run your program even though you
    have not written this part of it yet. You only have to expand the
    stub into a fully working piece of code when you have the rest of the
    code working.


    - single subscripted array

    Ask your instructor to explain. An ssa is a sort of array. It is an
    array with a "single subscript", that is an array with one subscript.
    Your code shows that you know what an array is. I suspect that
    "subscript" is causing the problem. Hint: seatingArray has one
    subscript while my_matrix[j] has two subscripts.


    - initialise the array

    See my comments above on seatingArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]


    - indicating that a seat is no longer available

    There are ten seats on the aircraft and there are ten elements in
    seatingArray. This is not a coincidence.

    The array is initialised to [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] and all the
    seats in the aircraft start empty. As the question says: "Initialize
    all the elements of the array to 0 in indicate that the seats are
    empty." From this you can deduce that a 0 means "this seat is
    currently empty".

    When a seat has been assigned you need a way to show that the seat is
    no longer available. The question says: "As each seat is assigned set
    the corresponding element of the array to 1 to indicate that the seat
    is no longer available." There is a lot of help for you in the
    question, refer back to it often.


    > int _tmain()
    > {
    > String *choice;
    >
    > //Prompt for First Class or Coach:
    > Console::WriteLine(S"Please enter <1> for First Class ");
    > Console::WriteLine(S"\nPlease enter <2> for Coach ");


    The question talks about "Economy", you talk about "Coach". Why have
    you changed it? Answer the question that is asked. Do you think the
    airline will pay you for a program that does not use the correct name
    for Economy tickets?

    > // Obtain number from user:
    > choice = Console::ReadLine();
    >
    > // Declare Array:
    > Console::WriteLine(S"Seating Chart");
    > int seatingArray[10];
    > int i;
    >
    > for (i=0; i<10; i++) {


    It is better to get into the habit of using ++i rather than i++. ++i
    is never slower and sometimes faster.
    for (i = 0; i < 10; ++i) {

    > seatingArray = i;
    > Console::WriteLine(seatingArray);
    > }
    >
    >
    > return 0;
    > }




    rossum

    >
    >Thanks,
    >
    >Simon


    --

    The Ultimate Truth is that there is no Ultimate Truth
    rossum, Jun 29, 2004
    #9
  10. Maybe you could use a pair of bool arrays instead of one int array? You
    could have loops evaluate seat numbers and assign the seats to the
    passengers in their chosen section. If all the seats in a class (Economy or
    First Class) evaluated true (1 - meaning occupied), you could ask the user
    if they wanted a seat in another section. Just a suggestion. You'll have
    to forgive me if this is stupid somehow; I haven't been at this for long.

    "Simon" <> wrote in message
    news:ujNDc.16913$...
    >
    >
    > Simon wrote:
    > > I am a programming student and have recently missed two weeks of school

    due
    > > to a serious injury in a car accident. I am completing all of my
    > > assignments (via Labs) but have come across the following lab and can't

    seem
    > > to put it all together. The scenario:
    > >
    > >
    > > 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 in indicate that the 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 section 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."
    > >
    > >
    > >
    > > Any suggestions? I have a few ideas but I would rather hear some other
    > > ideas...
    > >
    > > Thanks in advance,
    > >
    > > Simon
    > >
    > >
    > >

    >
    > Thank you for the advice so far. Looking at this original post I
    > realize that it appeared like I just wanted someone to do the work for
    > me. That's not the case at all. The fact is that I am a beginner
    > programming student and I am finding that I have no problem learning the
    > languages themselves, but have a bit of trouble coming up with the
    > algorithms necessary to create solutions to problem. Is this something
    > that comes with experience?
    >
    > The accident thing is true - I reinjured an already aggrivated condition
    > in my spine (disk herniations, ffacet joint damage, and nerve damage in
    > general). Lately I am on more narcotics than usual and seem to be
    > having a harder time concentrating than usual.
    >
    > Anyway, this is what I have so far:
    >
    > Promt user for coach or first class:
    >
    > String *choice;
    >
    > //Prompt for First Class or Coach:
    > Console::WriteLine(S"Please enter <1> for First Class ");
    > Console::WriteLine(S"\nPlease enter <2> for Coach ");
    >
    > // Obtain number from user:
    > choice = Console::ReadLine();
    >
    >
    > The array for the seating chart:
    >
    > // Declare Array:
    > Console::WriteLine(S"Seating Chart");
    > int seatingArray[10];
    > int i;
    >
    > for (i=0; i<10; i++) {
    > seatingArray = i;
    > Console::WriteLine(seatingArray);
    > }
    >
    >
    > return 0;
    >
    >
    > I am planning on using if statements for the seat availability
    > confirmations.
    >
    > My problem s are:
    >
    > - finding a way to assign the seats (maybe using random?)
    >
    > - initializing the array to zero
    >
    > These parts:
    > "... 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..."
    >
    > Single subscripted array?
    >
    > "...Initialize all the elements of the array to 0 in indicate that the
    > 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...."
    >
    > Any suggestions?
    >
    > This is the full code (just a start):
    >
    > int _tmain()
    > {
    > String *choice;
    >
    > //Prompt for First Class or Coach:
    > Console::WriteLine(S"Please enter <1> for First Class ");
    > Console::WriteLine(S"\nPlease enter <2> for Coach ");
    >
    > // Obtain number from user:
    > choice = Console::ReadLine();
    >
    > // Declare Array:
    > Console::WriteLine(S"Seating Chart");
    > int seatingArray[10];
    > int i;
    >
    > for (i=0; i<10; i++) {
    > seatingArray = i;
    > Console::WriteLine(seatingArray);
    > }
    >
    >
    > return 0;
    > }
    >
    > Thanks,
    >
    > Simon
    >
    Stephen Tyndall, Jul 1, 2004
    #10
  11. Oops, just after writing that last message I realized that the question
    asked for a single array; in that case you could use just one bool array and
    call a different loop (using if statements) based on which class the user
    selects. One loop could evaluate seats 1-5 and the other could evaluate
    seats 6-10. Also, here's a quick way to foolproof your inquiry for input:

    while(! strVariable.empty() ) {
    cout << "Please enter input";
    cin >> strVariable;
    }

    The loop repeats as long as the user hasn't entered anything. Also, you
    should have an if statement to deal with junk input, calling the function
    for the inquiry again if the input is unacceptable.

    "Simon" <> wrote in message
    news:ujNDc.16913$...
    >
    >
    > Simon wrote:
    > > I am a programming student and have recently missed two weeks of school

    due
    > > to a serious injury in a car accident. I am completing all of my
    > > assignments (via Labs) but have come across the following lab and can't

    seem
    > > to put it all together. The scenario:
    > >
    > >
    > > 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 in indicate that the 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 section 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."
    > >
    > >
    > >
    > > Any suggestions? I have a few ideas but I would rather hear some other
    > > ideas...
    > >
    > > Thanks in advance,
    > >
    > > Simon
    > >
    > >
    > >

    >
    > Thank you for the advice so far. Looking at this original post I
    > realize that it appeared like I just wanted someone to do the work for
    > me. That's not the case at all. The fact is that I am a beginner
    > programming student and I am finding that I have no problem learning the
    > languages themselves, but have a bit of trouble coming up with the
    > algorithms necessary to create solutions to problem. Is this something
    > that comes with experience?
    >
    > The accident thing is true - I reinjured an already aggrivated condition
    > in my spine (disk herniations, ffacet joint damage, and nerve damage in
    > general). Lately I am on more narcotics than usual and seem to be
    > having a harder time concentrating than usual.
    >
    > Anyway, this is what I have so far:
    >
    > Promt user for coach or first class:
    >
    > String *choice;
    >
    > //Prompt for First Class or Coach:
    > Console::WriteLine(S"Please enter <1> for First Class ");
    > Console::WriteLine(S"\nPlease enter <2> for Coach ");
    >
    > // Obtain number from user:
    > choice = Console::ReadLine();
    >
    >
    > The array for the seating chart:
    >
    > // Declare Array:
    > Console::WriteLine(S"Seating Chart");
    > int seatingArray[10];
    > int i;
    >
    > for (i=0; i<10; i++) {
    > seatingArray = i;
    > Console::WriteLine(seatingArray);
    > }
    >
    >
    > return 0;
    >
    >
    > I am planning on using if statements for the seat availability
    > confirmations.
    >
    > My problem s are:
    >
    > - finding a way to assign the seats (maybe using random?)
    >
    > - initializing the array to zero
    >
    > These parts:
    > "... 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..."
    >
    > Single subscripted array?
    >
    > "...Initialize all the elements of the array to 0 in indicate that the
    > 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...."
    >
    > Any suggestions?
    >
    > This is the full code (just a start):
    >
    > int _tmain()
    > {
    > String *choice;
    >
    > //Prompt for First Class or Coach:
    > Console::WriteLine(S"Please enter <1> for First Class ");
    > Console::WriteLine(S"\nPlease enter <2> for Coach ");
    >
    > // Obtain number from user:
    > choice = Console::ReadLine();
    >
    > // Declare Array:
    > Console::WriteLine(S"Seating Chart");
    > int seatingArray[10];
    > int i;
    >
    > for (i=0; i<10; i++) {
    > seatingArray = i;
    > Console::WriteLine(seatingArray);
    > }
    >
    >
    > return 0;
    > }
    >
    > Thanks,
    >
    > Simon
    >
    Stephen Tyndall, Jul 1, 2004
    #11
  12. Note to self: do not attempt programming late at night...

    Okay, one last correction message. That bit of code for input? It should be
    like this:

    while(strVariable.empty()) {
    cout << "Please enter input: ";
    cin >> strVariable;
    }

    That was pretty bad.
    (! strVariable.empty())
    would return false, not true, if strVariable was empty. Also, I forgot to
    give the user space for input. Also, I had a note later on saying to use an
    if statement to deal with junk input. This should be an else statement, not
    an if statement. Example:

    #include <string>
    using namespace std;

    int main() {
    string strVariable;
    while(strVariable.empty()) {
    cout << "Please enter \"Word1\" or \"Word2\": ";
    cin >> strVariable;
    }
    if( (strVariable == "Word1") || (strVariable == "word1") ) {
    word1function();
    }
    else if( (strVariable == "Word2") || (strVariable == "word2") ) {
    word2function();
    }
    else {
    cout << "Input unacceptable. Try again." << endl;
    main();
    }
    return 0;
    }

    You'll notice this code includes a recursive call to main(). This repeats
    the program from the beginning and asks the user to enter Word1 or Word2
    again (provided they entered bad input). Loops are faster than recursive
    functions, but both have their uses (you'll almost always use loops,
    though). Also, the if statements provided for two types of capitalization
    through use of the logical "OR" operator ||.
    Stephen Tyndall, Jul 1, 2004
    #12
  13. Stephen Tyndall wrote:

    > You'll notice this code includes a recursive call to main(). This repeats


    Explicit calls to main are forbidden in C++.

    --
    Salu2
    =?ISO-8859-15?Q?Juli=E1n?= Albo, Jul 1, 2004
    #13
  14. Simon

    JKop Guest

    Stephen Tyndall posted:

    > #include <string>
    > using namespace std;
    >
    > int main() {
    > string strVariable;
    > while(strVariable.empty()) {
    > cout << "Please enter \"Word1\" or \"Word2\": ";
    > cin >> strVariable;
    > }
    > if( (strVariable == "Word1") || (strVariable == "word1") ) {
    > word1function();
    > }
    > else if( (strVariable == "Word2") || (strVariable == "word2") )
    > {
    > word2function();
    > }
    > else {
    > cout << "Input unacceptable. Try again." << endl;
    > main();
    > }
    > return 0;
    > }


    I've made the following alterations:

    A) The first call to String::empty() is redundant, so I've replaced it with
    a do-while.

    B) I've removed the recursive call to main(), which is illegal in Standard
    C++


    Recomendations:

    A)Instead of comparing to both the uppercase or lowercase, use a function
    that compares two strings without regard to case.


    #include <string>
    using namespace std;

    int main() {

    string strVariable;

    Back_to_the_start:

    do
    {
    cout << "Please enter \"Word1\" or \"Word2\": ";
    cin >> strVariable;
    } while ( strVariable.empty() ) ;

    if( (strVariable == "Word1") || (strVariable == "word1") )
    {
    word1function();
    }

    else
    {
    if( (strVariable == "Word2") || (strVariable == "word2") )
    {
    word2function();
    }
    else
    {
    cout << "Input unacceptable. Try again." << endl;
    goto Back_to_the_start;
    }
    }

    }


    -JKop
    JKop, Jul 1, 2004
    #14
  15. Simon

    JKop Guest

    I indentation came out all screwed up. Here it is again:

    #include <string>
    using namespace std;

    int main()
    {
    string strVariable;

    Back_to_the_start:

    do
    {
    cout << "Please enter \"Word1\" or \"Word2\": ";
    cin >> strVariable;

    } while ( strVariable.empty() ) ;

    if ( (strVariable == "Word1") || (strVariable == "word1") )
    {
    word1function();
    }
    else
    {
    if ( (strVariable == "Word2") || (strVariable == "word2") )
    {
    word2function();
    }
    else
    {
    cout << "Input unacceptable. Try again." << endl;
    goto Back_to_the_start;
    }
    }

    }


    -JKop
    JKop, Jul 1, 2004
    #15
  16. Simon

    Julie Guest

    Julián Albo wrote:
    >
    > Stephen Tyndall wrote:
    >
    > > You'll notice this code includes a recursive call to main(). This repeats

    >
    > Explicit calls to main are forbidden in C++.
    >
    > --
    > Salu2


    As well as implicit calls.
    Julie, Jul 2, 2004
    #16
  17. I didn't know about the "recursive calls to main()" thing; I've only had
    about three weeks of C++ so far. I've never written code with a recursive
    call to main, but I did have some longer code where a function called
    itself; I just assumed you could do the same thing with main() as long as
    you qualified the recursive call (just like you would with any such call).
    As for the "do-while" loop, that's a good idea. Thanks for the info guys.

    "JKop" <> wrote in message
    news:H90Fc.3656$...
    > Stephen Tyndall posted:
    >
    > > #include <string>
    > > using namespace std;
    > >
    > > int main() {
    > > string strVariable;
    > > while(strVariable.empty()) {
    > > cout << "Please enter \"Word1\" or \"Word2\": ";
    > > cin >> strVariable;
    > > }
    > > if( (strVariable == "Word1") || (strVariable == "word1") ) {
    > > word1function();
    > > }
    > > else if( (strVariable == "Word2") || (strVariable == "word2") )
    > > {
    > > word2function();
    > > }
    > > else {
    > > cout << "Input unacceptable. Try again." << endl;
    > > main();
    > > }
    > > return 0;
    > > }

    >
    > I've made the following alterations:
    >
    > A) The first call to String::empty() is redundant, so I've replaced it

    with
    > a do-while.
    >
    > B) I've removed the recursive call to main(), which is illegal in Standard
    > C++
    >
    >
    > Recomendations:
    >
    > A)Instead of comparing to both the uppercase or lowercase, use a function
    > that compares two strings without regard to case.
    >
    >
    > #include <string>
    > using namespace std;
    >
    > int main() {
    >
    > string strVariable;
    >
    > Back_to_the_start:
    >
    > do
    > {
    > cout << "Please enter \"Word1\" or \"Word2\": ";
    > cin >> strVariable;
    > } while ( strVariable.empty() ) ;
    >
    > if( (strVariable == "Word1") || (strVariable == "word1") )
    > {
    > word1function();
    > }
    >
    > else
    > {
    > if( (strVariable == "Word2") || (strVariable == "word2") )
    > {
    > word2function();
    > }
    > else
    > {
    > cout << "Input unacceptable. Try again." << endl;
    > goto Back_to_the_start;
    > }
    > }
    >
    > }
    >
    >
    > -JKop
    Stephen Tyndall, Jul 2, 2004
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Timbers
    Replies:
    32
    Views:
    1,392
    Alvin Bruney
    Nov 8, 2003
  2. wh
    Replies:
    2
    Views:
    494
    Cowboy \(Gregory A. Beamer\)
    Jan 16, 2004
  3. M P
    Replies:
    6
    Views:
    537
    Joe Fallon
    Aug 7, 2004
  4. hunkgym
    Replies:
    1
    Views:
    1,971
    =?Utf-8?B?TGVvbiBNYXluZQ==?=
    Oct 30, 2006
  5. KevinGPO
    Replies:
    1
    Views:
    341
    Victor Bazarov
    Mar 6, 2006
Loading...

Share This Page