473,378 Members | 1,594 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Visual C++.NET - Help!

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

Jul 22 '05 #1
16 2783

"Simon" <Me@overthere.com> wrote in message
news:Rj*****************@newsread2.news.atl.earthl ink.net...
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

Jul 22 '05 #2
On Sat, 26 Jun 2004 17:25:05 GMT, "Simon" <Me@overthere.com> 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
No**********@Home.com
Jul 22 '05 #3
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
Jul 22 '05 #4
On Sat, 26 Jun 2004 17:25:05 GMT, "Simon" <Me@overthere.com> 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
Jul 22 '05 #5
On Sat, 26 Jun 2004 21:49:28 +0100 in comp.lang.c++, rossum
<ro******@coldmail.com> 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/

Jul 22 '05 #6


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] = i;
Console::WriteLine(seatingArray[i]);
}
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] = i;
Console::WriteLine(seatingArray[i]);
}
return 0;
}

Thanks,

Simon

Jul 22 '05 #7
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] = i;
Console::WriteLine(seatingArray[i]);
}
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] = i;
Console::WriteLine(seatingArray[i]);
}
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] = i;
cout<<seatingArray[i]<<endl;
}
return 0;
}


Regards,

Ioannis Vranos
Jul 22 '05 #8
On Mon, 28 Jun 2004 04:40:58 GMT, Simon <me*@aol.com> 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] = 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[i] has one
subscript while my_matrix[i][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] = i;
Console::WriteLine(seatingArray[i]);
}
return 0;
}
rossum

Thanks,

Simon


--

The Ultimate Truth is that there is no Ultimate Truth
Jul 22 '05 #9
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" <me*@aol.com> wrote in message
news:uj******************@newsread3.news.atl.earth link.net...


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] = i;
Console::WriteLine(seatingArray[i]);
}
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] = i;
Console::WriteLine(seatingArray[i]);
}
return 0;
}

Thanks,

Simon

Jul 22 '05 #10
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" <me*@aol.com> wrote in message
news:uj******************@newsread3.news.atl.earth link.net...


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] = i;
Console::WriteLine(seatingArray[i]);
}
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] = i;
Console::WriteLine(seatingArray[i]);
}
return 0;
}

Thanks,

Simon

Jul 22 '05 #11

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 ||.
Jul 22 '05 #12
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
Jul 22 '05 #13
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
Jul 22 '05 #14

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
Jul 22 '05 #15
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.
Jul 22 '05 #16
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" <NU**@NULL.NULL> wrote in message
news:H9*****************@news.indigo.ie...
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

Jul 22 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: angelag | last post by:
I am currently taking a college course in Visual Basic.Net and I am a beginner. I bought Visual Studio.Net 2003 to do my homework at home. I built my first project and e-mailed it to myself at...
2
by: AK | last post by:
I don't want any part of the previous discussion on Visual Basic versus Visual Basic.Net. My query is about using Visual Basic for Applications; and whether it is better to use Visual Basic 6 or...
2
by: Anil Sahai | last post by:
I installed Visual Studio Version 6.0 with Visual Basic and Visual C++ etc. When I tried to invoke Help in Visual BASIC, it said that I should install MSDN. I installed MSDN using the MSDN library...
4
by: Hawkmoth | last post by:
Hi I hope you can help with what seems to be a simple problem that is driving me nuts! I am developing a C# application using Visual studio 2003 and I need to use Office 2003 automation. In...
0
by: Al, Cambridge, UK | last post by:
I thought I'd share this, since it cost me 2.5 days... When running Visual Studio .NET 2003 as a Power User, if I pressed F1 for context-sensitive help, I either (consistently for particular...
1
by: Scott Chang | last post by:
Hi all, 1)I used Microsoft Visual C++.NET (2002) on my Windows Me and Windows XP Home Edition for the last one and half years. 4-5 weeks ago, I upgraded my PC from Windows XP Home Edition to...
6
by: JonSteng | last post by:
..Net Visual Studio Professional 2003 Version 7.1.3088 ..Net Framework 1.1 SP1 Version 1.1.4322 IIS 5.1 Windows XP Professional SP2 Micron T3000 Laptop (1.5 GHz; 1GB RAM; 40GB HD with 17GB Free)...
0
by: fiona | last post by:
Innovasys Ltd., a leader in help authoring and documentation tools, today announced the inclusion of a tailored version of the Innovasys HelpStudio help authoring product, HelpStudio Lite, in the...
18
by: surfrat_ | last post by:
Hi, I am having the following problems in getting Microsoft Visual Studio 2005 Professional to link to an Access .mdb database. Please help me to sort this out. Problem 1: The Microsoft...
0
jwwicks
by: jwwicks | last post by:
Introduction This tutorial describes how to use Visual Studio to create a new C++ program, compile/run a program, resume work on an existing program and debug a program. It is aimed at the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.